添加历史对话轮数的支持,默认 5 轮对话

This commit is contained in:
Wenjie Zhang 2024-08-07 17:42:26 +08:00
parent 312e3af23e
commit 317974c8ac
3 changed files with 17 additions and 12 deletions

View File

@ -25,9 +25,13 @@ class HistoryManager():
self.add_ai(content)
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."""
history = self.messages[:]
if max_rounds is None:
history = self.messages[:]
else:
history = self.messages[-(2*max_rounds):]
history.append({"role": role, "content": msg})
return history

View File

@ -34,7 +34,7 @@ def chat():
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)
logger.debug(f"Web history: {history_manager}")

View File

@ -43,7 +43,7 @@
<component :is="opts.showPanel ? FolderOpenOutlined : FolderOutlined" /> <span class="text">选项</span>
</div>
<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>
<a-dropdown>
@ -65,21 +65,24 @@
</a-dropdown>
</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>
<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>
</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>
<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>
<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>
<div class="flex-center">
最大历史轮数 <a-input-number id="inputNumber" v-model:value="meta.history_round" :min="1" :max="50" />
</div>
</div>
</div>
</div>
@ -216,6 +219,7 @@ const meta = reactive(JSON.parse(localStorage.getItem('meta')) || {
selectedKB: null,
stream: true,
summary_title: true,
history_round: 5,
})
// marked https://marked.js.org/
@ -517,9 +521,6 @@ watch(
justify-content: space-between;
align-items: center;
gap: 10px;
}
.graphbase {
padding: 8px 16px;
border-radius: 12px;
cursor: pointer;