Merge branch 'main' into v4.2.1

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

View File

@@ -90,13 +90,6 @@ func (h *ChatHandler) sendOpenAiMessage(
var toolCall = false
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)
for scanner.Scan() {
line := scanner.Text()

25
web/package-lock.json generated
View File

@@ -23,6 +23,7 @@
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
"markdown-it-emoji": "^2.0.0",
"markdown-it-katex": "^2.0.3",
"markdown-it-mathjax3": "^4.3.2",
"markmap-common": "^0.16.0",
"markmap-lib": "^0.16.1",
@@ -8654,6 +8655,25 @@
"resolved": "https://registry.npmmirror.com/markdown-it-emoji/-/markdown-it-emoji-2.0.2.tgz",
"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": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/markdown-it-mathjax3/-/markdown-it-mathjax3-4.3.2.tgz",
@@ -8895,6 +8915,11 @@
"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": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/mathjax-full/-/mathjax-full-3.2.2.tgz",

View File

@@ -22,7 +22,7 @@
"json-bigint": "^1.0.0",
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
"markdown-it-emoji": "^2.0.0",
"markdown-it-emoji": "^2.0.0",
"markdown-it-mathjax3": "^4.3.2",
"markmap-common": "^0.16.0",
"markmap-lib": "^0.16.1",

View File

@@ -2,25 +2,22 @@
<div class="chat-line chat-line-prompt-list" v-if="listStyle === 'list'">
<div class="chat-line-inner">
<div class="chat-icon">
<img :src="data.icon" alt="User"/>
<img :src="data.icon" alt="User" />
</div>
<div class="chat-item">
<div v-if="files.length > 0" class="file-list-box">
<div v-for="file in files">
<div class="image" v-if="isImage(file.ext)">
<el-image :src="file.url" fit="cover"/>
<el-image :src="file.url" fit="cover" />
</div>
<div class="item" v-else>
<div class="icon">
<el-image :src="GetFileIcon(file.ext)" fit="cover"/>
<el-image :src="GetFileIcon(file.ext)" fit="cover" />
</div>
<div class="body">
<div class="title">
<el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{
file.name
}}
</el-link>
<el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{ file.name }} </el-link>
</div>
<div class="info">
<span>{{ GetFileType(file.ext) }}</span>
@@ -33,7 +30,7 @@
<div class="content" v-html="content"></div>
<div class="bar" v-if="data.created_at > 0">
<span class="bar-item"
><el-icon><Clock/></el-icon> {{ dateFormat(data.created_at) }}</span
><el-icon><Clock /></el-icon> {{ dateFormat(data.created_at) }}</span
>
<span class="bar-item">tokens: {{ finalTokens }}</span>
</div>
@@ -44,25 +41,22 @@
<div class="chat-line chat-line-prompt-chat" v-else>
<div class="chat-line-inner">
<div class="chat-icon">
<img :src="data.icon" alt="User"/>
<img :src="data.icon" alt="User" />
</div>
<div class="chat-item">
<div v-if="files.length > 0" class="file-list-box">
<div v-for="file in files">
<div class="image" v-if="isImage(file.ext)">
<el-image :src="file.url" fit="cover"/>
<el-image :src="file.url" fit="cover" />
</div>
<div class="item" v-else>
<div class="icon">
<el-image :src="GetFileIcon(file.ext)" fit="cover"/>
<el-image :src="GetFileIcon(file.ext)" fit="cover" />
</div>
<div class="body">
<div class="title">
<el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{
file.name
}}
</el-link>
<el-link :href="file.url" target="_blank" style="--el-font-weight-primary: bold">{{ file.name }} </el-link>
</div>
<div class="info">
<span>{{ GetFileType(file.ext) }}</span>
@@ -77,7 +71,7 @@
</div>
<div class="bar" v-if="data.created_at > 0">
<span class="bar-item"
><el-icon><Clock/></el-icon> {{ dateFormat(data.created_at) }}</span
><el-icon><Clock /></el-icon> {{ dateFormat(data.created_at) }}</span
>
<!-- <span class="bar-item">tokens: {{ finalTokens }}</span>-->
</div>
@@ -87,12 +81,12 @@
</template>
<script setup>
import {onMounted, ref} from "vue";
import {Clock} from "@element-plus/icons-vue";
import {httpPost} from "@/utils/http";
import { onMounted, ref } from "vue";
import { Clock } from "@element-plus/icons-vue";
import { httpPost } from "@/utils/http";
import hl from "highlight.js";
import {dateFormat, isImage, processPrompt} from "@/utils/libs";
import {FormatFileSize, GetFileIcon, GetFileType} from "@/store/system";
import { dateFormat, isImage, processPrompt } from "@/utils/libs";
import { FormatFileSize, GetFileIcon, GetFileType } from "@/store/system";
import emoji from "markdown-it-emoji";
import mathjaxPlugin from "markdown-it-mathjax3";
import MarkdownIt from "markdown-it";
@@ -107,8 +101,8 @@ const md = new MarkdownIt({
// 显示复制代码按钮
const copyBtn = `<span class="copy-code-btn" data-clipboard-action="copy" data-clipboard-target="#copy-target-${codeIndex}">复制</span>
<textarea style="position: absolute;top: -9999px;left: -9999px;z-index: -9999;" id="copy-target-${codeIndex}">${str.replace(
/<\/textarea>/g,
"&lt;/textarea>"
/<\/textarea>/g,
"&lt;/textarea>"
)}</textarea>`;
if (lang && hl.getLanguage(lang)) {
const langHtml = `<span class="lang-name">${lang}</span>`;
@@ -157,19 +151,25 @@ const processFiles = () => {
const linkRegex = /(https?:\/\/\S+)/g;
const links = props.data.content.match(linkRegex);
const urlPrefix = `${window.location.protocol}//${window.location.host}`;
if (links) {
httpPost("/api/upload/list", {urls: links})
.then((res) => {
files.value = res.data.items;
const _links = links.map((link) => {
if (link.startsWith(urlPrefix)) {
return link.replace(urlPrefix, "");
}
return link;
});
httpPost("/api/upload/list", { urls: _links })
.then((res) => {
files.value = res.data.items;
for (let link of links) {
if (isExternalImg(link, files.value)) {
files.value.push({url: link, ext: ".png"});
}
for (let link of links) {
if (isExternalImg(link, files.value)) {
files.value.push({ url: link, ext: ".png" });
}
})
.catch(() => {
});
}
})
.catch(() => {});
for (let link of links) {
content.value = content.value.replace(link, "");

View File

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

View File

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

View File

@@ -370,7 +370,6 @@ httpGet("/api/function/list")
showMessageError("获取工具函数失败:" + e.message);
});
// 创建 socket 连接
const prompt = ref("");
const showStopGenerate = ref(false); // 停止生成
const lineBuffer = ref(""); // 输出缓冲行