Skip to content

fix: keep default model not configed#1094

Merged
deepin-ci-robot merged 2 commits intoCodeya-IDE:masterfrom
deepin-mozart:master
Mar 7, 2025
Merged

fix: keep default model not configed#1094
deepin-ci-robot merged 2 commits intoCodeya-IDE:masterfrom
deepin-mozart:master

Conversation

@deepin-mozart
Copy link
Contributor

@deepin-mozart deepin-mozart commented Mar 7, 2025

Log:
Bug: https://pms.uniontech.com/bug-view-306857.html Change-Id: If1326f4d472406017d457393eb09a513d5bb3fbf

Summary by Sourcery

Bug Fixes:

  • Fixes a bug where default models could be modified or removed.

Log:
Bug: https://pms.uniontech.com/bug-view-306857.html
Change-Id: If1326f4d472406017d457393eb09a513d5bb3fbf
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 7, 2025

Reviewer's Guide by Sourcery

This pull request prevents modification and removal of default models in the AI manager. It introduces an isdefault flag in the LLMInfo struct to identify default models and updates the UI to disable editing and removal options for these models.

Sequence diagram for handling model selection in DetailWidget

sequenceDiagram
    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
Loading

Updated class diagram for LLMInfo

classDiagram
    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."
Loading

File-Level Changes

Change Details Files
Added a check to prevent modification of default models in the model configuration dialog.
  • Added a condition to prevent the modification of default models.
  • The dialog will not be opened if the model is a default model.
src/plugins/aimanager/option/detailwidget.cpp
Disabled the remove button and restored the default palette for default models in the model list view.
  • The remove button is disabled if the model is a default model.
  • The default palette is restored when the remove button is disabled.
  • The remove button is enabled and the warning color is displayed if the model is not a default model.
src/plugins/aimanager/option/detailwidget.cpp
Added a boolean flag to the LLMInfo struct to indicate whether a model is a default model.
  • Added a isdefault field to the LLMInfo struct.
  • The operator== overload was updated to include the new isdefault field.
src/services/ai/aiservice.h
Set the isdefault flag to true for default models.
  • Set the isdefault flag to true for the liteInfo model.
  • Set the isdefault flag to true for the proInfo model.
src/plugins/aimanager/aimanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @deepin-mozart - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why the setPalette calls 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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();
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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.
  2. The types (e.g. QPushButton and QColor) are already included or imported in your code base.
  3. The variable buttonRemove and warningColor are in the accessible scope within the lambda after this change.

Comment on lines +39 to +46
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);
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link

github-actions bot commented Mar 7, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "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
@deepin-ci-robot
Copy link

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • AiManager::getDefaultLLM函数中,isdefault属性被添加到LLMInfo结构体中,但没有对应的注释说明其用途。
  • DetailWidget::setupUi函数中,当点击列表项时,如果模型是默认的,则直接返回,不执行任何操作。这可能是一个逻辑错误,因为用户可能期望能够查看或修改默认模型的配置。
  • DetailWidget::setupUi函数中,当点击列表项时,如果模型不是默认的,则启用删除按钮并设置其颜色。但是,当模型是默认的时,删除按钮被禁用,但没有恢复其默认外观。这可能会导致用户混淆。
  • AskPageWidget::onLLMChanged函数中,当LLM类型改变时,调用了onStopGenerate函数,但没有提供足够的上下文说明为什么需要这样做。
  • LLMInfo结构体的toVariant函数中,QVariantMap的创建没有使用QVariantMap::fromStdMap,可能会导致性能问题。

是否建议立即修改:

  • 应该添加注释来解释isdefault属性的作用。
  • 应该修复逻辑错误,允许用户查看或修改默认模型的配置。
  • 应该确保删除按钮在禁用时恢复其默认外观,以避免用户混淆。
  • 应该提供onStopGenerate函数的调用原因,或者如果这是不必要的,应该移除这个调用。
  • 应该使用QVariantMap::fromStdMap来创建QVariantMap,以提高性能。

@github-actions
Copy link

github-actions bot commented Mar 7, 2025

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "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"
        }
    ]
}

@deepin-ci-robot deepin-ci-robot merged commit be582ef into Codeya-IDE:master Mar 7, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants