🛣️ feat: directEndpoint Fetch Override for Custom Endpoints (#9179)

* feat: Add directEndpoint option to OpenAIConfigOptions and update fetch logic to override /chat/completions URL

* feat: Add directEndpoint support to fetchModels and update loadConfigModels logic
This commit is contained in:
Danny Avila 2025-08-20 15:55:32 -04:00 committed by GitHub
parent e0ebb7097e
commit a49b2b2833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 4 deletions

View file

@ -6,8 +6,11 @@ import type { AzureOpenAIInput } from '@langchain/openai';
import type { OpenAI } from 'openai';
import type * as t from '~/types';
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
import { createFetch } from '~/utils/generators';
import { isEnabled } from '~/utils/common';
type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
export const knownOpenAIParams = new Set([
// Constructor/Instance Parameters
'model',
@ -92,6 +95,7 @@ export function getOpenAIConfig(
const {
modelOptions: _modelOptions = {},
reverseProxyUrl,
directEndpoint,
defaultQuery,
headers,
proxy,
@ -311,6 +315,13 @@ export function getOpenAIConfig(
llmConfig.modelKwargs = modelKwargs;
}
if (directEndpoint === true && configOptions?.baseURL != null) {
configOptions.fetch = createFetch({
directEndpoint: directEndpoint,
reverseProxyUrl: configOptions?.baseURL,
}) as unknown as Fetch;
}
const result: t.LLMConfigResult = {
llmConfig,
configOptions,

View file

@ -12,6 +12,7 @@ export type OpenAIParameters = z.infer<typeof openAISchema>;
*/
export interface OpenAIConfigOptions {
modelOptions?: Partial<OpenAIParameters>;
directEndpoint?: boolean;
reverseProxyUrl?: string;
defaultQuery?: Record<string, string | undefined>;
headers?: Record<string, string>;