MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / promptPreProcessing

Method promptPreProcessing

src/plugins/chat/chatmanager.cpp:206–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206QString ChatManager::promptPreProcessing(const QString &originText)
207{
208 QString processedText = PrePrompt;
209
210 QString message = originText;
211#ifdef SUPPORTMINIFORGE
212 if (isReferenceCodebase()) {
213 if (!condaHasInstalled()) { // if not x86 or arm. @codebase can not be use
214 QStringList actions { "ai_rag_install", tr("Install") };
215 emit notify(0, ChatManager::tr("The file indexing feature is not available, which may cause functions such as @codebase to not work properly."
216 "Please install the required environment.\n the installation process may take several minutes."),
217 actions);
218 } else {
219 QString prompt = QString("Translate this passage into English :\"%1\", with the requirements: Do not provide responses other than translation.").arg(message.remove("@CodeBase"));
220 auto englishPrompt = requestSync(prompt);
221 QString chunksContext = getChunks(englishPrompt);
222 if (chunksContext.isEmpty())
223 return "";
224 if (message.contains("@CodeBase"))
225 message.remove("@CodeBase");
226 processedText.append("\n<context>\n" + chunksContext + "\n</context>");
227 }
228 }
229#endif
230 if (!getReferenceFiles().isEmpty()) {
231 QJsonArray files = parseFile(getReferenceFiles());
232 for (auto file : files) {
233 auto fileName = file.toObject()["name"].toString();
234 auto language = file.toObject()["language"].toString();
235 auto content = file.toObject()["content"].toString();
236
237 processedText.append("\n" + fileName + "\n```" + language + "\n" + content + "```\n");
238 }
239 }
240
241 if (processedText != PrePrompt) {
242 processedText.append("\n\n" + message);
243 if (locale == Chat::Zh)
244 processedText.append("\nPlease answer me by Chinese");
245 return processedText;
246 } else {
247 return originText;
248 }
249}
250
251void ChatManager::sendMessage(const QString &prompt)
252{

Callers

nothing calls this directly

Calls 7

parseFileFunction · 0.85
QStringClass · 0.50
removeMethod · 0.45
isEmptyMethod · 0.45
containsMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected