Skip to content

Commit

Permalink
fix: [codegeex] The format of the code in the parameters is incorrect.
Browse files Browse the repository at this point in the history
Log: as title
  • Loading branch information
LiHua000 authored and deepin-mozart committed Jul 22, 2024
1 parent 32d4971 commit 3d24752
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/plugins/codegeex/copilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,31 +192,31 @@ void Copilot::translate()
void Copilot::fixBug()
{
QString url = QString(kUrlSSEChat) + "?stream=true";
copilotApi.postCommand(url, selectedText(), locale, commandFixBug);
copilotApi.postCommand(url, assembleCodeByCurrentFile(selectedText()), locale, commandFixBug);

switchToCodegeexPage();
}

void Copilot::explain()
{
QString url = QString(kUrlSSEChat) + "?stream=true";
copilotApi.postCommand(url, selectedText(), locale, commandExplain);
copilotApi.postCommand(url, assembleCodeByCurrentFile(selectedText()), locale, commandExplain);

switchToCodegeexPage();
}

void Copilot::review()
{
QString url = QString(kUrlSSEChat) + "?stream=true";
copilotApi.postCommand(url, selectedText(), locale, commandReview);
copilotApi.postCommand(url, assembleCodeByCurrentFile(selectedText()), locale, commandReview);

switchToCodegeexPage();
}

void Copilot::tests()
{
QString url = QString(kUrlSSEChat) + "?stream=true";
copilotApi.postCommand(url, selectedText(), locale, commandTests);
copilotApi.postCommand(url, assembleCodeByCurrentFile(selectedText()), locale, commandTests);

switchToCodegeexPage();
}
Expand Down Expand Up @@ -256,3 +256,13 @@ void Copilot::switchToCodegeexPage()
if (windowService->switchWidgetNavigation)
windowService->switchWidgetNavigation(MWNA_CODEGEEX);
}

QString Copilot::assembleCodeByCurrentFile(const QString &code)
{
auto filePath = editorService->currentFile();
auto fileType = support_file::Language::id(filePath);

QString result;
result = "```" + fileType + "\n" + code + "```";
return result;
}
1 change: 1 addition & 0 deletions src/plugins/codegeex/copilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public slots:
QString locale { "zh" };
void switchToCodegeexPage();
bool responseValid(const QString &response);
QString assembleCodeByCurrentFile(const QString &code);

CodeGeeX::CopilotApi copilotApi;
dpfservice::EditorService *editorService = nullptr;
Expand Down

0 comments on commit 3d24752

Please sign in to comment.