mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2026-07-17 02:04:40 +00:00
fix: correct Vertex AI legacy model ids by removing stray asterisk (#1684)
The two Vertex AI "Legacy Stable Model" constants carried a trailing '*' that leaked in from the footnote marker in Google's model-versions table: ModelGeminiProV1_5 was "gemini-1.5-pro-002*" and ModelGeminiFlashV1_5 was "gemini-1.5-flash-002*". The '*' is not part of the model id. GetVertexAIModelOrDefault does an exact-match lookup and otherwise silently returns VERTEXAI_MODELS[0]. Because VERTEXAI_MODELS held the asterisked values, a user who correctly configured --model gemini-1.5-pro-002 failed the exact match and was silently switched to the default model, so the two legacy models could never be selected. Remove the trailing '*' from both literals and add a unit test covering the model and region resolvers. Closes #1516 Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
This commit is contained in:
@@ -66,8 +66,8 @@ const (
|
||||
ModelGeminiFlashV2_5 = "gemini-2.5-flash" // Latest Stable Model
|
||||
ModelGeminiFlashV2 = "gemini-2.0-flash" // Latest Stable Model
|
||||
ModelGeminiFlashLiteV2 = "gemini-2.0-flash-lite" // Latest Stable Model
|
||||
ModelGeminiProV1_5 = "gemini-1.5-pro-002*" // Legacy Stable Model
|
||||
ModelGeminiFlashV1_5 = "gemini-1.5-flash-002*" // Legacy Stable Model
|
||||
ModelGeminiProV1_5 = "gemini-1.5-pro-002" // Legacy Stable Model
|
||||
ModelGeminiFlashV1_5 = "gemini-1.5-flash-002" // Legacy Stable Model
|
||||
)
|
||||
|
||||
var VERTEXAI_MODELS = []string{
|
||||
|
||||
58
pkg/ai/googlevertexai_test.go
Normal file
58
pkg/ai/googlevertexai_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2023 The K8sGPT Authors.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package ai
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetVertexAIModelOrDefault(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
model string
|
||||
want string
|
||||
}{
|
||||
{"latest stable pro is preserved", ModelGeminiProV2_5, "gemini-2.5-pro"},
|
||||
{"legacy stable pro is preserved", "gemini-1.5-pro-002", "gemini-1.5-pro-002"},
|
||||
{"legacy stable flash is preserved", "gemini-1.5-flash-002", "gemini-1.5-flash-002"},
|
||||
{"unknown model falls back to default", "does-not-exist", VERTEXAI_MODELS[0]},
|
||||
{"empty model falls back to default", "", VERTEXAI_MODELS[0]},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, GetVertexAIModelOrDefault(tt.model))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVertexAIRegionOrDefault(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
region string
|
||||
want string
|
||||
}{
|
||||
{"supported region is preserved", US_West_4, "us-west4"},
|
||||
{"unknown region falls back to default", "moon-base-1", VERTEXAI_DEFAULT_REGION},
|
||||
{"empty region falls back to default", "", VERTEXAI_DEFAULT_REGION},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, GetVertexAIRegionOrDefault(tt.region))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user