mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-09 10:54:59 +01:00
feat: support VertexAI provider (#153)
* support: vertexai fix fix set default for vertexai added comment fix fix * create schema * fix README.md * fix order * added pupularity * set tools if tools is exists restore commentout * fix comment * set summarizer model
This commit is contained in:
@@ -235,6 +235,7 @@ func setProviderDefaults() {
|
||||
// 5. OpenRouter
|
||||
// 6. AWS Bedrock
|
||||
// 7. Azure
|
||||
// 8. Google Cloud VertexAI
|
||||
|
||||
// Anthropic configuration
|
||||
if key := viper.GetString("providers.anthropic.apiKey"); strings.TrimSpace(key) != "" {
|
||||
@@ -299,6 +300,15 @@ func setProviderDefaults() {
|
||||
viper.SetDefault("agents.title.model", models.AzureGPT41Mini)
|
||||
return
|
||||
}
|
||||
|
||||
// Google Cloud VertexAI configuration
|
||||
if hasVertexAICredentials() {
|
||||
viper.SetDefault("agents.coder.model", models.VertexAIGemini25)
|
||||
viper.SetDefault("agents.summarizer.model", models.VertexAIGemini25)
|
||||
viper.SetDefault("agents.task.model", models.VertexAIGemini25Flash)
|
||||
viper.SetDefault("agents.title.model", models.VertexAIGemini25Flash)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// hasAWSCredentials checks if AWS credentials are available in the environment.
|
||||
@@ -327,6 +337,19 @@ func hasAWSCredentials() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// hasVertexAICredentials checks if VertexAI credentials are available in the environment.
|
||||
func hasVertexAICredentials() bool {
|
||||
// Check for explicit VertexAI parameters
|
||||
if os.Getenv("VERTEXAI_PROJECT") != "" && os.Getenv("VERTEXAI_LOCATION") != "" {
|
||||
return true
|
||||
}
|
||||
// Check for Google Cloud project and location
|
||||
if os.Getenv("GOOGLE_CLOUD_PROJECT") != "" && (os.Getenv("GOOGLE_CLOUD_REGION") != "" || os.Getenv("GOOGLE_CLOUD_LOCATION") != "") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// readConfig handles the result of reading a configuration file.
|
||||
func readConfig(err error) error {
|
||||
if err == nil {
|
||||
@@ -549,6 +572,10 @@ func getProviderAPIKey(provider models.ModelProvider) string {
|
||||
if hasAWSCredentials() {
|
||||
return "aws-credentials-available"
|
||||
}
|
||||
case models.ProviderVertexAI:
|
||||
if hasVertexAICredentials() {
|
||||
return "vertex-ai-credentials-available"
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -669,6 +696,24 @@ func setDefaultModelForAgent(agent AgentName) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if hasVertexAICredentials() {
|
||||
var model models.ModelID
|
||||
maxTokens := int64(5000)
|
||||
|
||||
if agent == AgentTitle {
|
||||
model = models.VertexAIGemini25Flash
|
||||
maxTokens = 80
|
||||
} else {
|
||||
model = models.VertexAIGemini25
|
||||
}
|
||||
|
||||
cfg.Agents[agent] = Agent{
|
||||
Model: model,
|
||||
MaxTokens: maxTokens,
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user