🤖 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:
Danny Avila 2025-02-04 21:45:43 -05:00 committed by GitHub
parent 0312d4f4f4
commit 6c33dc2eb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 587 additions and 580 deletions

View file

@ -566,7 +566,16 @@ class GoogleClient extends BaseClient {
if (this.project_id != null) {
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)) {
logger.debug('Creating GenAI client');
return new GenAI(this.apiKey).getGenerativeModel({ model }, requestOptions);
@ -577,7 +586,7 @@ class GoogleClient extends BaseClient {
}
initializeClient() {
let clientOptions = { ...this.modelOptions, maxRetries: 2 };
let clientOptions = { ...this.modelOptions };
if (this.project_id) {
clientOptions['authOptions'] = {
@ -663,7 +672,9 @@ class GoogleClient extends BaseClient {
/** @type {import('@langchain/core/messages').AIMessageChunk['usage_metadata']} */
let usageMetadata;
const stream = await this.client.stream(messages, {
/** @type {ChatVertexAI} */
const client = this.client;
const stream = await client.stream(messages, {
signal: abortController.signal,
streamUsage: true,
safetySettings,
@ -681,10 +692,18 @@ class GoogleClient extends BaseClient {
}
for await (const chunk of stream) {
usageMetadata = !usageMetadata
? chunk?.usage_metadata
: concat(usageMetadata, chunk?.usage_metadata);
const chunkText = chunk?.content ?? chunk;
if (chunk?.usage_metadata) {
const metadata = chunk.usage_metadata;
for (const key in metadata) {
if (Number.isNaN(metadata[key])) {
delete metadata[key];
}
}
usageMetadata = !usageMetadata ? metadata : concat(usageMetadata, metadata);
}
const chunkText = chunk?.content ?? '';
await this.generateTextStream(chunkText, onProgress, {
delay,
});