更新历史记录消息(获得更加准确的历史消息,后面考虑将 conv.history 移除)
This commit is contained in:
parent
7e6a974757
commit
b653042e90
@ -271,7 +271,7 @@ const meta = reactive(JSON.parse(localStorage.getItem('meta')) || {
|
||||
selectedKB: null,
|
||||
stream: true,
|
||||
summary_title: false,
|
||||
history_round: 5,
|
||||
history_round: 20,
|
||||
db_id: null,
|
||||
fontSize: 'default',
|
||||
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 selected = opts.databases[index]
|
||||
console.log(selected)
|
||||
@ -494,14 +512,17 @@ const fetchChatResponse = (user_input, cur_res_id) => {
|
||||
const controller = new AbortController();
|
||||
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/', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
query: user_input,
|
||||
history: conv.value.history,
|
||||
meta: meta,
|
||||
cur_res_id: cur_res_id,
|
||||
}),
|
||||
body: JSON.stringify(params),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user