From 94c0af30370385734ed68a4a5e3c196c95bc37f3 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Thu, 8 Jun 2023 23:57:59 +0800 Subject: [PATCH] feat: support scen without app code --- bot/linkai/link_ai_bot.py | 15 +++++++++------ bridge/bridge.py | 2 +- config-template.json | 5 ++++- config.py | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bot/linkai/link_ai_bot.py b/bot/linkai/link_ai_bot.py index 023e62c..83b0fa7 100644 --- a/bot/linkai/link_ai_bot.py +++ b/bot/linkai/link_ai_bot.py @@ -31,22 +31,25 @@ class LinkAIBot(Bot): return Reply(ReplyType.ERROR, "请再问我一次吧") try: + # load config + app_code = conf().get("linkai_app_code") + linkai_api_key = conf().get("linkai_api_key") + session_id = context["session_id"] session = self.sessions.session_query(query, session_id) # remove system message - if session.messages[0].get("role") == "system": + if app_code and session.messages[0].get("role") == "system": session.messages.pop(0) - # load config - app_code = conf().get("linkai_app_code") - linkai_api_key = conf().get("linkai_api_key") + logger.info(f"[LINKAI] query={query}, app_code={app_code}") body = { "appCode": app_code, - "messages": session.messages + "messages": session.messages, + "temperature": conf().get("temperature") } headers = {"Authorization": "Bearer " + linkai_api_key} @@ -60,7 +63,7 @@ class LinkAIBot(Bot): return Reply(ReplyType.ERROR, "请再问我一次吧") elif res.get("code") == self.NO_QUOTA_CODE: - logger.exception(f"[LINKAI] please check your account quota, https://link-ai.chat/console/account") + logger.exception(f"[LINKAI] please check your account quota, https://chat.link-ai.tech/console/account") return Reply(ReplyType.ERROR, "提问太快啦,请休息一下再问我吧") else: diff --git a/bridge/bridge.py b/bridge/bridge.py index 119e855..d3fbd95 100644 --- a/bridge/bridge.py +++ b/bridge/bridge.py @@ -23,7 +23,7 @@ class Bridge(object): self.btype["chat"] = const.OPEN_AI if conf().get("use_azure_chatgpt", False): self.btype["chat"] = const.CHATGPTONAZURE - if conf().get("linkai_api_key") and conf().get("linkai_app_code"): + if conf().get("use_linkai") and conf().get("linkai_api_key"): self.btype["chat"] = const.LINKAI self.bots = {} diff --git a/config-template.json b/config-template.json index d179ff8..e2a6def 100644 --- a/config-template.json +++ b/config-template.json @@ -28,5 +28,8 @@ "conversation_max_tokens": 1000, "expires_in_seconds": 3600, "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。", - "subscribe_msg": "感谢您的关注!\n这里是ChatGPT,可以自由对话。\n支持语音对话。\n支持图片输入。\n支持图片输出,画字开头的消息将按要求创作图片。\n支持tool、角色扮演和文字冒险等丰富的插件。\n输入{trigger_prefix}#help 查看详细指令。" + "subscribe_msg": "感谢您的关注!\n这里是ChatGPT,可以自由对话。\n支持语音对话。\n支持图片输入。\n支持图片输出,画字开头的消息将按要求创作图片。\n支持tool、角色扮演和文字冒险等丰富的插件。\n输入{trigger_prefix}#help 查看详细指令。", + "use_linkai": false, + "linkai_api_key": "", + "linkai_app_code": "" } diff --git a/config.py b/config.py index 26b2f8a..4befe98 100644 --- a/config.py +++ b/config.py @@ -100,6 +100,7 @@ available_setting = { # 插件配置 "plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突 # 知识库平台配置 + "use_linkai": False, "linkai_api_key": "", "linkai_app_code": "" }