mirror of
https://github.com/zhayujie/bot-on-anything.git
synced 2026-01-19 01:21:06 +08:00
support an optional setting max_conversation_history_per_session for chatgpt model
This commit is contained in:
@@ -78,6 +78,7 @@ cp config-template.json config.json
|
||||
|
||||
+ `clear_memory_commands`: 对话内指令,主动清空前文记忆,字符串数组可自定义指令别名。
|
||||
+ default: ["#清除记忆"]
|
||||
+ `max_history_per_session`[optional]: 对话最大记忆长度,超过该长度则清理前面的记忆。
|
||||
|
||||
## 二、选择模型
|
||||
|
||||
|
||||
@@ -196,6 +196,7 @@ class Session(object):
|
||||
@staticmethod
|
||||
def save_session(query, answer, user_id, used_tokens=0):
|
||||
max_tokens = model_conf(const.OPEN_AI).get('conversation_max_tokens')
|
||||
max_history_per_session = model_conf(const.OPEN_AI).get('max_history_per_session', None)
|
||||
if not max_tokens or max_tokens > 4000:
|
||||
# default value
|
||||
max_tokens = 1000
|
||||
@@ -210,6 +211,10 @@ class Session(object):
|
||||
session.pop(1)
|
||||
session.pop(1)
|
||||
|
||||
if max_history_per_session is not None:
|
||||
while len(session) > max_history_per_session + 1:
|
||||
session.pop(1)
|
||||
|
||||
@staticmethod
|
||||
def clear_session(user_id):
|
||||
user_session[user_id] = []
|
||||
|
||||
Reference in New Issue
Block a user