fix markdown formula parse plugin

This commit is contained in:
RockYang 2024-05-29 13:49:45 +08:00
parent 1b0938b33f
commit f0959b5df6
9 changed files with 29 additions and 66 deletions

View File

@ -1,10 +1,12 @@
# 更新日志 # 更新日志
## v4.0.8 ## v4.0.8
* 功能优化:升级 mathjax 公式解析插件,修复公式因为图片访问限制而无法显示的问题
* 功能优化:当数据库更新失败的时候记录错误日志 * 功能优化:当数据库更新失败的时候记录错误日志
* 功能优化:聊天输入框会随着输入内容的增多自动调整高度 * 功能优化:聊天输入框会随着输入内容的增多自动调整高度
* Bug修复修复移动端聊天页面模型切换不生效的Bug * Bug修复修复移动端聊天页面模型切换不生效的Bug
* 功能优化给PC端扫码支付增加签名验证和有效期验证 * 功能优化给PC端扫码支付增加签名验证和有效期验证
* Bug修复修复支付码生成API权限控制的问题 * Bug修复修复支付码生成API权限控制的问题
* Bug修复模型算力设置为0时不扣减用户算力并且不记录算力消费日志
## v4.0.7 ## v4.0.7

View File

@ -462,7 +462,7 @@ func (h *ChatHandler) doRequest(ctx context.Context, req types.ApiRequest, sessi
} }
// use the last unused key // use the last unused key
if apiKey.Id == 0 { 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 { if apiKey.Id == 0 {
return nil, errors.New("no available key, please import key") 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) logger.Error("failed to save reply history message: ", res.Error)
} }
// 更新用户算力 if session.Model.Power > 0 {
h.subUserPower(userVo, session, promptToken, replyTokens) // 更新用户算力
h.subUserPower(userVo, session, promptToken, replyTokens)
// 保存当前会话 // 保存当前会话
var chatItem model.ChatItem var chatItem model.ChatItem
res = h.DB.Where("chat_id = ?", session.ChatId).First(&chatItem) res = h.DB.Where("chat_id = ?", session.ChatId).First(&chatItem)
if res.Error != nil { if res.Error != nil {
chatItem.ChatId = session.ChatId chatItem.ChatId = session.ChatId
chatItem.UserId = session.UserId chatItem.UserId = session.UserId
chatItem.RoleId = role.Id chatItem.RoleId = role.Id
chatItem.ModelId = session.Model.Id chatItem.ModelId = session.Model.Id
if utf8.RuneCountInString(prompt) > 30 { if utf8.RuneCountInString(prompt) > 30 {
chatItem.Title = string([]rune(prompt)[:30]) + "..." chatItem.Title = string([]rune(prompt)[:30]) + "..."
} else { } else {
chatItem.Title = prompt chatItem.Title = prompt
}
chatItem.Model = req.Model
h.DB.Create(&chatItem)
} }
chatItem.Model = req.Model
h.DB.Create(&chatItem)
} }
} }

View File

@ -6,4 +6,4 @@ VUE_APP_ADMIN_USER=admin
VUE_APP_ADMIN_PASS=admin123 VUE_APP_ADMIN_PASS=admin123
VUE_APP_KEY_PREFIX=ChatPLUS_DEV_ VUE_APP_KEY_PREFIX=ChatPLUS_DEV_
VUE_APP_TITLE="Geek-AI 创作系统" VUE_APP_TITLE="Geek-AI 创作系统"
VUE_APP_VERSION=v4.0.7 VUE_APP_VERSION=v4.0.8

View File

@ -2,4 +2,4 @@ VUE_APP_API_HOST=
VUE_APP_WS_HOST= VUE_APP_WS_HOST=
VUE_APP_KEY_PREFIX=ChatPLUS_ VUE_APP_KEY_PREFIX=ChatPLUS_
VUE_APP_TITLE="Geek-AI 创作系统" VUE_APP_TITLE="Geek-AI 创作系统"
VUE_APP_VERSION=v4.0.7 VUE_APP_VERSION=v4.0.8

View File

