fix: encoding bug

This commit is contained in:
zhayujie
2022-12-18 14:03:34 +08:00
parent 4ce6de07f5
commit 06065853a9
5 changed files with 15 additions and 5 deletions

View File

@@ -39,7 +39,7 @@
### 3.运行环境 ### 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.如果是开发机本地调试,直接在项目根目录下执行: 1.如果是开发机本地调试,直接在项目根目录下执行:
``` ```bash
python3 app.py python3 app.py
``` ```
终端输出二维码后,使用微信进行扫码,当输出 "Start auto replying" 时表示自动回复程序已经成功运行了。 终端输出二维码后,使用微信进行扫码,当输出 "Start auto replying" 时表示自动回复程序已经成功运行了。
@@ -86,7 +86,7 @@ python3 app.py
2.如果是服务器部署则使用nohup命令在后台运行 2.如果是服务器部署则使用nohup命令在后台运行
``` ```bash
touch nohup.out # 首次运行需要新建日志文件 touch nohup.out # 首次运行需要新建日志文件
nohup python3 app.py & tail -f nohup.out # 后台运行程序并输出日志 nohup python3 app.py & tail -f nohup.out # 后台运行程序并输出日志
``` ```

2
app.py
View File

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

View File

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

View File

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

View File

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