Skip to content

Commit

Permalink
fix: [InlineChat] The answer content was empty
Browse files Browse the repository at this point in the history
The prompt words and file content exceeded the maximum limit

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Oct 16, 2024
1 parent dd9eeee commit 46e97a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions assets/configures/language.support
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
},
"shell" : {
"mimeType" : ["application/x-shellscript"]
},
"html" : {
"mimeType" : ["text/html"]
}
}
2 changes: 2 additions & 0 deletions src/plugins/codeeditor/lexer/lexermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ QsciLexer *LexerManager::defaultSciLexer(const QString &language)
lexer = new QsciLexerJavaScript();
} else if (language.compare("shell", Qt::CaseInsensitive) == 0) {
lexer = new QsciLexerBash();
} else if (language.compare("html", Qt::CaseInsensitive) == 0) {
lexer = new QsciLexerHTML();
}

// The `lexer` is structured by `TextEditor`
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codegeex/codegeex/askapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ QJsonArray AskApiPrivate::parseFile(QStringList files)
obj["language"] = support_file::Language::id(file);
QFile content(file);
if (content.open(QIODevice::ReadOnly)) {
obj["content"] = QString(content.readAll());
obj["content"] = QString(content.read(20000));
}
result.append(obj);
}
Expand Down
21 changes: 11 additions & 10 deletions src/plugins/codegeex/widgets/inlinechatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#include <QFutureWatcher>
#include <QtConcurrent>

constexpr char VisibleProperty[] { "VisibleProperty" };
constexpr char UrlSSEChat[] = "https://codegeex.cn/prod/code/chatCodeSseV3/chat";
constexpr char kVisibleProperty[] { "VisibleProperty" };
constexpr char kUrlSSEChat[] = "https://codegeex.cn/prod/code/chatCodeSseV3/chat";
constexpr int kCodeMaxLength = 10000;

using namespace dpfservice;
DWIDGET_USE_NAMESPACE
Expand Down Expand Up @@ -178,20 +179,20 @@ void InlineChatWidgetPrivate::initUI()
contentLayout->setContentsMargins(0, 0, 0, 0);
questionLabel = new DLabel(q);
questionLabel->setWordWrap(true);
questionLabel->setProperty(VisibleProperty, QuestionComplete | SubmitComplete | FollowQuestion | SubmitStart | QuestionStart | FollowQuestion | FollowSubmit);
questionLabel->setProperty(kVisibleProperty, QuestionComplete | SubmitComplete | FollowQuestion | SubmitStart | QuestionStart | FollowQuestion | FollowSubmit);
answerLabel = new DLabel(q);
answerLabel->setProperty(VisibleProperty, QuestionComplete | FollowQuestion);
answerLabel->setProperty(kVisibleProperty, QuestionComplete | FollowQuestion);
answerLabel->setWordWrap(true);
edit = new InputEdit(q);
edit->setProperty(VisibleProperty, AllState & ~(SubmitStart | QuestionStart));
edit->setProperty(kVisibleProperty, AllState & ~(SubmitStart | QuestionStart));
edit->installEventFilter(q);
q->setFocusProxy(edit);

QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->setContentsMargins(0, 0, 0, 0);
spinner = new DSpinner(q);
spinner->setFixedSize({ 12, 12 });
spinner->setProperty(VisibleProperty, SubmitStart | QuestionStart);
spinner->setProperty(kVisibleProperty, SubmitStart | QuestionStart);
escBtn = createButton(InlineChatWidget::tr("Esc to close"), PushButton, Original | QuestionComplete);
submitBtn = createButton(InlineChatWidget::tr("Submit Edit"), SuggestButton, ReadyAsk);
questionBtn = createButton(InlineChatWidget::tr("quick question"), PushButton, ReadyAsk);
Expand Down Expand Up @@ -253,7 +254,7 @@ QAbstractButton *InlineChatWidgetPrivate::createButton(const QString &name, Butt
}

btn->setFixedHeight(24);
btn->setProperty(VisibleProperty, flags);
btn->setProperty(kVisibleProperty, flags);
if (!name.isEmpty())
btn->setText(name);

Expand Down Expand Up @@ -293,7 +294,7 @@ void InlineChatWidgetPrivate::setState(State s)
if (!w)
continue;

auto property = child->property(VisibleProperty);
auto property = child->property(kVisibleProperty);
if (!property.isValid())
continue;

Expand Down Expand Up @@ -456,7 +457,7 @@ void InlineChatWidgetPrivate::handleCreatePromptFinished()
const auto &prompt = watcher->result();
auto machineId = QSysInfo::machineUniqueId();
askApi.setReferenceFiles({ chatInfo.fileName });
askApi.postSSEChat(UrlSSEChat, CodeGeeXManager::instance()->getSessionId(),
askApi.postSSEChat(kUrlSSEChat, CodeGeeXManager::instance()->getSessionId(),
prompt, machineId, {}, CodeGeeXManager::instance()->getTalkId());
}

Expand Down Expand Up @@ -618,7 +619,7 @@ QString InlineChatWidgetPrivate::createPrompt(const QString &question, bool useC
prompt << "针对这段代码,回答我的问题。问题:";
prompt << question;
prompt << "代码:\n```";
prompt << chatInfo.originalText;
prompt << chatInfo.originalText.mid(0, kCodeMaxLength);
prompt << "```";

if (useChunk) {
Expand Down

0 comments on commit 46e97a9

Please sign in to comment.