diff --git a/api/handler/chatimpl/chat_handler.go b/api/handler/chatimpl/chat_handler.go index bd63d4c..11595c5 100644 --- a/api/handler/chatimpl/chat_handler.go +++ b/api/handler/chatimpl/chat_handler.go @@ -435,7 +435,11 @@ func (h *ChatHandler) doRequest(ctx context.Context, req types.ApiRequest, platf apiURL = strings.Replace(apiKey.ApiURL, "{model}", req.Model, 1) break default: - apiURL = apiKey.ApiURL + if req.Model == "gpt-4-all" { + apiURL = "https://gpt.bemore.lol/v1/chat/completions" + } else { + apiURL = apiKey.ApiURL + } } // 更新 API KEY 的最后使用时间 h.db.Model(apiKey).UpdateColumn("last_used_at", time.Now().Unix()) diff --git a/web/package-lock.json b/web/package-lock.json index f42b248..a0259b2 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -19,6 +19,7 @@ "json-bigint": "^1.0.0", "lodash": "^4.17.21", "markdown-it": "^13.0.1", + "markdown-it-emoji": "^3.0.0", "md-editor-v3": "^2.2.1", "pinia": "^2.1.4", "qrcode": "^1.5.3", @@ -7430,6 +7431,11 @@ "markdown-it": "bin/markdown-it.js" } }, + "node_modules/markdown-it-emoji": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/markdown-it-emoji/-/markdown-it-emoji-3.0.0.tgz", + "integrity": "sha512-+rUD93bXHubA4arpEZO3q80so0qgoFJEKRkRbjKX8RTdca89v2kfyF+xR3i2sQTwql9tpPZPOQN5B+PunspXRg==" + }, "node_modules/markdown-it/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -17361,6 +17367,11 @@ } } }, + "markdown-it-emoji": { + "version": "3.0.0", + "resolved": "https://registry.npmmirror.com/markdown-it-emoji/-/markdown-it-emoji-3.0.0.tgz", + "integrity": "sha512-+rUD93bXHubA4arpEZO3q80so0qgoFJEKRkRbjKX8RTdca89v2kfyF+xR3i2sQTwql9tpPZPOQN5B+PunspXRg==" + }, "md-editor-v3": { "version": "2.11.3", "resolved": "https://registry.npmjs.org/md-editor-v3/-/md-editor-v3-2.11.3.tgz", diff --git a/web/src/components/ChatPrompt.vue b/web/src/components/ChatPrompt.vue index 0bcc2ee..9954c88 100644 --- a/web/src/components/ChatPrompt.vue +++ b/web/src/components/ChatPrompt.vue @@ -102,6 +102,10 @@ export default defineComponent({ border-radius: 5px; overflow: auto; + a { + color #20a0ff + } + p { line-height 1.5 } diff --git a/web/src/components/ChatReply.vue b/web/src/components/ChatReply.vue index 7307119..2aed7e5 100644 --- a/web/src/components/ChatReply.vue +++ b/web/src/components/ChatReply.vue @@ -107,6 +107,10 @@ export default defineComponent({ border-radius: 5px; overflow auto; + a { + color #20a0ff + } + // control the image size in content img { @@ -166,6 +170,7 @@ export default defineComponent({ color #00e0e0 } + // 设置表格边框 table { @@ -190,6 +195,17 @@ export default defineComponent({ padding 10px } } + + // 代码快 + + blockquote { + margin 0 + background-color: #ebfffe; + padding: 0.8rem 1.5rem; + border-left: 0.5rem solid; + border-color: #026863; + color: #2c3e50; + } } diff --git a/web/src/views/ChatPlus.vue b/web/src/views/ChatPlus.vue index 14c6d85..8611acc 100644 --- a/web/src/views/ChatPlus.vue +++ b/web/src/views/ChatPlus.vue @@ -511,6 +511,9 @@ const removeChat = function (event, chat) { const md = require('markdown-it')({ breaks: true, + html: true, + linkify: true, + typographer: true, highlight: function (str, lang) { const codeIndex = parseInt(Date.now()) + Math.floor(Math.random() * 10000000) // 显示复制代码按钮 @@ -601,36 +604,6 @@ const connect = function (chat_id, role_id) { icon: _role['icon'], content: "" }); - } else if (data.type === "mj") { - disableInput(true) - const content = data.content; - content.html = md.render(content.content) - let key = content.key - // fixed bug: 执行 Upscale 和 Variation 操作的时候覆盖之前的绘画 - if (content.status === "Finished") { - key = randString(32) - enableInput() - } - // console.log(content) - // check if the message is in chatData - let flag = false - for (let i = 0; i < chatData.value.length; i++) { - if (chatData.value[i].id === content.key) { - flag = true - chatData.value[i].content = content - chatData.value[i].id = key - break - } - } - if (flag === false) { - chatData.value.push({ - type: "mj", - id: key, - icon: "/images/avatar/mid_journey.png", - content: content - }); - } - } else if (data.type === 'end') { // 消息接收完毕 // 追加当前会话到会话列表 if (isNewChat && newChatItem.value !== null) { @@ -659,7 +632,7 @@ const connect = function (chat_id, role_id) { lineBuffer.value += data.content; const reply = chatData.value[chatData.value.length - 1] reply['orgContent'] = lineBuffer.value; - reply['content'] = md.render(lineBuffer.value); + reply['content'] = md.render(processBlankQuote(lineBuffer.value)); } // 将聊天框的滚动条滑动到最底部 nextTick(() => { @@ -800,15 +773,8 @@ const loadChatHistory = function (chatId) { } showHello.value = false for (let i = 0; i < data.length; i++) { - if (data[i].type === "mj") { - data[i].content = JSON.parse(data[i].content) - data[i].content.html = md.render(data[i].content?.content) - chatData.value.push(data[i]); - continue; - } - data[i].orgContent = data[i].content; - data[i].content = md.render(data[i].content); + data[i].content = md.render(processBlankQuote(data[i].content)) chatData.value.push(data[i]); } @@ -822,6 +788,22 @@ const loadChatHistory = function (chatId) { }) } +const processBlankQuote = (content) => { + if (content.indexOf("\n") === -1) { + return content + } + + const texts = content.split("\n") + const lines = [] + for (let txt of texts) { + lines.push(txt) + if (txt.startsWith(">")) { + lines.push("\n") + } + } + return lines.join("\n") +} + const stopGenerate = function () { showStopGenerate.value = false; httpGet("/api/chat/stop?session_id=" + getSessionId()).then(() => {