Fix Gemini response (#885)
# Fixed Gemini llm response # use region variables in url 2 times
This commit is contained in:
parent
9fce7eb606
commit
66a4e76c2e
1 changed files with 7 additions and 3 deletions
|
|
@ -31,7 +31,7 @@ class Gemini extends BaseLLM {
|
|||
messages: ChatMessage[],
|
||||
options: CompletionOptions
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const apiUrl = `https://${this.region}-aiplatform.googleapis.com/v1/projects/${this.projectId}/locations/us-central1/publishers/google/models/gemini-pro:streamGenerateContent`;
|
||||
const apiUrl = `https://${this.region}-aiplatform.googleapis.com/v1/projects/${this.projectId}/locations/${this.region}/publishers/google/models/gemini-pro:streamGenerateContent`;
|
||||
const body = {
|
||||
contents: messages.map((msg) => {
|
||||
return {
|
||||
|
|
@ -60,8 +60,12 @@ class Gemini extends BaseLLM {
|
|||
if (data[0]?.error) {
|
||||
throw new Error(data[0].error.message);
|
||||
}
|
||||
yield data[0]?.candidates?.[0]?.content?.parts?.[0]?.text || "";
|
||||
}
|
||||
let combinedText = '';
|
||||
for (const entry of data || []) {
|
||||
combinedText += entry?.candidates?.[0]?.content?.parts?.[0]?.text || '';
|
||||
}
|
||||
|
||||
yield { role: "assistant", content: combinedText.trim() }; }
|
||||
}
|
||||
|
||||
export default Gemini;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue