Fix Gemini response (#885)

# Fixed Gemini llm response
# use region variables in url 2 times
This commit is contained in:
Konrad Początek 2024-02-21 22:52:16 +01:00 • committed by GitHub
parent 9fce7eb606
commit 66a4e76c2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;