添加历史对话轮数的支持,默认 5 轮对话
This commit is contained in:
parent
312e3af23e
commit
317974c8ac
@ -25,9 +25,13 @@ class HistoryManager():
|
|||||||
self.add_ai(content)
|
self.add_ai(content)
|
||||||
return self.messages
|
return self.messages
|
||||||
|
|
||||||
def get_history_with_msg(self, msg, role="user"):
|
def get_history_with_msg(self, msg, role="user", max_rounds=None):
|
||||||
"""Get history with new message, but not append it to history."""
|
"""Get history with new message, but not append it to history."""
|
||||||
history = self.messages[:]
|
if max_rounds is None:
|
||||||
|
history = self.messages[:]
|
||||||
|
else:
|
||||||
|
history = self.messages[-(2*max_rounds):]
|
||||||
|
|
||||||
history.append({"role": role, "content": msg})
|
history.append({"role": role, "content": msg})
|
||||||
return history
|
return history
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ def chat():
|
|||||||
|
|
||||||
new_query, refs = startup.retriever(query, history_manager.messages, meta)
|
new_query, refs = startup.retriever(query, history_manager.messages, meta)
|
||||||
|
|
||||||
messages = history_manager.get_history_with_msg(new_query)
|
messages = history_manager.get_history_with_msg(new_query, max_rounds=meta.get('history_round'))
|
||||||
history_manager.add_user(query)
|
history_manager.add_user(query)
|
||||||
logger.debug(f"Web history: {history_manager}")
|
logger.debug(f"Web history: {history_manager}")
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
<component :is="opts.showPanel ? FolderOpenOutlined : FolderOutlined" /> <span class="text">选项</span>
|
<component :is="opts.showPanel ? FolderOpenOutlined : FolderOutlined" /> <span class="text">选项</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="opts.showPanel" class="my-panal swing-in-top-fwd" ref="panel">
|
<div v-if="opts.showPanel" class="my-panal swing-in-top-fwd" ref="panel">
|
||||||
<div class="graphbase flex-center" v-if="configStore.config.enable_knowledge_base">
|
<div class="flex-center" v-if="configStore.config.enable_knowledge_base">
|
||||||
知识库
|
知识库
|
||||||
<div @click.stop>
|
<div @click.stop>
|
||||||
<a-dropdown>
|
<a-dropdown>
|
||||||
@ -65,21 +65,24 @@
|
|||||||
</a-dropdown>
|
</a-dropdown>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="graphbase flex-center" @click="meta.use_graph = !meta.use_graph" v-if="configStore.config.enable_knowledge_base">
|
<div class="flex-center" @click="meta.use_graph = !meta.use_graph" v-if="configStore.config.enable_knowledge_base">
|
||||||
图数据库 <div @click.stop><a-switch v-model:checked="meta.use_graph" /></div>
|
图数据库 <div @click.stop><a-switch v-model:checked="meta.use_graph" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="graphbase flex-center" @click="meta.use_web = !meta.use_web" v-if="configStore.config.enable_search_engine">
|
<div class="flex-center" @click="meta.use_web = !meta.use_web" v-if="configStore.config.enable_search_engine">
|
||||||
搜索引擎(Bing) <div @click.stop><a-switch v-model:checked="meta.use_web" /></div>
|
搜索引擎(Bing) <div @click.stop><a-switch v-model:checked="meta.use_web" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="graphbase flex-center" @click="meta.rewrite_query = !meta.rewrite_query" v-if="configStore.config.enable_reranker">
|
<div class="flex-center" @click="meta.rewrite_query = !meta.rewrite_query" v-if="configStore.config.enable_reranker">
|
||||||
重写查询 <div @click.stop><a-switch v-model:checked="meta.rewrite_query" /></div>
|
重写查询 <div @click.stop><a-switch v-model:checked="meta.rewrite_query" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="graphbase flex-center" @click="meta.rewrite_query = !meta.rewrite_query">
|
<div class="flex-center" @click="meta.rewrite_query = !meta.rewrite_query">
|
||||||
流式输出 <div @click.stop><a-switch v-model:checked="meta.stream" /></div>
|
流式输出 <div @click.stop><a-switch v-model:checked="meta.stream" /></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="graphbase flex-center" @click="meta.summary_title = !meta.summary_title">
|
<div class="flex-center" @click="meta.summary_title = !meta.summary_title">
|
||||||
总结对话标题 <div @click.stop><a-switch v-model:checked="meta.summary_title" /></div>
|
总结对话标题 <div @click.stop><a-switch v-model:checked="meta.summary_title" /></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex-center">
|
||||||
|
最大历史轮数 <a-input-number id="inputNumber" v-model:value="meta.history_round" :min="1" :max="50" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -216,6 +219,7 @@ const meta = reactive(JSON.parse(localStorage.getItem('meta')) || {
|
|||||||
selectedKB: null,
|
selectedKB: null,
|
||||||
stream: true,
|
stream: true,
|
||||||
summary_title: true,
|
summary_title: true,
|
||||||
|
history_round: 5,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 更多选项可以在 marked 文档中找到:https://marked.js.org/
|
// 更多选项可以在 marked 文档中找到:https://marked.js.org/
|
||||||
@ -517,9 +521,6 @@ watch(
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
|
||||||
|
|
||||||
.graphbase {
|
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user