From fef7d425b3ca83b3b8046021970e2a11dcf90865 Mon Sep 17 00:00:00 2001 From: jiechus <84175239+jiesou@users.noreply.github.com> Date: Thu, 22 Dec 2022 12:11:53 +0800 Subject: [PATCH] =?UTF-8?q?Openaichat=20=E9=99=90=E5=88=B6=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E9=95=BF=E5=BA=A6=EF=BC=8C=E5=B9=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=8E=B7=E5=8F=96=E5=B7=B2=E8=AE=B0=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AF=9D=E9=A2=98=20(#110)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 限制上下文长度,并支持获取已记录的聊天话题 * bump version * 过滤AI输出的开头空符 --- list.json | 8 ++++---- openaichat/main.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/list.json b/list.json index d3f57c6..a82081f 100644 --- a/list.json +++ b/list.json @@ -862,13 +862,13 @@ }, { "name": "openaichat", - "version": "1.1", + "version": "1.2", "section": "chat", "maintainer": "jiechus", - "size": "4.857 kb", + "size": "5.131 kb", "supported": true, - "des-short": "openaichat", - "des": "openaichat" + "des-short": "openaichat 使用 OpenAI Chat 聊天", + "des": "openaichat 使用 OpenAI Chat 聊天\n基于 text-davinci-003 模型,与 ChatGPT 的效果有些许不同\n代码参考了原先的 ChatGPT 插件" }, { "name": "copy_sticker_set", diff --git a/openaichat/main.py b/openaichat/main.py index 3a8b90e..35f9bec 100644 --- a/openaichat/main.py +++ b/openaichat/main.py @@ -1,5 +1,6 @@ import contextlib import threading +import re from collections import defaultdict @@ -22,7 +23,7 @@ async def get_chat_response(prompt: str) -> str: top_p=1, frequency_penalty=0.0, presence_penalty=0.6, - stop=[" Human:", " AI:"] + stop=["Human: ", "AI: "] ).choices[0].text @@ -54,6 +55,7 @@ def get_template() -> str: def formatted_response(prompt: str, message: str) -> str: if not get_template(): set_template(default_template) + message = re.sub(r'^\s+', r'', message) try: return get_template().format(prompt, message) except Exception: @@ -67,6 +69,7 @@ chat_bot_help = "使用 OpenAI Chat 聊天\n" \ "代码参考了原先的 ChatGPT 插件\n\n" \ "参数:\n\n- 问题:询问 ai\n" \ "- reset:重置聊天话题\n" \ + "- thread:获取已记录的聊天话题\n" \ "- set :设置 OpenAI API Key,获取 API Key: https://beta.openai.com/account/api-keys \n" \ "- del:删除 OpenAI API Key\n" \ "- template {set|get|reset}