diff --git a/CHANGELOG.md b/CHANGELOG.md index 146c4f3d..89dc3c7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,12 @@ # 更新日志 ## v4.0.8 +* 功能优化:升级 mathjax 公式解析插件,修复公式因为图片访问限制而无法显示的问题 * 功能优化:当数据库更新失败的时候记录错误日志 * 功能优化:聊天输入框会随着输入内容的增多自动调整高度 * Bug修复:修复移动端聊天页面模型切换不生效的Bug * 功能优化:给PC端扫码支付增加签名验证和有效期验证 * Bug修复:修复支付码生成API权限控制的问题 +* Bug修复:模型算力设置为0时,不扣减用户算力,并且不记录算力消费日志 ## v4.0.7 diff --git a/api/handler/chatimpl/chat_handler.go b/api/handler/chatimpl/chat_handler.go index 894a347a..c181e12b 100644 --- a/api/handler/chatimpl/chat_handler.go +++ b/api/handler/chatimpl/chat_handler.go @@ -462,7 +462,7 @@ func (h *ChatHandler) doRequest(ctx context.Context, req types.ApiRequest, sessi } // use the last unused key if apiKey.Id == 0 { - h.DB.Debug().Where("platform", session.Model.Platform).Where("type", "chat").Where("enabled", true).Order("last_used_at ASC").First(apiKey) + h.DB.Where("platform", session.Model.Platform).Where("type", "chat").Where("enabled", true).Order("last_used_at ASC").First(apiKey) } if apiKey.Id == 0 { return nil, errors.New("no available key, please import key") @@ -655,24 +655,26 @@ func (h *ChatHandler) saveChatHistory( logger.Error("failed to save reply history message: ", res.Error) } - // 更新用户算力 - h.subUserPower(userVo, session, promptToken, replyTokens) + if session.Model.Power > 0 { + // 更新用户算力 + h.subUserPower(userVo, session, promptToken, replyTokens) - // 保存当前会话 - var chatItem model.ChatItem - res = h.DB.Where("chat_id = ?", session.ChatId).First(&chatItem) - if res.Error != nil { - chatItem.ChatId = session.ChatId - chatItem.UserId = session.UserId - chatItem.RoleId = role.Id - chatItem.ModelId = session.Model.Id - if utf8.RuneCountInString(prompt) > 30 { - chatItem.Title = string([]rune(prompt)[:30]) + "..." - } else { - chatItem.Title = prompt + // 保存当前会话 + var chatItem model.ChatItem + res = h.DB.Where("chat_id = ?", session.ChatId).First(&chatItem) + if res.Error != nil { + chatItem.ChatId = session.ChatId + chatItem.UserId = session.UserId + chatItem.RoleId = role.Id + chatItem.ModelId = session.Model.Id + if utf8.RuneCountInString(prompt) > 30 { + chatItem.Title = string([]rune(prompt)[:30]) + "..." + } else { + chatItem.Title = prompt + } + chatItem.Model = req.Model + h.DB.Create(&chatItem) } - chatItem.Model = req.Model - h.DB.Create(&chatItem) } } diff --git a/web/.env.development b/web/.env.development index 9811fffe..62d3b372 100644 --- a/web/.env.development +++ b/web/.env.development @@ -6,4 +6,4 @@ VUE_APP_ADMIN_USER=admin VUE_APP_ADMIN_PASS=admin123 VUE_APP_KEY_PREFIX=ChatPLUS_DEV_ VUE_APP_TITLE="Geek-AI 创作系统" -VUE_APP_VERSION=v4.0.7 +VUE_APP_VERSION=v4.0.8 diff --git a/web/.env.production b/web/.env.production index 9404e7a0..3f594239 100644 --- a/web/.env.production +++ b/web/.env.production @@ -2,4 +2,4 @@ VUE_APP_API_HOST= VUE_APP_WS_HOST= VUE_APP_KEY_PREFIX=ChatPLUS_ VUE_APP_TITLE="Geek-AI 创作系统" -VUE_APP_VERSION=v4.0.7 +VUE_APP_VERSION=v4.0.8 diff --git a/web/package.json b/web/package.json index a38dc236..e9969bba 100644 --- a/web/package.json +++ b/web/package.json @@ -20,8 +20,7 @@ "json-bigint": "^1.0.0", "lodash": "^4.17.21", "markdown-it": "^13.0.1", - "markdown-it-latex2img": "^0.0.6", - "markdown-it-mathjax": "^2.0.0", + "markdown-it-mathjax3": "^4.3.2", "markmap-common": "^0.16.0", "markmap-lib": "^0.16.1", "markmap-toolbar": "^0.17.0", diff --git a/web/src/views/ChatPlus.vue b/web/src/views/ChatPlus.vue index 4b9b1602..887ddf77 100644 --- a/web/src/views/ChatPlus.vue +++ b/web/src/views/ChatPlus.vue @@ -503,8 +503,7 @@ const removeChat = function (chat) { } -const latexPlugin = require('markdown-it-latex2img') -const mathjaxPlugin = require('markdown-it-mathjax') +const mathjaxPlugin = require('markdown-it-mathjax3') const md = require('markdown-it')({ breaks: true, html: true, @@ -529,7 +528,6 @@ const md = require('markdown-it')({ return `
${preCode}
${copyBtn}
`
}
});
-md.use(latexPlugin)
md.use(mathjaxPlugin)
// 创建 socket 连接
diff --git a/web/src/views/admin/ChatList.vue b/web/src/views/admin/ChatList.vue
index 10292745..4da48ca6 100644
--- a/web/src/views/admin/ChatList.vue
+++ b/web/src/views/admin/ChatList.vue
@@ -163,11 +163,8 @@
:model="item.model"
:content="item.content"/>
${preCode}
`
}
});
-md.use(latexPlugin)
md.use(mathjaxPlugin)
const showContentDialog = ref(false)
diff --git a/web/src/views/mobile/ChatList.vue b/web/src/views/mobile/ChatList.vue
index f31d0c27..ed4d186a 100644
--- a/web/src/views/mobile/ChatList.vue
+++ b/web/src/views/mobile/ChatList.vue
@@ -225,18 +225,6 @@ const newChat = (item) => {
}
showPicker.value = false
const options = item.selectedOptions
- // setChatConfig({
- // role: {
- // id: options[0].value,
- // name: options[0].text,
- // icon: options[0].icon,
- // helloMsg: options[0].helloMsg
- // },
- // model: options[1].value,
- // modelValue: getModelValue(options[1].value),
- // title: '新建会话',
- // chatId: 0
- // })
router.push({
name: "mobile-chat-session",
params: {role_id: options[0].value, model_id: options[1].value, title: '新建会话', chat_id: 0}
@@ -244,25 +232,6 @@ const newChat = (item) => {
}
const changeChat = (chat) => {
- // let role = {}
- // for (let i = 0; i < roles.value.length; i++) {
- // if (roles.value[i].value === chat.role_id) {
- // role = roles.value[i]
- // break
- // }
- // }
- // setChatConfig({
- // role: {
- // id: chat.role_id,
- // name: role.text,
- // icon: role.icon
- // },
- // model: chat.model_id,
- // modelValue: getModelValue(chat.model_id),
- // title: chat.title,
- // chatId: chat.chat_id,
- // helloMsg: chat.hello_msg,
- // })
router.push(`/mobile/chat/session?chat_id=${chat.chat_id}`)
}
diff --git a/web/src/views/mobile/ChatSession.vue b/web/src/views/mobile/ChatSession.vue
index a8c0fde8..e1de43d8 100644
--- a/web/src/views/mobile/ChatSession.vue
+++ b/web/src/views/mobile/ChatSession.vue
@@ -249,8 +249,7 @@ const loading = ref(false)
const finished = ref(false)
const error = ref(false)
-const latexPlugin = require('markdown-it-latex2img')
-const mathjaxPlugin = require('markdown-it-mathjax')
+const mathjaxPlugin = require('markdown-it-mathjax3')
const md = require('markdown-it')({
breaks: true,
html: true,
@@ -275,7 +274,6 @@ const md = require('markdown-it')({
return `${preCode}
${copyBtn}
`
}
});
-md.use(latexPlugin)
md.use(mathjaxPlugin)