mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
✨ 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:
parent
486fe34a2b
commit
7147bce3c3
14 changed files with 989 additions and 6 deletions
|
|
@ -8,6 +8,62 @@ import type * as t from '~/types';
|
|||
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
|
||||
import { isEnabled } from '~/utils/common';
|
||||
|
||||
export const knownOpenAIParams = new Set([
|
||||
// Constructor/Instance Parameters
|
||||
'model',
|
||||
'modelName',
|
||||
'temperature',
|
||||
'topP',
|
||||
'frequencyPenalty',
|
||||
'presencePenalty',
|
||||
'n',
|
||||
'logitBias',
|
||||
'stop',
|
||||
'stopSequences',
|
||||
'user',
|
||||
'timeout',
|
||||
'stream',
|
||||
'maxTokens',
|
||||
'maxCompletionTokens',
|
||||
'logprobs',
|
||||
'topLogprobs',
|
||||
'apiKey',
|
||||
'organization',
|
||||
'audio',
|
||||
'modalities',
|
||||
'reasoning',
|
||||
'zdrEnabled',
|
||||
'service_tier',
|
||||
'supportsStrictToolCalling',
|
||||
'useResponsesApi',
|
||||
'configuration',
|
||||
// Call-time Options
|
||||
'tools',
|
||||
'tool_choice',
|
||||
'functions',
|
||||
'function_call',
|
||||
'response_format',
|
||||
'seed',
|
||||
'stream_options',
|
||||
'parallel_tool_calls',
|
||||
'strict',
|
||||
'prediction',
|
||||
'promptIndex',
|
||||
// Responses API specific
|
||||
'text',
|
||||
'truncation',
|
||||
'include',
|
||||
'previous_response_id',
|
||||
// LangChain specific
|
||||
'__includeRawResponse',
|
||||
'maxConcurrency',
|
||||
'maxRetries',
|
||||
'verbose',
|
||||
'streaming',
|
||||
'streamUsage',
|
||||
'disableStreaming',
|
||||
]);
|
||||
|
||||
function hasReasoningParams({
|
||||
reasoning_effort,
|
||||
reasoning_summary,
|
||||
|
|
@ -44,7 +100,7 @@ export function getOpenAIConfig(
|
|||
addParams,
|
||||
dropParams,
|
||||
} = options;
|
||||
const { reasoning_effort, reasoning_summary, ...modelOptions } = _modelOptions;
|
||||
const { reasoning_effort, reasoning_summary, verbosity, ...modelOptions } = _modelOptions;
|
||||
const llmConfig: Partial<t.ClientOptions> &
|
||||
Partial<t.OpenAIParameters> &
|
||||
Partial<AzureOpenAIInput> = Object.assign(
|
||||
|
|
@ -55,8 +111,23 @@ export function getOpenAIConfig(
|
|||
modelOptions,
|
||||
);
|
||||
|
||||
const modelKwargs: Record<string, unknown> = {};
|
||||
let hasModelKwargs = false;
|
||||
|
||||
if (verbosity != null && verbosity !== '') {
|
||||
modelKwargs.verbosity = verbosity;
|
||||
hasModelKwargs = true;
|
||||
}
|
||||
|
||||
if (addParams && typeof addParams === 'object') {
|
||||
Object.assign(llmConfig, addParams);
|
||||
for (const [key, value] of Object.entries(addParams)) {
|
||||
if (knownOpenAIParams.has(key)) {
|
||||
(llmConfig as Record<string, unknown>)[key] = value;
|
||||
} else {
|
||||
hasModelKwargs = true;
|
||||
modelKwargs[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let useOpenRouter = false;
|
||||
|
|
@ -223,6 +294,21 @@ export function getOpenAIConfig(
|
|||
});
|
||||
}
|
||||
|
||||
if (modelKwargs.verbosity && llmConfig.useResponsesApi === true) {
|
||||
modelKwargs.text = { verbosity: modelKwargs.verbosity };
|
||||
delete modelKwargs.verbosity;
|
||||
}
|
||||
|
||||
if (llmConfig.model && /\bgpt-[5-9]\b/i.test(llmConfig.model) && llmConfig.maxTokens != null) {
|
||||
modelKwargs.max_completion_tokens = llmConfig.maxTokens;
|
||||
delete llmConfig.maxTokens;
|
||||
hasModelKwargs = true;
|
||||
}
|
||||
|
||||
if (hasModelKwargs) {
|
||||
llmConfig.modelKwargs = modelKwargs;
|
||||
}
|
||||
|
||||
const result: t.LLMConfigResult = {
|
||||
llmConfig,
|
||||
configOptions,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue