2025-03-25 22:01:24 +05:30
|
|
|
import { ChatAnthropic } from '@langchain/anthropic';
|
2025-03-19 16:23:27 +05:30
|
|
|
import { ChatModel } from '.';
|
|
|
|
|
import { getAnthropicApiKey } from '../config';
|
2025-04-01 19:26:15 +04:00
|
|
|
|
|
|
|
|
export const PROVIDER_INFO = {
|
|
|
|
|
key: 'anthropic',
|
2025-04-12 11:58:52 +05:30
|
|
|
displayName: 'Anthropic',
|
2025-04-01 19:26:15 +04:00
|
|
|
};
|
2025-03-19 16:23:27 +05:30
|
|
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
|
|
|
|
|
|
|
|
const anthropicChatModels: Record<string, string>[] = [
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3.7 Sonnet',
|
|
|
|
|
key: 'claude-3-7-sonnet-20250219',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3.5 Haiku',
|
|
|
|
|
key: 'claude-3-5-haiku-20241022',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3.5 Sonnet v2',
|
|
|
|
|
key: 'claude-3-5-sonnet-20241022',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3.5 Sonnet',
|
|
|
|
|
key: 'claude-3-5-sonnet-20240620',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3 Opus',
|
|
|
|
|
key: 'claude-3-opus-20240229',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3 Sonnet',
|
|
|
|
|
key: 'claude-3-sonnet-20240229',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Claude 3 Haiku',
|
|
|
|
|
key: 'claude-3-haiku-20240307',
|
|
|
|
|
},
|
|
|
|
|
];
|
2024-07-15 21:20:16 +05:30
|
|
|
|
|
|
|
|
export const loadAnthropicChatModels = async () => {
|
|
|
|
|
const anthropicApiKey = getAnthropicApiKey();
|
|
|
|
|
|
|
|
|
|
if (!anthropicApiKey) return {};
|
|
|
|
|
|
|
|
|
|
try {
|
2025-03-19 16:23:27 +05:30
|
|
|
const chatModels: Record<string, ChatModel> = {};
|
|
|
|
|
|
|
|
|
|
anthropicChatModels.forEach((model) => {
|
|
|
|
|
chatModels[model.key] = {
|
|
|
|
|
displayName: model.displayName,
|
2025-03-25 22:01:24 +05:30
|
|
|
model: new ChatAnthropic({
|
|
|
|
|
apiKey: anthropicApiKey,
|
2025-03-19 16:23:27 +05:30
|
|
|
modelName: model.key,
|
2024-09-24 22:34:43 +05:30
|
|
|
temperature: 0.7,
|
2025-03-19 16:23:27 +05:30
|
|
|
}) as unknown as BaseChatModel,
|
|
|
|
|
};
|
|
|
|
|
});
|
2024-07-15 21:20:16 +05:30
|
|
|
|
|
|
|
|
return chatModels;
|
|
|
|
|
} catch (err) {
|
2025-03-19 16:23:27 +05:30
|
|
|
console.error(`Error loading Anthropic models: ${err}`);
|
2024-07-15 21:20:16 +05:30
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
};
|