mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🐛 fix: Handle content generation errors in GoogleClient (#5575)
This commit is contained in:
parent
6920e23fb2
commit
fdf0b41d08
1 changed files with 78 additions and 72 deletions
|
|
@ -605,6 +605,7 @@ class GoogleClient extends BaseClient {
|
||||||
|
|
||||||
let reply = '';
|
let reply = '';
|
||||||
|
|
||||||
|
try {
|
||||||
if (!EXCLUDED_GENAI_MODELS.test(modelName) && !this.project_id) {
|
if (!EXCLUDED_GENAI_MODELS.test(modelName) && !this.project_id) {
|
||||||
/** @type {GenAI} */
|
/** @type {GenAI} */
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
|
|
@ -629,6 +630,7 @@ class GoogleClient extends BaseClient {
|
||||||
const delay = modelName.includes('flash') ? 8 : 15;
|
const delay = modelName.includes('flash') ? 8 : 15;
|
||||||
/** @type {GenAIUsageMetadata} */
|
/** @type {GenAIUsageMetadata} */
|
||||||
let usageMetadata;
|
let usageMetadata;
|
||||||
|
|
||||||
const result = await client.generateContentStream(requestOptions);
|
const result = await client.generateContentStream(requestOptions);
|
||||||
for await (const chunk of result.stream) {
|
for await (const chunk of result.stream) {
|
||||||
usageMetadata = !usageMetadata
|
usageMetadata = !usageMetadata
|
||||||
|
|
@ -648,6 +650,7 @@ class GoogleClient extends BaseClient {
|
||||||
output_tokens: usageMetadata.candidatesTokenCount,
|
output_tokens: usageMetadata.candidatesTokenCount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -691,6 +694,9 @@ class GoogleClient extends BaseClient {
|
||||||
if (usageMetadata) {
|
if (usageMetadata) {
|
||||||
this.usage = usageMetadata;
|
this.usage = usageMetadata;
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('[GoogleClient] There was an issue generating the completion', e);
|
||||||
|
}
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue