Compare commits

..

3 Commits

Author SHA1 Message Date
ef5022ff64 prompt and homepage notice tuning. 2023-04-08 10:42:14 +08:00
c4800ddf55 start server with waitress 2023-04-08 10:41:13 +08:00
6dcf5d757a return error message when request fail 2023-04-08 10:40:48 +08:00
4 changed files with 15 additions and 9 deletions

View File

@ -6,4 +6,5 @@ RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
RUN python3 -m pip install --upgrade pip && pip3 install --upgrade setuptools
COPY . /web-gpt
RUN pip3 install -r /web-gpt/requirements.txt
CMD cd /web-gpt && flask --app=project run --host=0.0.0.0
RUN pip3 install waitress
CMD cd /web-gpt && waitress-serve --listen 0.0.0.0:5000 project:app

View File

@ -1,7 +1,7 @@
[app]
NAME=APP_NAME
SECRET_KEY=SOME_RANDOM_STRING
HOMEPAGE_NOTICE=1. 此网站基于openAI的API提供服务\n2. 为了限制滥用,注册后需要管理员激活才能使用\n3. 为了支持多轮对话,历史聊天会保存在服务端\n4. 网站不做关键词过滤,但请不要违反相关法律
HOMEPAGE_NOTICE=1. 此网站基于openAI的API提供服务\n2. 为了限制滥用,注册后需要管理员激活才能使用\n3. 为了支持多轮对话,历史聊天会保存在服务端\n4. 网站不做关键词过滤,但请不要违反相关法律\n5. GPT生成的任何内容不保证准确性请自行甄别
SQLALCHEMY_DATABASE_URI=sqlite:///sqlite.db
#SQLALCHEMY_DATABASE_URI=mysql://username:password@server/db
@ -11,4 +11,4 @@ PROXY=http://127.0.0.1:7890
[openai]
API_KEY=
MODEL_NAME=gpt-3.5-turbo
PROMPT=You are a helpful assistant
PROMPT=你是一个有用的人工智能助理,你尽力确保回答的准确性,避免给出误导信息。

View File

@ -45,3 +45,6 @@ def create_app():
app.register_blueprint(main_blueprint)
return app
app = create_app()

View File

@ -95,12 +95,14 @@ def chat_post():
else:
messages.append(
{"role": "user", "content": chat.request})
openai_resp = openai.ChatCompletion.create(
model=current_app.config['OPENAI_MODEL_NAME'],
messages=messages
)
msg_resp = openai_resp['choices'][0]['message']['content']
try:
openai_resp = openai.ChatCompletion.create(
model=current_app.config['OPENAI_MODEL_NAME'],
messages=messages
)
msg_resp = openai_resp['choices'][0]['message']['content']
except:
msg_resp = "请求错误,请尝试重发。如果持续错误,请联系管理员检查。"
if msg_resp:
response = {"message": msg_resp, "status": "success"}
else: