更新历史记录消息(获得更加准确的历史消息,后面考虑将 conv.history 移除)
This commit is contained in:
parent
7e6a974757
commit
b653042e90
@ -119,10 +119,10 @@
|
|||||||
请求错误,请重试。{{ message.message }}
|
请求错误,请重试。{{ message.message }}
|
||||||
</div>
|
</div>
|
||||||
<div v-if="message.isStoppedByUser" class="retry-hint">
|
<div v-if="message.isStoppedByUser" class="retry-hint">
|
||||||
你停止生成了本次回答
|
你停止生成了本次回答
|
||||||
<span class="retry-link" @click="retryStoppedMessage(message)">重新编辑问题</span>
|
<span class="retry-link" @click="retryStoppedMessage(message)">重新编辑问题</span>
|
||||||
</div>
|
</div>
|
||||||
<RefsComponent v-if="message.role=='received' && message.status=='finished'" :message="message" :conv="conv" @regenerateMessage="regenerateMessage" />
|
<RefsComponent v-if="message.role=='received' && message.status=='finished'" :message="message" :conv="conv" @regenerateMessage="regenerateMessage" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bottom">
|
<div class="bottom">
|
||||||
@ -176,10 +176,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="options__right">
|
<div class="options__right">
|
||||||
<a-tooltip :title="isStreaming ? '停止回答' : ''">
|
<a-tooltip :title="isStreaming ? '停止回答' : ''">
|
||||||
<a-button
|
<a-button
|
||||||
size="large"
|
size="large"
|
||||||
@click="handleSendOrStop"
|
@click="handleSendOrStop"
|
||||||
:disabled="(!conv.inputText && !isStreaming)"
|
:disabled="(!conv.inputText && !isStreaming)"
|
||||||
type="link"
|
type="link"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
@ -271,7 +271,7 @@ const meta = reactive(JSON.parse(localStorage.getItem('meta')) || {
|
|||||||
selectedKB: null,
|
selectedKB: null,
|
||||||
stream: true,
|
stream: true,
|
||||||
summary_title: false,
|
summary_title: false,
|
||||||
history_round: 5,
|
history_round: 20,
|
||||||
db_id: null,
|
db_id: null,
|
||||||
fontSize: 'default',
|
fontSize: 'default',
|
||||||
wideScreen: false,
|
wideScreen: false,
|
||||||
@ -303,6 +303,24 @@ const renderMarkdown = (msg) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从 message 中获取 history 信息,每个消息都是 {role, content} 的格式
|
||||||
|
const getHistory = () => {
|
||||||
|
const history = conv.value.messages.map((msg) => {
|
||||||
|
if (msg.text) {
|
||||||
|
return {
|
||||||
|
role: msg.role === 'sent' ? 'user' : 'assistant',
|
||||||
|
content: msg.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).reduce((acc, cur) => {
|
||||||
|
if (cur) {
|
||||||
|
acc.push(cur)
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, [])
|
||||||
|
return history.slice(-meta.history_round)
|
||||||
|
}
|
||||||
|
|
||||||
const useDatabase = (index) => {
|
const useDatabase = (index) => {
|
||||||
const selected = opts.databases[index]
|
const selected = opts.databases[index]
|
||||||
console.log(selected)
|
console.log(selected)
|
||||||
@ -494,14 +512,17 @@ const fetchChatResponse = (user_input, cur_res_id) => {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const signal = controller.signal;
|
const signal = controller.signal;
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
query: user_input,
|
||||||
|
history: getHistory(),
|
||||||
|
meta: meta,
|
||||||
|
cur_res_id: cur_res_id,
|
||||||
|
}
|
||||||
|
console.log(params)
|
||||||
|
|
||||||
fetch('/api/chat/', {
|
fetch('/api/chat/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(params),
|
||||||
query: user_input,
|
|
||||||
history: conv.value.history,
|
|
||||||
meta: meta,
|
|
||||||
cur_res_id: cur_res_id,
|
|
||||||
}),
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
@ -971,7 +992,7 @@ const regenerateMessage = (message) => {
|
|||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
text-align: justify;
|
text-align: justify;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user