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"
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const LocalModel = "local-model"
|
||||||
|
|
||||||
func NewModelCommand() *cobra.Command {
|
func NewModelCommand() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "model [model_name]",
|
Use: "model [model_name]",
|
||||||
|
|
@ -38,10 +40,6 @@ Examples:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 1 {
|
|
||||||
return fmt.Errorf("wrong command, should be model [model_name]")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set new default model
|
// Set new default model
|
||||||
modelName := args[0]
|
modelName := args[0]
|
||||||
return setDefaultModel(configPath, cfg, modelName)
|
return setDefaultModel(configPath, cfg, modelName)
|
||||||
|
|
@ -96,11 +94,8 @@ func setDefaultModel(configPath string, cfg *config.Config, modelName string) er
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !modelFound {
|
if !modelFound && modelName != LocalModel {
|
||||||
fmt.Printf("Error: Model '%s' not found in config.\n\n", modelName)
|
return fmt.Errorf("Model '%s' not found in config.", modelName)
|
||||||
fmt.Println("Available models:")
|
|
||||||
listAvailableModels(cfg)
|
|
||||||
panic("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the default model
|
// Update the default model
|
||||||
|
|
|
||||||
|
|
@ -267,23 +267,7 @@ func TestSetDefaultModel_InvalidModel(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
oldStdout := os.Stdout
|
assert.Error(t, setDefaultModel(configPath, cfg, "nonexistent-model"))
|
||||||
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:")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultModel_ModelWithoutAPIKey(t *testing.T) {
|
func TestSetDefaultModel_ModelWithoutAPIKey(t *testing.T) {
|
||||||
|
|
@ -301,9 +285,7 @@ func TestSetDefaultModel_ModelWithoutAPIKey(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Panics(t, func() {
|
assert.Error(t, setDefaultModel(configPath, cfg, "no-key-model"))
|
||||||
setDefaultModel(configPath, cfg, "no-key-model")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetDefaultModel_SaveConfigError(t *testing.T) {
|
func TestSetDefaultModel_SaveConfigError(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue