fix local-model can not set as default issue
This commit is contained in:
parent
a0a9ad57ac
commit
ce63c28ed1
2 changed files with 6 additions and 29 deletions
|
|
@ -9,6 +9,8 @@ import (
|
|||
"github.com/sipeed/picoclaw/pkg/config"
|
||||
)
|
||||
|
||||
const LocalModel = "local-model"
|
||||
|
||||
func NewModelCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "model [model_name]",
|
||||
|
|
@ -38,10 +40,6 @@ Examples:
|
|||
return nil
|
||||
}
|
||||
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("wrong command, should be model [model_name]")
|
||||
}
|
||||
|
||||
// Set new default model
|
||||
modelName := args[0]
|
||||
return setDefaultModel(configPath, cfg, modelName)
|
||||
|
|
@ -96,11 +94,8 @@ func setDefaultModel(configPath string, cfg *config.Config, modelName string) er
|
|||
}
|
||||
}
|
||||
|
||||
if !modelFound {
|
||||
fmt.Printf("Error: Model '%s' not found in config.\n\n", modelName)
|
||||
fmt.Println("Available models:")
|
||||
listAvailableModels(cfg)
|
||||
panic("")
|
||||
if !modelFound && modelName != LocalModel {
|
||||
return fmt.Errorf("Model '%s' not found in config.", modelName)
|
||||
}
|
||||
|
||||
// Update the default model
|
||||
|
|
|
|||
|
|
@ -267,23 +267,7 @@ func TestSetDefaultModel_InvalidModel(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
oldStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
|
||||
// This should call os.Exit(1), so we expect a panic``
|
||||
assert.Panics(t, func() {
|
||||
_ = setDefaultModel(configPath, cfg, "nonexistent-model")
|
||||
})
|
||||
|
||||
w.Close()
|
||||
os.Stdout = oldStdout
|
||||
|
||||
var buf bytes.Buffer
|
||||
io.Copy(&buf, r)
|
||||
output := buf.String()
|
||||
assert.Contains(t, output, "Error: Model 'nonexistent-model' not found in config.")
|
||||
assert.Contains(t, output, "Available models:")
|
||||
assert.Error(t, setDefaultModel(configPath, cfg, "nonexistent-model"))
|
||||
}
|
||||
|
||||
func TestSetDefaultModel_ModelWithoutAPIKey(t *testing.T) {
|
||||
|
|
@ -301,9 +285,7 @@ func TestSetDefaultModel_ModelWithoutAPIKey(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
assert.Panics(t, func() {
|
||||
setDefaultModel(configPath, cfg, "no-key-model")
|
||||
})
|
||||
assert.Error(t, setDefaultModel(configPath, cfg, "no-key-model"))
|
||||
}
|
||||
|
||||
func TestSetDefaultModel_SaveConfigError(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue