mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-18 12:40:06 +08:00
fix: gemini support api base
This commit is contained in:
@@ -32,6 +32,19 @@ class GoogleGeminiBot(Bot):
|
||||
self.model = conf().get("model") or "gemini-pro"
|
||||
if self.model == "gemini":
|
||||
self.model = "gemini-pro"
|
||||
|
||||
# 支持自定义API base地址,复用open_ai_api_base配置
|
||||
self.api_base = conf().get("open_ai_api_base", "").strip()
|
||||
if self.api_base:
|
||||
# 移除末尾的斜杠
|
||||
self.api_base = self.api_base.rstrip('/')
|
||||
# 如果配置的是OpenAI的地址,则使用默认的Gemini地址
|
||||
if "api.openai.com" in self.api_base or not self.api_base:
|
||||
self.api_base = "https://generativelanguage.googleapis.com"
|
||||
logger.info(f"[Gemini] Using custom API base: {self.api_base}")
|
||||
else:
|
||||
self.api_base = "https://generativelanguage.googleapis.com"
|
||||
|
||||
def reply(self, query, context: Context = None) -> Reply:
|
||||
try:
|
||||
if context.type != ContextType.TEXT:
|
||||
@@ -245,7 +258,7 @@ class GoogleGeminiBot(Bot):
|
||||
logger.info(f"[Gemini] Added {len(tools)} tools to request")
|
||||
|
||||
# Make REST API call
|
||||
base_url = "https://generativelanguage.googleapis.com/v1beta"
|
||||
base_url = f"{self.api_base}/v1beta"
|
||||
endpoint = f"{base_url}/models/{model_name}:generateContent"
|
||||
if stream:
|
||||
endpoint = f"{base_url}/models/{model_name}:streamGenerateContent?alt=sse"
|
||||
|
||||
@@ -212,6 +212,14 @@ class Config(dict):
|
||||
return super().__setitem__(key, value)
|
||||
|
||||
def get(self, key, default=None):
|
||||
# 跳过以下划线开头的注释字段
|
||||
if key.startswith("_"):
|
||||
return super().get(key, default)
|
||||
|
||||
# 如果key不在available_setting中,直接返回default
|
||||
if key not in available_setting:
|
||||
return super().get(key, default)
|
||||
|
||||
try:
|
||||
return self[key]
|
||||
except KeyError as e:
|
||||
|
||||
@@ -19,14 +19,9 @@ dulwich
|
||||
web.py
|
||||
wechatpy
|
||||
|
||||
# chatgpt-tool-hub plugin
|
||||
chatgpt_tool_hub==0.5.0
|
||||
|
||||
# xunfei spark
|
||||
websocket-client==1.2.0
|
||||
|
||||
# claude bot
|
||||
curl_cffi
|
||||
|
||||
# claude API
|
||||
anthropic==0.25.0
|
||||
|
||||
Reference in New Issue
Block a user