Browse Source

feat: support scen without app code

master
zhayujie 1 year ago
parent
commit
94c0af3037
4 changed files with 15 additions and 8 deletions
  1. +9
    -6
      bot/linkai/link_ai_bot.py
  2. +1
    -1
      bridge/bridge.py
  3. +4
    -1
      config-template.json
  4. +1
    -0
      config.py

+ 9
- 6
bot/linkai/link_ai_bot.py View File

@@ -31,22 +31,25 @@ class LinkAIBot(Bot):
return Reply(ReplyType.ERROR, "请再问我一次吧") return Reply(ReplyType.ERROR, "请再问我一次吧")


try: try:
# load config
app_code = conf().get("linkai_app_code")
linkai_api_key = conf().get("linkai_api_key")

session_id = context["session_id"] session_id = context["session_id"]


session = self.sessions.session_query(query, session_id) session = self.sessions.session_query(query, session_id)


# remove system message # remove system message
if session.messages[0].get("role") == "system":
if app_code and session.messages[0].get("role") == "system":
session.messages.pop(0) 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}") logger.info(f"[LINKAI] query={query}, app_code={app_code}")


body = { body = {
"appCode": app_code, "appCode": app_code,
"messages": session.messages
"messages": session.messages,
"temperature": conf().get("temperature")
} }
headers = {"Authorization": "Bearer " + linkai_api_key} headers = {"Authorization": "Bearer " + linkai_api_key}


@@ -60,7 +63,7 @@ class LinkAIBot(Bot):
return Reply(ReplyType.ERROR, "请再问我一次吧") return Reply(ReplyType.ERROR, "请再问我一次吧")


elif res.get("code") == self.NO_QUOTA_CODE: 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, "提问太快啦,请休息一下再问我吧") return Reply(ReplyType.ERROR, "提问太快啦,请休息一下再问我吧")


else: else:


+ 1
- 1
bridge/bridge.py View File

@@ -23,7 +23,7 @@ class Bridge(object):
self.btype["chat"] = const.OPEN_AI self.btype["chat"] = const.OPEN_AI
if conf().get("use_azure_chatgpt", False): if conf().get("use_azure_chatgpt", False):
self.btype["chat"] = const.CHATGPTONAZURE 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.btype["chat"] = const.LINKAI
self.bots = {} self.bots = {}




+ 4
- 1
config-template.json View File

@@ -28,5 +28,8 @@
"conversation_max_tokens": 1000, "conversation_max_tokens": 1000,
"expires_in_seconds": 3600, "expires_in_seconds": 3600,
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。", "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": ""
} }

+ 1
- 0
config.py View File

@@ -100,6 +100,7 @@ available_setting = {
# 插件配置 # 插件配置
"plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突 "plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突
# 知识库平台配置 # 知识库平台配置
"use_linkai": False,
"linkai_api_key": "", "linkai_api_key": "",
"linkai_app_code": "" "linkai_app_code": ""
} }


Loading…
Cancel
Save