Skip to content

Commit 3c662fa

Browse files
fix: latest changes to enable gpt 5 models
1 parent 63c2fff commit 3c662fa

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

packages/api/src/endpoints/openai/llm.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { HttpsProxyAgent } from 'https-proxy-agent';
2-
import { KnownEndpoints } from 'librechat-data-provider';
3-
import type { AzureOpenAIInput } from '@langchain/azure-openai';
2+
import { KnownEndpoints, ReasoningEffort, ReasoningSummary, Verbosity } from 'librechat-data-provider';
3+
import type { AzureOpenAIInput } from '@langchain/openai';
4+
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
5+
import type { OpenAI } from 'openai';
46
import type * as t from '~/types';
57
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
68
import { isEnabled } from '~/utils/common';
@@ -82,7 +84,7 @@ function hasReasoningParams({
8284
*/
8385
export function getOpenAIConfig(
8486
apiKey: string,
85-
options: t.LLMConfigOptions = {},
87+
options: t.OpenAIConfigOptions = {},
8688
endpoint?: string | null,
8789
): t.LLMConfigResult {
8890
const {
@@ -174,18 +176,18 @@ export function getOpenAIConfig(
174176

175177
// Handle reasoning parameters for Responses API
176178
if (hasReasoningParams({ reasoning_effort, reasoning_summary })) {
177-
if (reasoning_effort && reasoning_effort !== '') {
179+
if (reasoning_effort != null && reasoning_effort !== ReasoningEffort.none) {
178180
modelKwargs.reasoning_effort = reasoning_effort;
179181
hasModelKwargs = true;
180182
}
181-
if (reasoning_summary && reasoning_summary !== '') {
183+
if (reasoning_summary != null && reasoning_summary !== ReasoningSummary.none) {
182184
modelKwargs.reasoning_summary = reasoning_summary;
183185
hasModelKwargs = true;
184186
}
185187
}
186188

187189
// Add verbosity parameter
188-
if (verbosity && verbosity !== '') {
190+
if (verbosity != null && verbosity !== Verbosity.none) {
189191
modelKwargs.verbosity = verbosity;
190192
hasModelKwargs = true;
191193
}
@@ -256,7 +258,7 @@ export function getOpenAIConfig(
256258

257259
if (useOpenRouter && llmConfig.reasoning_effort != null) {
258260
llmConfig.reasoning = {
259-
effort: llmConfig.reasoning_effort,
261+
effort: llmConfig.reasoning_effort as any,
260262
};
261263
delete llmConfig.reasoning_effort;
262264
}
@@ -270,10 +272,22 @@ export function getOpenAIConfig(
270272
llmConfig.modelKwargs = modelKwargs;
271273
}
272274

275+
const tools: BindToolsInput[] = [];
276+
277+
if (modelOptions.web_search) {
278+
llmConfig.useResponsesApi = true;
279+
tools.push({ type: 'web_search_preview' });
280+
}
281+
273282
const result: t.LLMConfigResult = {
274283
llmConfig,
275284
configOptions,
285+
tools,
276286
};
277287

288+
if (useOpenRouter) {
289+
result.provider = 'openrouter';
290+
}
291+
278292
return result;
279293
}

packages/api/src/types/openai.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { z } from 'zod';
22
import { openAISchema, EModelEndpoint } from 'librechat-data-provider';
33
import type { TEndpointOption, TAzureConfig, TEndpoint } from 'librechat-data-provider';
44
import type { OpenAIClientOptions } from '@librechat/agents';
5+
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
56
import type { AzureOptions } from './azure';
67

78
export type OpenAIParameters = z.infer<typeof openAISchema>;
89

910
/**
1011
* Configuration options for the getLLMConfig function
1112
*/
12-
export interface LLMConfigOptions {
13+
export interface OpenAIConfigOptions {
1314
modelOptions?: Partial<OpenAIParameters>;
1415
reverseProxyUrl?: string;
1516
defaultQuery?: Record<string, string | undefined>;
@@ -21,7 +22,14 @@ export interface LLMConfigOptions {
2122
dropParams?: string[];
2223
}
2324

24-
export type OpenAIConfiguration = OpenAIClientOptions['configuration'];
25+
export interface LLMConfigOptions extends OpenAIConfigOptions {}
26+
27+
export type OpenAIConfiguration = OpenAIClientOptions['configuration'] & {
28+
fetchOptions?: {
29+
dispatcher?: any;
30+
};
31+
httpAgent?: any;
32+
};
2533

2634
export type ClientOptions = OpenAIClientOptions & {
2735
include_reasoning?: boolean;
@@ -33,6 +41,8 @@ export type ClientOptions = OpenAIClientOptions & {
3341
export interface LLMConfigResult {
3442
llmConfig: ClientOptions;
3543
configOptions: OpenAIConfiguration;
44+
tools?: BindToolsInput[];
45+
provider?: string;
3646
}
3747

3848
/**

packages/data-provider/src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ export const alternateName = {
936936
const sharedOpenAIModels = [
937937
'gpt-4o-mini',
938938
'gpt-4o',
939+
'gpt-5',
940+
'gpt-5-mini',
941+
'gpt-5-nano',
939942
'gpt-4.5-preview',
940943
'gpt-4.5-preview-2025-02-27',
941944
'gpt-3.5-turbo',

0 commit comments

Comments
 (0)