Merge branch 'main' into v4.2.1

This commit is contained in:
RockYang 2025-02-20 11:22:52 +08:00
commit 183829a08b
8 changed files with 69 additions and 44 deletions

View File

@ -90,7 +90,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
} }
// 检查 prompt 长度是否超过了当前模型允许的最大上下文长度 // 检查 prompt 长度是否超过了当前模型允许的最大上下文长度
promptTokens, err := utils.CalcTokens(prompt, session.Model.Value) promptTokens, _ := utils.CalcTokens(prompt, session.Model.Value)
if promptTokens > session.Model.MaxContext { if promptTokens > session.Model.MaxContext {
return errors.New("对话内容超出了当前模型允许的最大上下文长度!") return errors.New("对话内容超出了当前模型允许的最大上下文长度!")
@ -105,7 +105,6 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
if strings.HasPrefix(session.Model.Value, "o1-") || if strings.HasPrefix(session.Model.Value, "o1-") ||
strings.HasPrefix(session.Model.Value, "o3-") || strings.HasPrefix(session.Model.Value, "o3-") ||
strings.HasPrefix(session.Model.Value, "gpt") { strings.HasPrefix(session.Model.Value, "gpt") {
utils.SendChunkMsg(ws, "> AI 正在思考...\n")
req.MaxCompletionTokens = session.Model.MaxTokens req.MaxCompletionTokens = session.Model.MaxTokens
session.Start = time.Now().Unix() session.Start = time.Now().Unix()
} else { } else {

View File

@ -90,13 +90,6 @@ func (h *ChatHandler) sendOpenAiMessage(
var toolCall = false var toolCall = false
var arguments = make([]string, 0) var arguments = make([]string, 0)
if strings.HasPrefix(req.Model, "o1-") {
content := fmt.Sprintf("AI 思考结束,耗时:%d 秒。\n\n", time.Now().Unix()-session.Start)
contents = append(contents, "> AI 正在思考中...\n")
contents = append(contents, content)
utils.SendChunkMsg(ws, content)
}
scanner := bufio.NewScanner(response.Body) scanner := bufio.NewScanner(response.Body)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()

25
web/package-lock.json generated
View File

@ -23,6 +23,7 @@
"lodash": "^4.17.21", "lodash": "^4.17.21",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"markdown-it-emoji": "^2.0.0", "markdown-it-emoji": "^2.0.0",
"markdown-it-katex": "^2.0.3",
"markdown-it-mathjax3": "^4.3.2", "markdown-it-mathjax3": "^4.3.2",
"markmap-common": "^0.16.0", "markmap-common": "^0.16.0",
"markmap-lib": "^0.16.1", "markmap-lib": "^0.16.1",
@ -8654,6 +8655,25 @@
"resolved": "https://registry.npmmirror.com/markdown-it-emoji/-/markdown-it-emoji-2.0.2.tgz", "resolved": "https://registry.npmmirror.com/markdown-it-emoji/-/markdown-it-emoji-2.0.2.tgz",
"integrity": "sha512-zLftSaNrKuYl0kR5zm4gxXjHaOI3FAOEaloKmRA5hijmJZvSjmxcokOLlzycb/HXlUFWzXqpIEoyEMCE4i9MvQ==" "integrity": "sha512-zLftSaNrKuYl0kR5zm4gxXjHaOI3FAOEaloKmRA5hijmJZvSjmxcokOLlzycb/HXlUFWzXqpIEoyEMCE4i9MvQ=="
}, },
"node_modules/markdown-it-katex": {
"version": "2.0.3",
"resolved": "https://registry.npmmirror.com/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz",
"integrity": "sha512-nUkkMtRWeg7OpdflamflE/Ho/pWl64Lk9wNBKOmaj33XkQdumhXAIYhI0WO03GeiycPCsxbmX536V5NEXpC3Ng==",
"dependencies": {
"katex": "^0.6.0"
}
},
"node_modules/markdown-it-katex/node_modules/katex": {
"version": "0.6.0",
"resolved": "https://registry.npmmirror.com/katex/-/katex-0.6.0.tgz",
"integrity": "sha512-rS4mY3SvHYg5LtQV6RBcK0if7ur6plyEukAOV+jGGPqFImuzu8fHL6M752iBmRGoUyF0bhZbAPoezehn7xYksA==",
"dependencies": {
"match-at": "^0.1.0"
},
"bin": {
"katex": "cli.js"
}
},
"node_modules/markdown-it-mathjax3": { "node_modules/markdown-it-mathjax3": {
"version": "4.3.2", "version": "4.3.2",
"resolved": "https://registry.npmjs.org/markdown-it-mathjax3/-/markdown-it-mathjax3-4.3.2.tgz", "resolved": "https://registry.npmjs.org/markdown-it-mathjax3/-/markdown-it-mathjax3-4.3.2.tgz",
@ -8895,6 +8915,11 @@
"markmap-common": "*" "markmap-common": "*"
} }
}, },
"node_modules/match-at": {
"version": "0.1.1",
"resolved": "https://registry.npmmirror.com/match-at/-/match-at-0.1.1.tgz",
"integrity": "sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q=="
},
"node_modules/mathjax-full": { "node_modules/mathjax-full": {
"version": "3.2.2", "version": "3.2.2",
"resolved": "https://registry.npmjs.org/mathjax-full/-/mathjax-full-3.2.2.tgz", "resolved": "https://registry.npmjs.org/mathjax-full/-/mathjax-full-3.2.2.tgz",

View File

@ -17,10 +17,7 @@
</div> </div>
<div class="body"> <div class="body">
<div class="title"> <div class="title">
<el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{ <el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{ file.name }} </el-link>
file.name
}}
</el-link>
</div> </div>
<div class="info"> <div class="info">
<span>{{ GetFileType(file.ext) }}</span> <span>{{ GetFileType(file.ext) }}</span>
@ -59,10 +56,7 @@
</div> </div>
<div class="body"> <div class="body">
<div class="title"> <div class="title">
<el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{ <el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{ file.name }} </el-link>
file.name
}}
</el-link>
</div> </div>
<div class="info"> <div class="info">
<span>{{ GetFileType(file.ext) }}</span> <span>{{ GetFileType(file.ext) }}</span>
@ -157,8 +151,15 @@ const processFiles = () => {
const linkRegex = /(https?:\/\/\S+)/g; const linkRegex = /(https?:\/\/\S+)/g;
const links = props.data.content.match(linkRegex); const links = props.data.content.match(linkRegex);
const urlPrefix = `${window.location.protocol}//${window.location.host}`;
if (links) { if (links) {
httpPost("/api/upload/list", {urls: links}) const _links = links.map((link) => {
if (link.startsWith(urlPrefix)) {
return link.replace(urlPrefix, "");
}
return link;
});
httpPost("/api/upload/list", { urls: _links })
.then((res) => { .then((res) => {
files.value = res.data.items; files.value = res.data.items;
@ -168,8 +169,7 @@ const processFiles = () => {
} }
} }
}) })
.catch(() => { .catch(() => {});
});
for (let link of links) { for (let link of links) {
content.value = content.value.replace(link, ""); content.value = content.value.replace(link, "");

View File

@ -173,6 +173,11 @@ const reGenerate = (prompt) => {
font-family: var(--font-family); font-family: var(--font-family);
.chat-line { .chat-line {
.boxed {
border: 1px solid var(--el-border-color);
border-radius: 5px;
padding: 0 5px;
}
.chat-item { .chat-item {
.content-wrapper { .content-wrapper {
img { img {

View File

@ -213,6 +213,10 @@ export function processContent(content) {
return ""; return "";
}); });
} }
// 支持 \[ 公式标签
content = content.replace(/\\\[/g, "$$").replace(/\\\]/g, "$$");
content = content.replace(/\\\(\\boxed\{(\d+)\}\\\)/g, '<span class="boxed">$1</span>');
return content; return content;
} }

View File

@ -370,7 +370,6 @@ httpGet("/api/function/list")
showMessageError("获取工具函数失败:" + e.message); showMessageError("获取工具函数失败:" + e.message);
}); });
// socket
const prompt = ref(""); const prompt = ref("");
const showStopGenerate = ref(false); // const showStopGenerate = ref(false); //
const lineBuffer = ref(""); // const lineBuffer = ref(""); //