Skip to content

Commit af5f03f

Browse files
committed
fix-comments
Signed-off-by: yxia216 <[email protected]>
1 parent 5bd0014 commit af5f03f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

internal/translator/openai_gcpanthropic.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ const (
3535
tempNotSupportedError = "temperature %.2f is not supported by Anthropic (must be between 0.0 and 1.0)"
3636
)
3737

38+
// anthropicInputSchemaKeysToSkip defines the keys from an OpenAI function parameter map
39+
// that are handled explicitly and should not go into the ExtraFields map.
40+
var anthropicInputSchemaKeysToSkip = map[string]struct{}{
41+
"required": {},
42+
"type": {},
43+
"properties": {},
44+
}
45+
3846
// NewChatCompletionOpenAIToGCPAnthropicTranslator implements [Factory] for OpenAI to GCP Anthropic translation.
3947
// This translator converts OpenAI ChatCompletion API requests to GCP Anthropic API format.
4048
func NewChatCompletionOpenAIToGCPAnthropicTranslator(apiVersion string, modelNameOverride internalapi.ModelNameOverride) OpenAIChatCompletionTranslator {
@@ -199,24 +207,17 @@ func translateOpenAItoAnthropicTools(openAITools []openai.Tool, openAIToolChoice
199207
inputSchema.Required = requiredSlice
200208
}
201209

202-
// Keys to skip
203-
keysToSkip := map[string]bool{
204-
"required": true,
205-
"type": true,
206-
"properties": true,
207-
}
208-
209210
// ExtraFieldsMap to construct
210211
ExtraFieldsMap := make(map[string]any)
211212

212-
// Iterate over the original map
213+
// Iterate over the original map from openai
213214
for key, value := range paramsMap {
214215
// Check if the current key should be skipped
215-
if _, found := keysToSkip[key]; found {
216-
continue // Skip the current iteration
216+
if _, found := anthropicInputSchemaKeysToSkip[key]; found {
217+
continue
217218
}
218219

219-
// If not skipped, add the key-value pair to the new map
220+
// If not skipped, add the key-value pair to extra field map
220221
ExtraFieldsMap[key] = value
221222
}
222223
inputSchema.ExtraFields = ExtraFieldsMap

0 commit comments

Comments
 (0)