File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
packages/cost/models/providers
worker/src/lib/clients/llmmapper/providers/openai/request Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import type {
44 AuthResult ,
55 ModelProviderConfig ,
66 UserEndpointConfig ,
7+ Endpoint ,
8+ RequestBodyContext ,
79} from "../types" ;
810
911export class AnthropicProvider extends BaseProvider {
@@ -24,16 +26,22 @@ export class AnthropicProvider extends BaseProvider {
2426 if ( userConfig . gatewayMapping === "NO_MAPPING" ) {
2527 return "https://api.anthropic.com/v1/messages" ;
2628 }
27- return "https://api.anthropic.com/v1/chat/completions " ;
29+ return "https://api.anthropic.com/v1/messages " ;
2830 }
2931
3032 authenticate ( context : AuthContext ) : AuthResult {
3133 const headers : Record < string , string > = { } ;
32- if ( context . bodyMapping === "NO_MAPPING" ) {
33- headers [ "x-api-key" ] = context . apiKey || "" ;
34- } else {
35- headers [ "Authorization" ] = `Bearer ${ context . apiKey || "" } ` ;
36- }
34+ headers [ "x-api-key" ] = context . apiKey || "" ;
35+ headers [ "anthropic-version" ] = "2023-06-01" ;
3736 return { headers } ;
3837 }
38+
39+ buildRequestBody ( endpoint : Endpoint , context : RequestBodyContext ) : string {
40+ const anthropicBody = context . toAnthropic ( context . parsedBody ) ;
41+ const updatedBody = {
42+ ...anthropicBody ,
43+ // anthropic_version: "2023-06-01",
44+ } ;
45+ return JSON . stringify ( updatedBody ) ;
46+ }
3947}
Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ function extractSystemMessage(messages: OpenAIRequestBody["messages"]): {
5555}
5656
5757function mapModel ( model : string ) : string {
58+ if ( model . includes ( 'claude-3.5-haiku' ) ) {
59+ return 'claude-3-5-haiku-20241022' ;
60+ } else if ( model . includes ( 'claude-3.5-sonnet' ) ) {
61+ return 'claude-3-5-sonnet-latest' ;
62+ }
5863 return model ;
5964}
6065
You can’t perform that action at this time.
0 commit comments