Skip to content

Commit

Permalink
feat: support scen without app code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhayujie committed Jun 8, 2023
1 parent 165182c commit 94c0af3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions bot/linkai/link_ai_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,25 @@ def _chat(self, query, context, retry_count=0):
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}

Expand All @@ -60,7 +63,7 @@ def _chat(self, query, context, retry_count=0):
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:
Expand Down
2 changes: 1 addition & 1 deletion bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self):
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 = {}

Expand Down
5 changes: 4 additions & 1 deletion config-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
# 插件配置
"plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突
# 知识库平台配置
"use_linkai": False,
"linkai_api_key": "",
"linkai_app_code": ""
}
Expand Down

0 comments on commit 94c0af3

Please sign in to comment.