feat: Add OpenAI Verbosity Parameter (#8929)

* WIP: Verbosity OpenAI Parameter

* 🔧 chore: remove unused import of extractEnvVariable from parsers.ts

*  feat: add comprehensive tests for getOpenAIConfig and enhance verbosity handling

* fix: Handling for maxTokens in GPT-5+ models and add corresponding tests

* feat: Implement GPT-5+ model handling in processMemory function
This commit is contained in:
Danny Avila 2025-08-07 20:49:40 -04:00 committed by GitHub
parent 486fe34a2b
commit 7147bce3c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 989 additions and 6 deletions

View file

@ -5,8 +5,10 @@ import { Tools } from 'librechat-data-provider';
import { logger } from '@librechat/data-schemas';
import { Run, Providers, GraphEvents } from '@librechat/agents';
import type {
OpenAIClientOptions,
StreamEventData,
ToolEndCallback,
ClientOptions,
EventHandler,
ToolEndData,
LLMConfig,
@ -332,7 +334,7 @@ ${memory ?? 'No existing memories'}`;
disableStreaming: true,
};
const finalLLMConfig = {
const finalLLMConfig: ClientOptions = {
...defaultLLMConfig,
...llmConfig,
/**
@ -342,6 +344,20 @@ ${memory ?? 'No existing memories'}`;
disableStreaming: true,
};
// Handle GPT-5+ models
if ('model' in finalLLMConfig && /\bgpt-[5-9]\b/i.test(finalLLMConfig.model ?? '')) {
// Remove temperature for GPT-5+ models
delete finalLLMConfig.temperature;
// Move maxTokens to modelKwargs for GPT-5+ models
if ('maxTokens' in finalLLMConfig && finalLLMConfig.maxTokens != null) {
const modelKwargs = (finalLLMConfig as OpenAIClientOptions).modelKwargs ?? {};
modelKwargs.max_completion_tokens = finalLLMConfig.maxTokens;
delete finalLLMConfig.maxTokens;
(finalLLMConfig as OpenAIClientOptions).modelKwargs = modelKwargs;
}
}
const artifactPromises: Promise<TAttachment | null>[] = [];
const memoryCallback = createMemoryCallback({ res, artifactPromises });
const customHandlers = {