feat: gpt-4-all model is ready

This commit is contained in:
RockYang 2024-01-15 14:07:24 +08:00
parent a140671aad
commit 59fa21779b
5 changed files with 57 additions and 40 deletions

View File

@ -435,8 +435,12 @@ func (h *ChatHandler) doRequest(ctx context.Context, req types.ApiRequest, platf
apiURL = strings.Replace(apiKey.ApiURL, "{model}", req.Model, 1)
break
default:
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())
// 百度文心,需要串接 access_token

11
web/package-lock.json generated
View File

@ -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",

View File

@ -102,6 +102,10 @@ export default defineComponent({
border-radius: 5px;
overflow: auto;
a {
color #20a0ff
}
p {
line-height 1.5
}

View File

@ -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;
}
}

View File

@ -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(() => {