-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: strip -customtools variant suffix for provider and auth lookup #1958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -801,6 +801,19 @@ func (h *BaseAPIHandler) getRequestDetails(modelName string) (providers []string | |||||
| providers = util.GetProviderName(resolvedModelName) | ||||||
| } | ||||||
|
|
||||||
| // Fallback: strip known model variant suffixes (e.g. "-customtools") for | ||||||
| // provider lookup. The suffix is also stripped from resolvedModelName | ||||||
| // because CPA routes gemini-cli through cloudcode-pa/v1internal (OAuth) | ||||||
| // which does not accept variant suffixes (returns 404). | ||||||
| // The behavioral difference is minor: -customtools only changes tool | ||||||
| // selection priority (prefers custom tools over bash), not model capabilities. | ||||||
| if len(providers) == 0 { | ||||||
| if stripped := stripModelVariantSuffix(baseModel); stripped != baseModel { | ||||||
| providers = util.GetProviderName(stripped) | ||||||
| resolvedModelName = stripModelVariantSuffix(resolvedModelName) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a potential bug here. The A more robust way to strip the variant suffix while preserving the thinking suffix would be to replace the
Suggested change
|
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if len(providers) == 0 { | ||||||
| return nil, "", &interfaces.ErrorMessage{StatusCode: http.StatusBadGateway, Error: fmt.Errorf("unknown provider for model %s", modelName)} | ||||||
| } | ||||||
|
|
@@ -810,6 +823,20 @@ func (h *BaseAPIHandler) getRequestDetails(modelName string) (providers []string | |||||
| return providers, resolvedModelName, nil | ||||||
| } | ||||||
|
|
||||||
| // knownModelVariantSuffixes lists suffixes that Google appends to model names | ||||||
| // for specialised fine-tune variants (e.g. "-customtools" for tool-calling). | ||||||
| // These variants share the same provider/executor as the base model. | ||||||
| var knownModelVariantSuffixes = []string{"-customtools"} | ||||||
|
|
||||||
| func stripModelVariantSuffix(model string) string { | ||||||
| for _, suffix := range knownModelVariantSuffixes { | ||||||
| if strings.HasSuffix(model, suffix) { | ||||||
| return strings.TrimSuffix(model, suffix) | ||||||
| } | ||||||
| } | ||||||
| return model | ||||||
| } | ||||||
|
Comment on lines
+826
to
+838
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helper function and the |
||||||
|
|
||||||
| func cloneBytes(src []byte) []byte { | ||||||
| if len(src) == 0 { | ||||||
| return nil | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper function and the
knownModelVariantSuffixesvariable are also defined insdk/api/handlers/handlers.go. To avoid code duplication and improve maintainability, they should be moved to a shared package. Theinternal/thinking/suffix.gofile seems like a suitable location, as it already handles model name suffix parsing. You would then need to add an import forinternal/thinkingin this file and use the shared function.