From 1cff2521f422ec3bee1a8bdb0b64094e27b3e481 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Tue, 22 Aug 2023 11:09:01 +0800 Subject: [PATCH] fix: add web.py and linkai base url --- bot/linkai/link_ai_bot.py | 4 ++-- config.py | 3 ++- plugins/linkai/midjourney.py | 3 +-- requirements.txt | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bot/linkai/link_ai_bot.py b/bot/linkai/link_ai_bot.py index d90bcb0..c5aed0f 100644 --- a/bot/linkai/link_ai_bot.py +++ b/bot/linkai/link_ai_bot.py @@ -22,7 +22,6 @@ class LinkAIBot(Bot, OpenAIImage): def __init__(self): super().__init__() - self.base_url = "https://api.link-ai.chat/v1" self.sessions = SessionManager(ChatGPTSession, model=conf().get("model") or "gpt-3.5-turbo") def reply(self, query, context: Context = None) -> Reply: @@ -83,7 +82,8 @@ class LinkAIBot(Bot, OpenAIImage): headers = {"Authorization": "Bearer " + linkai_api_key} # do http request - res = requests.post(url=self.base_url + "/chat/completions", json=body, headers=headers, + base_url = conf().get("linkai_api_base", "https://api.link-ai.chat") + res = requests.post(url=base_url + "/v1/chat/completions", json=body, headers=headers, timeout=conf().get("request_timeout", 180)) if res.status_code == 200: # execute success diff --git a/config.py b/config.py index fb5b407..373dd42 100644 --- a/config.py +++ b/config.py @@ -112,7 +112,8 @@ available_setting = { # 知识库平台配置 "use_linkai": False, "linkai_api_key": "", - "linkai_app_code": "" + "linkai_app_code": "", + "linkai_api_base": "https://api.link-ai.chat" # linkAI服务地址,若国内无法访问或延迟较高可改为 https://api.link-ai.tech } diff --git a/plugins/linkai/midjourney.py b/plugins/linkai/midjourney.py index c6c6cfa..d7d0634 100644 --- a/plugins/linkai/midjourney.py +++ b/plugins/linkai/midjourney.py @@ -68,8 +68,7 @@ class MJTask: # midjourney bot class MJBot: def __init__(self, config): - self.base_url = "https://api.link-ai.chat/v1/img/midjourney" - + self.base_url = conf().get("linkai_api_base", "https://api.link-ai.chat") + "/v1/img/midjourney" self.headers = {"Authorization": "Bearer " + conf().get("linkai_api_key")} self.config = config self.tasks = {} diff --git a/requirements.txt b/requirements.txt index 7fec2c6..0863125 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ requests>=2.28.2 chardet>=5.1.0 Pillow pre-commit +web.py