Sfoglia il codice sorgente

fix: reduce session max words

master
zhayujie 1 anno fa
parent
commit
152724f05d
4 ha cambiato i file con 12 aggiunte e 8 eliminazioni
  1. +1
    -1
      README.md
  2. +8
    -6
      bot/openai/open_ai_bot.py
  3. +1
    -1
      config-template.json
  4. +2
    -0
      requirement.txt

+ 1
- 1
README.md Vedi File

@@ -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 # 支持上下文记忆的最多字符数
}
```
**配置说明:**


+ 8
- 6
bot/openai/open_ai_bot.py Vedi File

@@ -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


+ 1
- 1
config-template.json Vedi File

@@ -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
}

+ 2
- 0
requirement.txt Vedi File

@@ -0,0 +1,2 @@
itchat-uos==1.5.0.dev0
openai

Loading…
Annulla
Salva