fix: keep default model not configed#1094
Conversation
Log: Bug: https://pms.uniontech.com/bug-view-306857.html Change-Id: If1326f4d472406017d457393eb09a513d5bb3fbf
Reviewer's Guide by SourceryThis pull request prevents modification and removal of default models in the AI manager. It introduces an Sequence diagram for handling model selection in DetailWidgetsequenceDiagram
participant User
participant DetailWidget
participant DListView
participant LLMModel
User->>DListView: Clicks on a model in the list
DListView->>DetailWidget: clicked(index)
DetailWidget->>LLMModel: allLLMs().at(index.row())
LLMModel-->>DetailWidget: llmInfo
alt llmInfo.isdefault == true
DetailWidget->>buttonRemove: setEnabled(false)
DetailWidget->>buttonRemove: setPalette(QPalette())
else llmInfo.isdefault == false
DetailWidget->>buttonRemove: setEnabled(true)
DetailWidget->>buttonRemove: setPalette(pa)
end
Updated class diagram for LLMInfoclassDiagram
class LLMInfo {
QString modelName
QString modelPath
QString apikey
QIcon icon
LLMType type
bool isdefault
QVariant toVariant()
bool operator==()
}
note for LLMInfo "Added isdefault attribute to indicate default models."
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @deepin-mozart - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a comment explaining why the
setPalettecalls are necessary. - It might be better to store the default models in a separate data structure to avoid iterating through all models.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| @@ -230,6 +235,23 @@ void DetailWidget::setupUi() | |||
| } | |||
| dialog->deleteLater(); | |||
| }); | |||
There was a problem hiding this comment.
suggestion: Palette reset and warning color handling could be encapsulated.
The logic for updating the palette based on the model's default status is inline in the clicked lambda. Encapsulating this palette update logic in a helper function or method could improve maintainability and clarity.
Suggested implementation:
#include <QPushButton>
#include <QPalette>
namespace {
void updateButtonRemovePalette(QPushButton* button, bool isDefault, const QColor& warningColor)
{
if (isDefault) {
button->setEnabled(false);
// Restore default palette when disabled
button->setPalette(QPalette());
} else {
button->setEnabled(true);
// Display warning color
auto palette = button->palette();
palette.setColor(QPalette::ButtonText, warningColor);
button->setPalette(palette);
}
}
}
connect(d->modelsView, &DListView::clicked, this, [=](const QModelIndex &index){
if (!index.isValid())
return;
auto llmInfo = d->LLMModel->allLLMs().at(index.row());
updateButtonRemovePalette(buttonRemove, llmInfo.isdefault, warningColor);
});
Ensure that:
- The helper function is placed in a suitable location in the file (e.g. at the top, within an anonymous namespace) so it is accessible to the lambda.
- The types (e.g. QPushButton and QColor) are already included or imported in your code base.
- The variable buttonRemove and warningColor are in the accessible scope within the lambda after this change.
| bool isdefault = false; | ||
| bool operator==(const LLMInfo &info) const | ||
| { | ||
| return (this->modelName == info.modelName | ||
| && this->modelPath == info.modelPath | ||
| && this->apikey == info.apikey | ||
| && this->type == info.type); | ||
| }; | ||
| } |
There was a problem hiding this comment.
question (bug_risk): Consider including 'isdefault' in the equality operator for LLMInfo.
Currently, the operator== ignores the isdefault flag. If two models differ only in the isdefault property, they will be considered equal. Confirm whether this behavior is intentional or if the flag should be incorporated into the equality check.
| @@ -211,6 +211,11 @@ void DetailWidget::setupUi() | |||
|
|
|||
| auto dialog = new ModelConfigDialog(this); | |||
| auto llmInfo = d->LLMModel->allLLMs().at(index.row()); | |||
There was a problem hiding this comment.
issue (complexity): Consider creating a helper function to encapsulate the logic for updating the remove button based on whether the LLM is the default, to avoid code duplication and improve readability
You can reduce duplicated “default” logic by extracting the checks and UI adjustments into a helper function. For example, you can add a private helper like:
// in DetailWidget.h
private:
void updateRemoveButton(const LLMInfo &llmInfo, QPushButton *buttonRemove);
// in DetailWidget.cpp
void DetailWidget::updateRemoveButton(const LLMInfo &llmInfo, QPushButton *buttonRemove)
{
if (llmInfo.isdefault) {
buttonRemove->setEnabled(false);
buttonRemove->setPalette(QPalette()); // reset to default palette
} else {
buttonRemove->setEnabled(true);
auto pa = buttonRemove->palette();
pa.setColor(QPalette::ButtonText, warningColor);
buttonRemove->setPalette(pa);
}
}Then in your lambda you only need to call this helper:
connect(d->modelsView, &DListView::clicked, this, [=](const QModelIndex &index){
if (!index.isValid())
return;
auto llmInfo = d->LLMModel->allLLMs().at(index.row());
updateRemoveButton(llmInfo, buttonRemove);
});For the doubleClicked lambda, if the primary purpose of checking llmInfo.isdefault is to early return, this check is simple enough. However, if additional similar UI adjustments are needed there in the future, refactor in a similar manner.
This consolidation removes duplicated branching and makes the intent clearer without altering functionality.
|
Note
详情{
"src/plugins/aimanager/aimanager.cpp": [
{
"line": "static const char *kCodeGeeXModelPath = \"https://codegeex.cn/prod/code/chatCodeSseV3/chat\";",
"line_number": 18,
"rule": "S35",
"reason": "Url link | 9a3dc8cf24"
}
]
} |
Log: bug fix Bug: https://pms.uniontech.com/bug-view-306851.html Change-Id: Iacae941b5509d913024f9937528d55e5e8cfe402
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deepin-mozart The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
deepin pr auto review关键摘要:
是否建议立即修改:
|
|
Note
详情{
"src/plugins/aimanager/aimanager.cpp": [
{
"line": "static const char *kCodeGeeXModelPath = \"https://codegeex.cn/prod/code/chatCodeSseV3/chat\";",
"line_number": 18,
"rule": "S35",
"reason": "Url link | 9a3dc8cf24"
}
]
} |
Log:
Bug: https://pms.uniontech.com/bug-view-306857.html Change-Id: If1326f4d472406017d457393eb09a513d5bb3fbf
Summary by Sourcery
Bug Fixes: