mirror of
https://gitee.com/blackfox/geekai.git
synced 2025-12-07 01:08:24 +08:00
Merge branch 'main' into v4.2.1
This commit is contained in:
commit
183829a08b
@ -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 {
|
||||||
|
|||||||
@ -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
25
web/package-lock.json
generated
@ -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",
|
||||||
|
|||||||
@ -2,25 +2,22 @@
|
|||||||
<div class="chat-line chat-line-prompt-list" v-if="listStyle === 'list'">
|
<div class="chat-line chat-line-prompt-list" v-if="listStyle === 'list'">
|
||||||
<div class="chat-line-inner">
|
<div class="chat-line-inner">
|
||||||
<div class="chat-icon">
|
<div class="chat-icon">
|
||||||
<img :src="data.icon" alt="User"/>
|
<img :src="data.icon" alt="User" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="chat-item">
|
<div class="chat-item">
|
||||||
<div v-if="files.length > 0" class="file-list-box">
|
<div v-if="files.length > 0" class="file-list-box">
|
||||||
<div v-for="file in files">
|
<div v-for="file in files">
|
||||||
<div class="image" v-if="isImage(file.ext)">
|
<div class="image" v-if="isImage(file.ext)">
|
||||||
<el-image :src="file.url" fit="cover"/>
|
<el-image :src="file.url" fit="cover" />
|
||||||
</div>
|
</div>
|
||||||
<div class="item" v-else>
|
<div class="item" v-else>
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<el-image :src="GetFileIcon(file.ext)" fit="cover"/>
|
<el-image :src="GetFileIcon(file.ext)" fit="cover" />
|
||||||
</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>
|
||||||
@ -33,7 +30,7 @@
|
|||||||
<div class="content" v-html="content"></div>
|
<div class="content" v-html="content"></div>
|
||||||
<div class="bar" v-if="data.created_at > 0">
|
<div class="bar" v-if="data.created_at > 0">
|
||||||
<span class="bar-item"
|
<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>
|
<span class="bar-item">tokens: {{ finalTokens }}</span>
|
||||||
</div>
|
</div>
|
||||||
@ -44,25 +41,22 @@
|
|||||||
<div class="chat-line chat-line-prompt-chat" v-else>
|
<div class="chat-line chat-line-prompt-chat" v-else>
|
||||||
<div class="chat-line-inner">
|
<div class="chat-line-inner">
|
||||||
<div class="chat-icon">
|
<div class="chat-icon">
|
||||||
<img :src="data.icon" alt="User"/>
|
<img :src="data.icon" alt="User" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="chat-item">
|
<div class="chat-item">
|
||||||
<div v-if="files.length > 0" class="file-list-box">
|
<div v-if="files.length > 0" class="file-list-box">
|
||||||
<div v-for="file in files">
|
<div v-for="file in files">
|
||||||
<div class="image" v-if="isImage(file.ext)">
|
<div class="image" v-if="isImage(file.ext)">
|
||||||
<el-image :src="file.url" fit="cover"/>
|
<el-image :src="file.url" fit="cover" />
|
||||||
</div>
|
</div>
|
||||||
<div class="item" v-else>
|
<div class="item" v-else>
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<el-image :src="GetFileIcon(file.ext)" fit="cover"/>
|
<el-image :src="GetFileIcon(file.ext)" fit="cover" />
|
||||||
</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>
|
||||||
@ -77,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="bar" v-if="data.created_at > 0">
|
<div class="bar" v-if="data.created_at > 0">
|
||||||
<span class="bar-item"
|
<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>-->
|
<!-- <span class="bar-item">tokens: {{ finalTokens }}</span>-->
|
||||||
</div>
|
</div>
|
||||||
@ -87,12 +81,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {onMounted, ref} from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
import {Clock} from "@element-plus/icons-vue";
|
import { Clock } from "@element-plus/icons-vue";
|
||||||
import {httpPost} from "@/utils/http";
|
import { httpPost } from "@/utils/http";
|
||||||
import hl from "highlight.js";
|
import hl from "highlight.js";
|
||||||
import {dateFormat, isImage, processPrompt} from "@/utils/libs";
|
import { dateFormat, isImage, processPrompt } from "@/utils/libs";
|
||||||
import {FormatFileSize, GetFileIcon, GetFileType} from "@/store/system";
|
import { FormatFileSize, GetFileIcon, GetFileType } from "@/store/system";
|
||||||
import emoji from "markdown-it-emoji";
|
import emoji from "markdown-it-emoji";
|
||||||
import mathjaxPlugin from "markdown-it-mathjax3";
|
import mathjaxPlugin from "markdown-it-mathjax3";
|
||||||
import MarkdownIt from "markdown-it";
|
import MarkdownIt from "markdown-it";
|
||||||
@ -157,19 +151,25 @@ 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;
|
||||||
|
|
||||||
for (let link of links) {
|
for (let link of links) {
|
||||||
if (isExternalImg(link, files.value)) {
|
if (isExternalImg(link, files.value)) {
|
||||||
files.value.push({url: link, ext: ".png"});
|
files.value.push({ url: link, ext: ".png" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {});
|
||||||
});
|
|
||||||
|
|
||||||
for (let link of links) {
|
for (let link of links) {
|
||||||
content.value = content.value.replace(link, "");
|
content.value = content.value.replace(link, "");
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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(""); // 输出缓冲行
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user