瀏覽代碼

fix: encoding bug

zhayujie 3 年之前
父節點
當前提交
06065853a9
共有 5 個文件被更改,包括 15 次插入5 次删除
  1. 3 3
      README.md
  2. 2 0
      app.py
  3. 5 1
      bot/openai/open_ai_bot.py
  4. 2 0
      channel/wechat/wechat_channel.py
  5. 3 1
      config.py

+ 3 - 3
README.md

@@ -39,7 +39,7 @@
 
 ### 3.运行环境
 
-支持运行在 Linux、MacOS、Windows 操作系统上,需安装 `Python3.6` 及以上版本。推荐使用Linux服务器,可以托管在后台长期运行。
+支持运行在 Linux、MacOS、Windows 系统上,需安装有 `Python`(版本在3.7.1 ~ 3.8.16 之间),推荐使用Linux服务器,可以托管在后台长期运行。
 
 克隆项目代码:
 
@@ -78,7 +78,7 @@ pip3 install openai
 
 1.如果是开发机本地调试,直接在项目根目录下执行:
 
-```
+```bash
 python3 app.py
 ```
 终端输出二维码后,使用微信进行扫码,当输出 "Start auto replying" 时表示自动回复程序已经成功运行了。
@@ -86,7 +86,7 @@ python3 app.py
 
 2.如果是服务器部署,则使用nohup命令在后台运行:
 
-```
+```bash
 touch nohup.out                                   # 首次运行需要新建日志文件                     
 nohup python3 app.py & tail -f nohup.out          # 后台运行程序并输出日志
 ```

+ 2 - 0
app.py

@@ -1,3 +1,5 @@
+# encoding:utf-8
+
 import config
 from channel import channel_factory
 

+ 5 - 1
bot/openai/open_ai_bot.py

@@ -1,3 +1,5 @@
+# encoding:utf-8
+
 from bot.bot import Bot
 from config import conf
 from common.log import logger
@@ -19,7 +21,7 @@ class OpenAIBot(Bot):
                 max_tokens=1200,               #回复最大的字符数
                 top_p=1,
                 frequency_penalty=0.0,         #[-2,2]之间,该值越大则更倾向于产生不同的内容
-                presence_penalty=0.2,          #[-2,2]之间,该值越大则更倾向于产生不同的内容
+                presence_penalty=0.6,          #[-2,2]之间,该值越大则更倾向于产生不同的内容
                 stop=["#"]
             )
             res_content = response.choices[0]["text"].strip()
@@ -28,3 +30,5 @@ class OpenAIBot(Bot):
             return None
         logger.info("[OPEN_AI] reply={}".format(res_content))
         return res_content
+
+

+ 2 - 0
channel/wechat/wechat_channel.py

@@ -1,3 +1,5 @@
+# encoding:utf-8
+
 """
 wechat channel
 """

+ 3 - 1
config.py

@@ -1,3 +1,5 @@
+# encoding:utf-8
+
 import json
 import os
 from common.log import logger
@@ -25,7 +27,7 @@ def get_root():
 
 
 def read_file(path):
-    with open(path, 'r') as f:
+    with open(path, mode='r', encoding='utf-8') as f:
         return f.read()