feat: add anthropic llm config support for openai-like (custom) endpoints

This commit is contained in:
Dustin Healy 2025-08-30 23:31:53 -07:00 committed by Danny Avila
parent d5accf55c8
commit f1dab7f924
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
2 changed files with 31 additions and 7 deletions

View file

@ -1,10 +1,12 @@
import { ProxyAgent } from 'undici';
import { Providers } from '@librechat/agents';
import { KnownEndpoints, removeNullishValues } from 'librechat-data-provider';
import type { AnthropicClientOptions } from '@librechat/agents';
import { KnownEndpoints, removeNullishValues, EModelEndpoint } from 'librechat-data-provider';
import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
import type { AzureOpenAIInput } from '@langchain/openai';
import type { OpenAI } from 'openai';
import type * as t from '~/types';
import { getLLMConfig as getAnthropicLLMConfig } from '~/endpoints/anthropic/llm';
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
import { createFetch } from '~/utils/generators';
import { isEnabled } from '~/utils/common';
@ -233,12 +235,30 @@ export function getOpenAIConfig(
dropParams,
} = options;
const { llmConfig, tools } = getOpenAILLMConfig({
streaming,
modelOptions: _modelOptions,
addParams,
dropParams,
});
let llmConfig:
| (Partial<t.ClientOptions> & Partial<t.OpenAIParameters> & Partial<AzureOpenAIInput>)
| AnthropicClientOptions;
let tools: BindToolsInput[];
if (options.customParams?.defaultParamsEndpoint === EModelEndpoint.anthropic) {
const anthropicResult = getAnthropicLLMConfig(apiKey, {
modelOptions: _modelOptions,
userId: options.userId || '',
proxy: options.proxy,
reverseProxyUrl: options.reverseProxyUrl,
});
llmConfig = anthropicResult.llmConfig;
tools = anthropicResult.tools;
} else {
const openaiResult = getOpenAILLMConfig({
streaming,
modelOptions: _modelOptions,
addParams,
dropParams,
});
llmConfig = openaiResult.llmConfig;
tools = openaiResult.tools;
}
let useOpenRouter = false;
const configOptions: t.OpenAIConfiguration = {};

View file

@ -22,6 +22,10 @@ export interface OpenAIConfigOptions {
streaming?: boolean;
addParams?: Record<string, unknown>;
dropParams?: string[];
customParams?: {
defaultParamsEndpoint?: string;
};
userId?: string;
}
export type OpenAIConfiguration = OpenAIClientOptions['configuration'];