mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-10-10 07:23:23 +08:00
askAi进度条支持markdown
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
const DOMPurify = require("dompurify");
|
||||
const marked = require("marked");
|
||||
|
||||
window.aiResponseParser = (content) => {
|
||||
const markedContent = marked.parse(content.trim());
|
||||
const processedContent = markedContent
|
||||
.replace("<p><think>", "<think><p>")
|
||||
.replace("</think></p>", "</p></think>")
|
||||
.replace("<think>\n\n</think>", "");
|
||||
const purifiedContent = DOMPurify.sanitize(processedContent, {
|
||||
ADD_TAGS: ["think"],
|
||||
});
|
||||
return purifiedContent;
|
||||
};
|
||||
|
||||
// 支持的模型类型
|
||||
const API_TYPES = {
|
||||
OPENAI: "openai",
|
||||
@@ -303,7 +318,7 @@ async function chat(content, apiConfig, options = {}) {
|
||||
if (processBar) {
|
||||
quickcommand.updateProcessBar(
|
||||
{
|
||||
text: fullResponse,
|
||||
text: window.aiResponseParser(fullResponse),
|
||||
},
|
||||
processBar
|
||||
);
|
||||
@@ -410,5 +425,4 @@ async function getModels(apiConfig) {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { chat, getModels };
|
||||
|
@@ -600,7 +600,6 @@ textarea:focus {
|
||||
.process-text {
|
||||
font-size: 13px;
|
||||
margin-bottom: 8px;
|
||||
white-space: pre-wrap;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding-right: 2px;
|
||||
@@ -748,3 +747,86 @@ textarea:focus {
|
||||
.show-pause .process-pause-btn {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* markdown */
|
||||
#process p {
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
#process pre {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
padding: 8px 10px;
|
||||
border-radius: 4px;
|
||||
margin: 4px 0;
|
||||
overflow-x: auto;
|
||||
max-width: 100%;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#process code {
|
||||
font-family: Monaco, Consolas, Liberation Mono, monospace;
|
||||
padding: 2px 4px;
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#process pre code {
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
#process ul,
|
||||
#process ol {
|
||||
margin: 4px 0;
|
||||
padding-left: 1.2em;
|
||||
}
|
||||
|
||||
#process h1,
|
||||
#process h2,
|
||||
#process h3,
|
||||
#process h4,
|
||||
#process h5,
|
||||
#process h6 {
|
||||
margin: 6px 0 4px 0;
|
||||
font-weight: 600;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
#process h1 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
#process h2 {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
#process h3 {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#process h4,
|
||||
#process h5,
|
||||
#process h6 {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
#process pre::-webkit-scrollbar {
|
||||
height: 3px;
|
||||
}
|
||||
|
||||
#process think,
|
||||
#process blockquote {
|
||||
display: block;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
border-left: 3px solid rgba(255, 255, 255, 0.3);
|
||||
padding: 2px 0 2px 8px;
|
||||
font-size: 12px;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
#process hr {
|
||||
border-style: solid;
|
||||
border-width: 0.5px;
|
||||
}
|
||||
|
Reference in New Issue
Block a user