提交 17925977 authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 d86688c9
......@@ -2757,23 +2757,6 @@
"thenify-all": "^1.0.0"
}
},
"node_modules/nanoid": {
"version": "3.3.7",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz",
"integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"bin": {
"nanoid": "bin/nanoid.cjs"
},
"engines": {
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
......@@ -3045,6 +3028,23 @@
"node": ">=4"
}
},
"node_modules/postcss/node_modules/nanoid": {
"version": "3.3.7",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz",
"integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"bin": {
"nanoid": "bin/nanoid.cjs"
},
"engines": {
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/prelude-ls": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
......
......@@ -33,7 +33,7 @@ async function postMessage() {
if (!userChatInput.value) return
console.log(userChatInput.value)
messages.value.push({ role: 'user', content: userChatInput.value })
post({ userChatInput: userChatInput.value, chatId: '', agentId: 'f3846153ba784b6d86bdcd5533259c88' })
post({ userChatInput: userChatInput.value })
userChatInput.value = ''
}
......
......@@ -7,6 +7,7 @@ export function useChat() {
const authSecret = 'HO4IyLEwEOHpeOXBxaLQUOqWslJRGs1M'
const messages = ref([])
const chatId = ref('')
async function post(data) {
const timestamp = Date.now()
......@@ -14,16 +15,19 @@ export function useChat() {
await fetchEventSource('/openapi/agent/chat/stream/v1', {
method: 'POST',
headers: { authKey, timestamp, sign, 'Content-Type': 'application/json' },
body: JSON.stringify(data),
body: JSON.stringify({ ...data, chatId: chatId.value, agentId: 'f3846153ba784b6d86bdcd5533259c88' }),
onmessage(res) {
console.log(res.data)
const message = JSON.parse(res.data)
chatId.value = message.chatId
const conversationId = message.conversationId
const messageId = messages.value.findIndex(session => session.conversationId === conversationId)
if (messageId === -1) {
messages.value.push({ conversationId, role: 'bot', content: message.content })
const messageIndex = messages.value.findIndex(session => session.conversationId === conversationId)
let content = message.content || ''
if (message.content === '\n') content = '<br/>'
if (messageIndex === -1) {
messages.value.push({ conversationId, role: 'bot', content })
} else {
messages.value[messageId].content + message.content
messages.value[messageIndex].content = messages.value[messageIndex].content + content
}
}
})
......@@ -33,5 +37,5 @@ export function useChat() {
await fetchAgents()
}
return { messages, post, getAgents }
return { chatId, messages, post, getAgents }
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论