Perplexica/src/lib/providers/anthropic.ts

67 lines
1.5 KiB
TypeScript
Raw Normal View History

import { ChatAnthropic } from '@langchain/anthropic';
2025-03-19 16:23:27 +05:30
import { ChatModel } from '.';
import { getAnthropicApiKey } from '../config';
export const PROVIDER_INFO = {
key: 'anthropic',
2025-04-12 11:58:52 +05:30
displayName: 'Anthropic',
};
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,
model: new ChatAnthropic({
apiKey: anthropicApiKey,
2025-03-19 16:23:27 +05:30
modelName: model.key,
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 {};
}
};