@@ -34,6 +34,14 @@ const (
3434 tempNotSupportedError = "temperature %.2f is not supported by Anthropic (must be between 0.0 and 1.0)"
3535)
3636
37+ // anthropicInputSchemaKeysToSkip defines the keys from an OpenAI function parameter map
38+ // that are handled explicitly and should not go into the ExtraFields map.
39+ var anthropicInputSchemaKeysToSkip = map [string ]struct {}{
40+ "required" : {},
41+ "type" : {},
42+ "properties" : {},
43+ }
44+
3745// NewChatCompletionOpenAIToGCPAnthropicTranslator implements [Factory] for OpenAI to GCP Anthropic translation.
3846// This translator converts OpenAI ChatCompletion API requests to GCP Anthropic API format.
3947func NewChatCompletionOpenAIToGCPAnthropicTranslator (apiVersion string , modelNameOverride internalapi.ModelNameOverride ) OpenAIChatCompletionTranslator {
@@ -184,24 +192,17 @@ func translateOpenAItoAnthropicTools(openAITools []openai.Tool, openAIToolChoice
184192 inputSchema .Required = requiredSlice
185193 }
186194
187- // Keys to skip
188- keysToSkip := map [string ]bool {
189- "required" : true ,
190- "type" : true ,
191- "properties" : true ,
192- }
193-
194195 // ExtraFieldsMap to construct
195196 ExtraFieldsMap := make (map [string ]any )
196197
197- // Iterate over the original map
198+ // Iterate over the original map from openai
198199 for key , value := range paramsMap {
199200 // Check if the current key should be skipped
200- if _ , found := keysToSkip [key ]; found {
201- continue // Skip the current iteration
201+ if _ , found := anthropicInputSchemaKeysToSkip [key ]; found {
202+ continue
202203 }
203204
204- // If not skipped, add the key-value pair to the new map
205+ // If not skipped, add the key-value pair to extra field map
205206 ExtraFieldsMap [key ] = value
206207 }
207208 inputSchema .ExtraFields = ExtraFieldsMap
0 commit comments