add model command to set default model#1250
Conversation
|
original is #1072, wrongly closed... |
|
@yofabr |
yinwm
left a comment
There was a problem hiding this comment.
PR Review: Add model command to set default model
Thanks for the contribution! Overall this is a well-structured implementation with good test coverage. Here are my findings:
✅ What's Good
- Clean code structure - Well organized using cobra framework
- Comprehensive tests - 446 lines of tests covering various scenarios
- Good backward compatibility - Handles both
ModelNameand legacyModelfield - Nice UX - Clear output format with
>marker for current model - Reasonable config.go changes - Making
model_namenon-omitempty andmodelomitempty correctly reflects the field migration direction
⚠️ Issues & Suggestions
1. [Bug] Incomplete marker logic in listAvailableModels
// command.go:70-72
if model.ModelName == cfg.Agents.Defaults.ModelName {
marker = "> "
}This only compares ModelName, but if a user's config uses the legacy Model field (without ModelName), the marker won't work correctly. Should handle it the same way as showCurrentModel:
defaultModel := cfg.Agents.Defaults.ModelName
if defaultModel == "" {
defaultModel = cfg.Agents.Defaults.Model
}
// Then compare with defaultModel2. [Minor] local-model lacks documentation
if !modelFound && modelName != LocalModel {
return fmt.Errorf("Model '%s' not found in config.", modelName)
}local-model is a special value that doesn't need to exist in model_list, but users may not understand what it means. Consider adding an explanation in the command's Long description.
3. [Minor] Inconsistent error message formatting
return fmt.Errorf("Model '%s' not found in config.", modelName) // Has period
return fmt.Errorf("failed to load config: %w", err) // No period
return fmt.Errorf("failed to save config: %w", err) // No periodSuggest unifying the style.
4. [Nit] Test helper could reduce boilerplate
The stdout capture code is repeated many times in tests. Could be extracted into a helper function.
📊 Summary
| Category | Status |
|---|---|
| Functionality | ✅ Complete |
| Code Quality | |
| Test Coverage | ✅ Good |
| Backward Compat | ✅ Handled well |
| Documentation |
Recommendation: Fix issue #1 (the bug) before merging. Others are optional improvements.
done |
yinwm
left a comment
There was a problem hiding this comment.
Follow-up Review
Thanks for addressing the previous feedback! The marker logic bug in listAvailableModels has been fixed correctly.
⚠️ Still Needs Fix
Error message grammar issue
File: command.go:95
return fmt.Errorf("can not found model '%s' in config", modelName)"can not found" is grammatically incorrect. Should be:
return fmt.Errorf("cannot find model '%s' in config", modelName)
// or
return fmt.Errorf("model '%s' not found in config", modelName)💡 Suggested Improvement
local-model lacks documentation
local-model is a special value that bypasses the APIKey check, designed for local VLLM servers. However, users won't discover this feature from --help.
Consider adding to the Long description:
Long: `Show or change the default model configuration.
If no argument is provided, shows the current default model.
If a model name is provided, sets it as the default model.
Examples:
picoclaw model # Show current default model
picoclaw model gpt-5.2 # Set gpt-5.2 as default
picoclaw model claude-sonnet-4.6 # Set claude-sonnet-4.6 as default
picoclaw model local-model # Set local VLLM server as default
Note: 'local-model' is a special value for using a local VLLM server
(running at localhost:8000 by default) which does not require an API key.`,📊 Summary
| Issue | Severity | Status |
|---|---|---|
| Marker logic bug | 🔴 Required | ✅ Fixed |
| Error message grammar | 🟡 Suggested | ❌ Pending |
| local-model docs | 🟢 Optional | ❌ Pending |
Recommendation: Fix the error message grammar before merging. Documentation improvement is optional.
all done |
yinwm
left a comment
There was a problem hiding this comment.
Review Summary
✅ Approved
The feature is complete with good test coverage. Ready to merge.
Pros
- Clean command design for viewing and setting default model
- Proper backward compatibility handling for
model_nameand legacymodelfield - Comprehensive test coverage (369 lines of tests)
Minor issues (non-blocking, can be fixed in follow-up)
command.go:107- "cannot found" is grammatically incorrect, should be "cannot find" or "not found"getDefaultModellogic is duplicated in multiple places, could be extracted to a helper function
Good job! 🎉
Conflicts resolved: - helpers.go: merged import sections (io, log, net/http + sync) - config.go: merged AgentDefaults with Schedule, SafetyLevel, BirthYear Upstream features merged: - Config hot reload (PR sipeed#1187) - Anthropic Messages protocol (PR sipeed#1284) - Enhanced Skill Installer v2 (PR sipeed#1252) - Model command CLI (PR sipeed#1250) - ModelScope provider (PR sipeed#1486) - LINE webhook DoS protection (PR sipeed#1413)
* add model command to set default model * fix for ci * fix test for model * fix active agent not recognized * implement test for model command * fix local-model can not set as default issue * fix review comment * fix for comment
* add model command to set default model * fix for ci * fix test for model * fix active agent not recognized * implement test for model command * fix local-model can not set as default issue * fix review comment * fix for comment
* add model command to set default model * fix for ci * fix test for model * fix active agent not recognized * implement test for model command * fix local-model can not set as default issue * fix review comment * fix for comment
* add model command to set default model * fix for ci * fix test for model * fix active agent not recognized * implement test for model command * fix local-model can not set as default issue * fix review comment * fix for comment
* add model command to set default model * fix for ci * fix test for model * fix active agent not recognized * implement test for model command * fix local-model can not set as default issue * fix review comment * fix for comment
📝 Description
Now we can use picoclaw model <new_model_name> to change the default model in config.json.
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
☑️ Checklist