@@ -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 {
@@ -194,24 +202,17 @@ func translateOpenAItoAnthropicTools(openAITools []openai.Tool, openAIToolChoice
194202 inputSchema .Required = requiredSlice
195203 }
196204
197- // Keys to skip
198- keysToSkip := map [string ]bool {
199- "required" : true ,
200- "type" : true ,
201- "properties" : true ,
202- }
203-
204205 // ExtraFieldsMap to construct
205206 ExtraFieldsMap := make (map [string ]any )
206207
207- // Iterate over the original map
208+ // Iterate over the original map from openai
208209 for key , value := range paramsMap {
209210 // Check if the current key should be skipped
210- if _ , found := keysToSkip [key ]; found {
211- continue // Skip the current iteration
211+ if _ , found := anthropicInputSchemaKeysToSkip [key ]; found {
212+ continue
212213 }
213214
214- // If not skipped, add the key-value pair to the new map
215+ // If not skipped, add the key-value pair to extra field map
215216 ExtraFieldsMap [key ] = value
216217 }
217218 inputSchema .ExtraFields = ExtraFieldsMap
0 commit comments