@ -20,8 +20,7 @@
"json-bigint": "^1.0.0", "json-bigint": "^1.0.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"markdown-it-latex2img": "^0.0.6", "markdown-it-mathjax3": "^4.3.2",
"markdown-it-mathjax": "^2.0.0",
"markmap-common": "^0.16.0", "markmap-common": "^0.16.0",
"markmap-lib": "^0.16.1", "markmap-lib": "^0.16.1",
"markmap-toolbar": "^0.17.0", "markmap-toolbar": "^0.17.0",

View File

@ -503,8 +503,7 @@ const removeChat = function (chat) {
} }
const latexPlugin = require('markdown-it-latex2img') const mathjaxPlugin = require('markdown-it-mathjax3')
const mathjaxPlugin = require('markdown-it-mathjax')
const md = require('markdown-it')({ const md = require('markdown-it')({
breaks: true, breaks: true,
html: true, html: true,
@ -529,7 +528,6 @@ const md = require('markdown-it')({
return `<pre class="code-container"><code class="language-${lang} hljs">${preCode}</code>${copyBtn}</pre>` return `<pre class="code-container"><code class="language-${lang} hljs">${preCode}</code>${copyBtn}</pre>`
} }
}); });
md.use(latexPlugin)
md.use(mathjaxPlugin) md.use(mathjaxPlugin)
// socket // socket

View File

@ -163,11 +163,8 @@
:model="item.model" :model="item.model"
:content="item.content"/> :content="item.content"/>
<chat-reply v-else-if="item.type==='reply'" <chat-reply v-else-if="item.type==='reply'"
:icon="item.icon" :read-only="true"
:org-content="item.orgContent" :data="item"/>
:created-at="dateFormat(item['created_at'])"
:tokens="item['tokens']"
:content="item.content"/>
</div> </div>
</div><!-- end chat box --> </div><!-- end chat box -->
</el-dialog> </el-dialog>
@ -291,8 +288,7 @@ const removeMessage = function (row) {
}) })
} }
const latexPlugin = require('markdown-it-latex2img') const mathjaxPlugin = require('markdown-it-mathjax3')
const mathjaxPlugin = require('markdown-it-mathjax')
const md = require('markdown-it')({ const md = require('markdown-it')({
breaks: true, breaks: true,
html: true, html: true,
@ -312,7 +308,6 @@ const md = require('markdown-it')({
return `<pre class="code-container"><code class="language-${lang} hljs">${preCode}</code></pre>` return `<pre class="code-container"><code class="language-${lang} hljs">${preCode}</code></pre>`
} }
}); });
md.use(latexPlugin)
md.use(mathjaxPlugin) md.use(mathjaxPlugin)
const showContentDialog = ref(false) const showContentDialog = ref(false)

View File

@ -225,18 +225,6 @@ const newChat = (item) => {
} }
showPicker.value = false showPicker.value = false
const options = item.selectedOptions 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({ router.push({
name: "mobile-chat-session", name: "mobile-chat-session",
params: {role_id: options[0].value, model_id: options[1].value, title: '新建会话', chat_id: 0} 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) => { 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}`) router.push(`/mobile/chat/session?chat_id=${chat.chat_id}`)
} }

View File

@ -249,8 +249,7 @@ const loading = ref(false)
const finished = ref(false) const finished = ref(false)
const error = ref(false) const error = ref(false)
const latexPlugin = require('markdown-it-latex2img') const mathjaxPlugin = require('markdown-it-mathjax3')
const mathjaxPlugin = require('markdown-it-mathjax')
const md = require('markdown-it')({ const md = require('markdown-it')({
breaks: true, breaks: true,
html: true, html: true,
@ -275,7 +274,6 @@ const md = require('markdown-it')({
return `<pre class="code-container"><code class="language-${lang} hljs">${preCode}</code>${copyBtn}</pre>` return `<pre class="code-container"><code class="language-${lang} hljs">${preCode}</code>${copyBtn}</pre>`
} }
}); });
md.use(latexPlugin)
md.use(mathjaxPlugin) md.use(mathjaxPlugin)