diff --git a/README.md b/README.md index e78cd3e..aa1914f 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ cp config-template.json config.json "group_chat_prefix": ["@bot"], # 群聊时包含该前缀则会触发机器人回复 "group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"], # 开启自动回复的群名称列表 "image_create_prefix": ["画", "看", "找"], # 开启图片回复的前缀 - "conversation_max_tokens": 3000 # 支持上下文记忆的最多字符数 + "conversation_max_tokens": 1000 # 支持上下文记忆的最多字符数 } ``` **配置说明:** diff --git a/bot/openai/open_ai_bot.py b/bot/openai/open_ai_bot.py index a6858c0..0aedc4d 100644 --- a/bot/openai/open_ai_bot.py +++ b/bot/openai/open_ai_bot.py @@ -117,22 +117,24 @@ class Session(object): :param user_id: from user id :return: query content with conversaction ''' - new_query = "" + prompt = conf().get("character_desc", "") + if prompt: + prompt += "\n\n" session = user_session.get(user_id, None) if session: for conversation in session: - new_query += "Q: " + conversation["question"] + "\n\n\nA: " + conversation["answer"] + "<|im_end|>\n" - new_query += "Q: " + query + "\nA: " - return new_query + prompt += "Q: " + conversation["question"] + "\n\n\nA: " + conversation["answer"] + "<|im_end|>\n" + prompt += "Q: " + query + "\nA: " + return prompt else: - return "Q: " + query + "\nA: " + return prompt + "Q: " + query + "\nA: " @staticmethod def save_session(query, answer, user_id): max_tokens = conf().get("conversation_max_tokens") if not max_tokens: # default 3000 - max_tokens = 3000 + max_tokens = 1000 conversation = dict() conversation["question"] = query conversation["answer"] = answer diff --git a/config-template.json b/config-template.json index 84d660c..148e6a4 100644 --- a/config-template.json +++ b/config-template.json @@ -5,5 +5,5 @@ "group_chat_prefix": ["@bot"], "group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"], "image_create_prefix": ["画", "看", "找"], - "conversation_max_tokens": 3000 + "conversation_max_tokens": 1000 } diff --git a/requirement.txt b/requirement.txt new file mode 100644 index 0000000..18dce49 --- /dev/null +++ b/requirement.txt @@ -0,0 +1,2 @@ +itchat-uos==1.5.0.dev0 +openai