- 新增 pkg/gemini: 模型定义与回退列表 - 新增 pkg/googleapi: Google API 错误状态处理 - 新增 pkg/geminicli/models.go: CLI 模型结构 - 更新 constants.go: AI Studio 相关常量 - 更新 oauth.go: 支持 AI Studio OAuth 流程,凭据通过环境变量配置
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package gemini
|
|
|
|
// This package provides minimal fallback model metadata for Gemini native endpoints.
|
|
// It is used when upstream model listing is unavailable (e.g. OAuth token missing AI Studio scopes).
|
|
|
|
type Model struct {
|
|
Name string `json:"name"`
|
|
DisplayName string `json:"displayName,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
SupportedGenerationMethods []string `json:"supportedGenerationMethods,omitempty"`
|
|
}
|
|
|
|
type ModelsListResponse struct {
|
|
Models []Model `json:"models"`
|
|
}
|
|
|
|
func DefaultModels() []Model {
|
|
methods := []string{"generateContent", "streamGenerateContent"}
|
|
return []Model{
|
|
{Name: "models/gemini-3-pro-preview", SupportedGenerationMethods: methods},
|
|
{Name: "models/gemini-2.0-flash", SupportedGenerationMethods: methods},
|
|
{Name: "models/gemini-2.0-flash-lite", SupportedGenerationMethods: methods},
|
|
{Name: "models/gemini-1.5-pro", SupportedGenerationMethods: methods},
|
|
{Name: "models/gemini-1.5-flash", SupportedGenerationMethods: methods},
|
|
{Name: "models/gemini-1.5-flash-8b", SupportedGenerationMethods: methods},
|
|
}
|
|
}
|
|
|
|
func FallbackModelsList() ModelsListResponse {
|
|
return ModelsListResponse{Models: DefaultModels()}
|
|
}
|
|
|
|
func FallbackModel(model string) Model {
|
|
methods := []string{"generateContent", "streamGenerateContent"}
|
|
if model == "" {
|
|
return Model{Name: "models/unknown", SupportedGenerationMethods: methods}
|
|
}
|
|
if len(model) >= 7 && model[:7] == "models/" {
|
|
return Model{Name: model, SupportedGenerationMethods: methods}
|
|
}
|
|
return Model{Name: "models/" + model, SupportedGenerationMethods: methods}
|
|
}
|
|
|