@@ -85,7 +85,16 @@ func (c *claudeProviderInitializer) ValidateConfig(config *ProviderConfig) error
85
85
return nil
86
86
}
87
87
88
+ func (c * claudeProviderInitializer ) DefaultCapabilities () map [string ]string {
89
+ return map [string ]string {
90
+ string (ApiNameChatCompletion ): claudeChatCompletionPath ,
91
+ // docs: https://docs.anthropic.com/en/docs/build-with-claude/embeddings#voyage-http-api
92
+ string (ApiNameEmbeddings ): PathOpenAIEmbeddings ,
93
+ }
94
+ }
95
+
88
96
func (c * claudeProviderInitializer ) CreateProvider (config ProviderConfig ) (Provider , error ) {
97
+ config .setDefaultCapabilities (c .DefaultCapabilities ())
89
98
return & claudeProvider {
90
99
config : config ,
91
100
contextCache : createContextCache (& config ),
@@ -102,15 +111,15 @@ func (c *claudeProvider) GetProviderType() string {
102
111
}
103
112
104
113
func (c * claudeProvider ) OnRequestHeaders (ctx wrapper.HttpContext , apiName ApiName , log wrapper.Log ) error {
105
- if apiName != ApiNameChatCompletion {
114
+ if ! c . config . isSupportedAPI ( apiName ) {
106
115
return errUnsupportedApiName
107
116
}
108
117
c .config .handleRequestHeaders (c , ctx , apiName , log )
109
118
return nil
110
119
}
111
120
112
121
func (c * claudeProvider ) TransformRequestHeaders (ctx wrapper.HttpContext , apiName ApiName , headers http.Header , log wrapper.Log ) {
113
- util .OverwriteRequestPathHeader (headers , claudeChatCompletionPath )
122
+ util .OverwriteRequestPathHeaderByCapability (headers , string ( apiName ), c . config . capabilities )
114
123
util .OverwriteRequestHostHeader (headers , claudeDomain )
115
124
116
125
headers .Set ("x-api-key" , c .config .GetApiTokenInUse (ctx ))
@@ -123,13 +132,16 @@ func (c *claudeProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiNam
123
132
}
124
133
125
134
func (c * claudeProvider ) OnRequestBody (ctx wrapper.HttpContext , apiName ApiName , body []byte , log wrapper.Log ) (types.Action , error ) {
126
- if apiName != ApiNameChatCompletion {
135
+ if ! c . config . isSupportedAPI ( apiName ) {
127
136
return types .ActionContinue , errUnsupportedApiName
128
137
}
129
138
return c .config .handleRequestBody (c , c .contextCache , ctx , apiName , body , log )
130
139
}
131
140
132
141
func (c * claudeProvider ) TransformRequestBody (ctx wrapper.HttpContext , apiName ApiName , body []byte , log wrapper.Log ) ([]byte , error ) {
142
+ if apiName != ApiNameChatCompletion {
143
+ return c .config .defaultTransformRequestBody (ctx , apiName , body , log )
144
+ }
133
145
request := & chatCompletionRequest {}
134
146
if err := c .config .parseRequestAndMapModel (ctx , request , body , log ); err != nil {
135
147
return nil , err
@@ -139,6 +151,9 @@ func (c *claudeProvider) TransformRequestBody(ctx wrapper.HttpContext, apiName A
139
151
}
140
152
141
153
func (c * claudeProvider ) TransformResponseBody (ctx wrapper.HttpContext , apiName ApiName , body []byte , log wrapper.Log ) ([]byte , error ) {
154
+ if apiName != ApiNameChatCompletion {
155
+ return body , nil
156
+ }
142
157
claudeResponse := & claudeTextGenResponse {}
143
158
if err := json .Unmarshal (body , claudeResponse ); err != nil {
144
159
return nil , fmt .Errorf ("unable to unmarshal claude response: %v" , err )
@@ -154,6 +169,10 @@ func (c *claudeProvider) OnStreamingResponseBody(ctx wrapper.HttpContext, name A
154
169
if isLastChunk || len (chunk ) == 0 {
155
170
return nil , nil
156
171
}
172
+ // only process the response from chat completion, skip other responses
173
+ if name != ApiNameChatCompletion {
174
+ return chunk , nil
175
+ }
157
176
158
177
responseBuilder := & strings.Builder {}
159
178
lines := strings .Split (string (chunk ), "\n " )
0 commit comments