Skip to content

Commit

Permalink
Merge pull request #176 from zhayujie/fix-reply-cut-off
Browse files Browse the repository at this point in the history
fix: replies were cut off #152
  • Loading branch information
zhayujie authored Feb 11, 2023
2 parents 25c2f1a + 24f00a2 commit 33e84a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ cp config-template.json config.json
"group_name_white_list": ["ChatGPT测试群", "ChatGPT测试群2"], # 开启自动回复的群名称列表
"image_create_prefix": ["", "", ""], # 开启图片回复的前缀
"conversation_max_tokens": 1000, # 支持上下文记忆的最多字符数
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你乐于回答人们的各种问题" # 人格描述
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流" # 人格描述
}
```
**配置说明:**
Expand Down Expand Up @@ -143,6 +143,6 @@ FAQs: <https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs>

## 联系

欢迎提交PR、Issues,以及Star支持一下。程序运行遇到问题优先查看 [常见问题列表](https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs) ,其次前往 [Issues](https://github.com/zhayujie/chatgpt-on-wechat/issues) 中搜索,没有相似问题则创建Issue,一段时间内无回复可加微信 eijuyahz 交流。
欢迎提交PR、Issues,以及Star支持一下。程序运行遇到问题优先查看 [常见问题列表](https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs) ,其次前往 [Issues](https://github.com/zhayujie/chatgpt-on-wechat/issues) 中搜索,若无相似问题可创建Issue,或加微信 eijuyahz 交流。


10 changes: 5 additions & 5 deletions bot/openai/open_ai_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class OpenAIBot(Bot):
def __init__(self):
openai.api_key = conf().get('open_ai_api_key')

def reply(self, query, context=None):

def reply(self, query, context=None):
# acquire reply content
if not context or not context.get('type') or context.get('type') == 'TEXT':
logger.info("[OPEN_AI] query={}".format(query))
Expand Down Expand Up @@ -45,9 +45,9 @@ def reply_text(self, query, user_id, retry_count=0):
top_p=1,
frequency_penalty=0.0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
presence_penalty=0.0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
stop=["#"]
stop=["\n\n\n"]
)
res_content = response.choices[0]["text"].strip().rstrip("<|im_end|>")
res_content = response.choices[0]['text'].strip().replace('<|endoftext|>', '')
logger.info("[OPEN_AI] reply={}".format(res_content))
return res_content
except openai.error.RateLimitError as e:
Expand Down Expand Up @@ -104,11 +104,11 @@ def build_session_query(query, user_id):
'''
prompt = conf().get("character_desc", "")
if prompt:
prompt += "\n\n"
prompt += "<|endoftext|>\n\n\n"
session = user_session.get(user_id, None)
if session:
for conversation in session:
prompt += "Q: " + conversation["question"] + "\n\n\nA: " + conversation["answer"] + "<|im_end|>\n"
prompt += "Q: " + conversation["question"] + "\n\n\nA: " + conversation["answer"] + "<|endoftext|>\n"
prompt += "Q: " + query + "\nA: "
return prompt
else:
Expand Down

0 comments on commit 33e84a9

Please sign in to comment.