mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-13 11:26:18 +01:00
feat: add anthropic llm config support for openai-like (custom) endpoints
This commit is contained in:
parent
d5accf55c8
commit
f1dab7f924
2 changed files with 31 additions and 7 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
import { ProxyAgent } from 'undici';
|
import { ProxyAgent } from 'undici';
|
||||||
import { Providers } from '@librechat/agents';
|
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 { BindToolsInput } from '@langchain/core/language_models/chat_models';
|
||||||
import type { AzureOpenAIInput } from '@langchain/openai';
|
import type { AzureOpenAIInput } from '@langchain/openai';
|
||||||
import type { OpenAI } from 'openai';
|
import type { OpenAI } from 'openai';
|
||||||
import type * as t from '~/types';
|
import type * as t from '~/types';
|
||||||
|
import { getLLMConfig as getAnthropicLLMConfig } from '~/endpoints/anthropic/llm';
|
||||||
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
|
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
|
||||||
import { createFetch } from '~/utils/generators';
|
import { createFetch } from '~/utils/generators';
|
||||||
import { isEnabled } from '~/utils/common';
|
import { isEnabled } from '~/utils/common';
|
||||||
|
|
@ -233,12 +235,30 @@ export function getOpenAIConfig(
|
||||||
dropParams,
|
dropParams,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const { llmConfig, tools } = getOpenAILLMConfig({
|
let llmConfig:
|
||||||
streaming,
|
| (Partial<t.ClientOptions> & Partial<t.OpenAIParameters> & Partial<AzureOpenAIInput>)
|
||||||
modelOptions: _modelOptions,
|
| AnthropicClientOptions;
|
||||||
addParams,
|
let tools: BindToolsInput[];
|
||||||
dropParams,
|
|
||||||
});
|
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;
|
let useOpenRouter = false;
|
||||||
const configOptions: t.OpenAIConfiguration = {};
|
const configOptions: t.OpenAIConfiguration = {};
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ export interface OpenAIConfigOptions {
|
||||||
streaming?: boolean;
|
streaming?: boolean;
|
||||||
addParams?: Record<string, unknown>;
|
addParams?: Record<string, unknown>;
|
||||||
dropParams?: string[];
|
dropParams?: string[];
|
||||||
|
customParams?: {
|
||||||
|
defaultParamsEndpoint?: string;
|
||||||
|
};
|
||||||
|
userId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OpenAIConfiguration = OpenAIClientOptions['configuration'];
|
export type OpenAIConfiguration = OpenAIClientOptions['configuration'];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue