mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 19:30:15 +01:00
🤖 refactor: Prevent Vertex AI from Setting Parameter Defaults (#5653)
* refactor: remove google defaults * refactor: improve GoogleClient stream handling and metadata usage * chore: update @librechat/agents to version 2.0.1 * fix: return client instance in GoogleClient configuration
This commit is contained in:
parent
0312d4f4f4
commit
6c33dc2eb3
3 changed files with 587 additions and 580 deletions
|
|
@ -566,7 +566,16 @@ class GoogleClient extends BaseClient {
|
||||||
|
|
||||||
if (this.project_id != null) {
|
if (this.project_id != null) {
|
||||||
logger.debug('Creating VertexAI client');
|
logger.debug('Creating VertexAI client');
|
||||||
return new ChatVertexAI(clientOptions);
|
clientOptions.streaming = true;
|
||||||
|
const client = new ChatVertexAI(clientOptions);
|
||||||
|
client.temperature = clientOptions.temperature;
|
||||||
|
client.topP = clientOptions.topP;
|
||||||
|
client.topK = clientOptions.topK;
|
||||||
|
client.topLogprobs = clientOptions.topLogprobs;
|
||||||
|
client.frequencyPenalty = clientOptions.frequencyPenalty;
|
||||||
|
client.presencePenalty = clientOptions.presencePenalty;
|
||||||
|
client.maxOutputTokens = clientOptions.maxOutputTokens;
|
||||||
|
return client;
|
||||||
} else if (!EXCLUDED_GENAI_MODELS.test(model)) {
|
} else if (!EXCLUDED_GENAI_MODELS.test(model)) {
|
||||||
logger.debug('Creating GenAI client');
|
logger.debug('Creating GenAI client');
|
||||||
return new GenAI(this.apiKey).getGenerativeModel({ model }, requestOptions);
|
return new GenAI(this.apiKey).getGenerativeModel({ model }, requestOptions);
|
||||||
|
|
@ -577,7 +586,7 @@ class GoogleClient extends BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeClient() {
|
initializeClient() {
|
||||||
let clientOptions = { ...this.modelOptions, maxRetries: 2 };
|
let clientOptions = { ...this.modelOptions };
|
||||||
|
|
||||||
if (this.project_id) {
|
if (this.project_id) {
|
||||||
clientOptions['authOptions'] = {
|
clientOptions['authOptions'] = {
|
||||||
|
|
@ -663,7 +672,9 @@ class GoogleClient extends BaseClient {
|
||||||
|
|
||||||
/** @type {import('@langchain/core/messages').AIMessageChunk['usage_metadata']} */
|
/** @type {import('@langchain/core/messages').AIMessageChunk['usage_metadata']} */
|
||||||
let usageMetadata;
|
let usageMetadata;
|
||||||
const stream = await this.client.stream(messages, {
|
/** @type {ChatVertexAI} */
|
||||||
|
const client = this.client;
|
||||||
|
const stream = await client.stream(messages, {
|
||||||
signal: abortController.signal,
|
signal: abortController.signal,
|
||||||
streamUsage: true,
|
streamUsage: true,
|
||||||
safetySettings,
|
safetySettings,
|
||||||
|
|
@ -681,10 +692,18 @@ class GoogleClient extends BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
usageMetadata = !usageMetadata
|
if (chunk?.usage_metadata) {
|
||||||
? chunk?.usage_metadata
|
const metadata = chunk.usage_metadata;
|
||||||
: concat(usageMetadata, chunk?.usage_metadata);
|
for (const key in metadata) {
|
||||||
const chunkText = chunk?.content ?? chunk;
|
if (Number.isNaN(metadata[key])) {
|
||||||
|
delete metadata[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usageMetadata = !usageMetadata ? metadata : concat(usageMetadata, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chunkText = chunk?.content ?? '';
|
||||||
await this.generateTextStream(chunkText, onProgress, {
|
await this.generateTextStream(chunkText, onProgress, {
|
||||||
delay,
|
delay,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
"@langchain/google-genai": "^0.1.7",
|
"@langchain/google-genai": "^0.1.7",
|
||||||
"@langchain/google-vertexai": "^0.1.8",
|
"@langchain/google-vertexai": "^0.1.8",
|
||||||
"@langchain/textsplitters": "^0.1.0",
|
"@langchain/textsplitters": "^0.1.0",
|
||||||
"@librechat/agents": "^2.0.0",
|
"@librechat/agents": "^2.0.1",
|
||||||
"@waylaidwanderer/fetch-event-source": "^3.0.1",
|
"@waylaidwanderer/fetch-event-source": "^3.0.1",
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
|
|
|
||||||
1132
package-lock.json
generated
1132
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue