From 6a10bb1ba0cb4858b1a1f22c983c53f9f820d63a Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 29 Aug 2024 14:00:44 +0300 Subject: [PATCH] fix: anthropic typo and add helicone to it --- src/models.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/models.ts b/src/models.ts index 231f387..b89fc6c 100644 --- a/src/models.ts +++ b/src/models.ts @@ -72,7 +72,8 @@ type Providers = | "groq" | "togetherai" | "openrouter" - | "mistral"; + | "mistral" + | "anthropic"; type AnalyticsConfig = | { name: "helicone"; token: string } | { name: "langsmith"; token: string; apiUrl?: string } @@ -108,6 +109,15 @@ const setupAnalytics = ( }, }; } + case "anthropic": { + return { + baseURL: "https://anthropic.helicone.ai", + defaultHeaders: { + "Helicone-Auth": `Bearer ${analytics.token}`, + Authorization: `Bearer ${providerApiKey}`, + }, + }; + } case "upstash": { return { baseURL: "https://qstash.helicone.ai/llm/v1", @@ -266,9 +276,20 @@ export const mistralai = (model: string, options?: Omit }); }; -export const antrophic = (model: string, options?: Omit) => { +export const anthropic = (model: string, options?: Omit) => { + if (!options?.apiKey) { + throw new Error("Failed to create Anthropic client: Anthropic key not found."); + } + const analyticsSetup = options.analytics + ? setupAnalytics(options.analytics, options.apiKey, undefined, "anthropic") + : undefined; + return new ChatAnthropic({ model, ...options, + clientOptions: { + baseURL: analyticsSetup?.baseURL, + defaultHeaders: analyticsSetup?.defaultHeaders, + }, }); };