From 0f33591f4d5352d577c5ec4d49cbdce9ff224099 Mon Sep 17 00:00:00 2001 From: FuQuan233 Date: Mon, 24 Aug 2026 11:23:53 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89User-Agent=E6=94=AF=E6=8C=81=EF=BC=8C?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=9C=A8=E8=AF=B7=E6=B1=82API=E6=97=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEUser-Agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + nonebot_plugin_llmchat/config.py | 1 + nonebot_plugin_llmchat/conversation.py | 2 ++ 3 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 8a17624..4092e02 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ _✨ 支持多API预设、MCP协议、内置工具、联网搜索、视觉模型 | max_tokens | 否 | 2048 | 最大响应token数 | | temperature | 否 | 0.7 | 生成温度 | | proxy | 否 | 无 | 请求API时使用的HTTP代理 | +| user_agent | 否 | 无 | 请求API时使用的自定义User-Agent | | support_mcp | 否 | False | 是否支持MCP协议 | | support_image | 否 | False | 是否支持图片输入 | | stream | 否 | False | 是否启用流式响应;普通行完成后立即发送,三反引号内容框闭合后整体发送 | diff --git a/nonebot_plugin_llmchat/config.py b/nonebot_plugin_llmchat/config.py index 188e6e3..3e95664 100755 --- a/nonebot_plugin_llmchat/config.py +++ b/nonebot_plugin_llmchat/config.py @@ -11,6 +11,7 @@ class PresetConfig(BaseModel): max_tokens: int = Field(default=2048, description="最大响应token数") temperature: float = Field(default=0.7, description="生成温度(0-2]") proxy: str = Field(default="", description="HTTP代理服务器") + user_agent: str = Field(default="", description="请求API时使用的自定义User-Agent") support_mcp: bool = Field(default=False, description="是否支持MCP") support_image: bool = Field(default=False, description="是否支持图片输入") stream: bool = Field(default=False, description="是否使用流式响应") diff --git a/nonebot_plugin_llmchat/conversation.py b/nonebot_plugin_llmchat/conversation.py index 7645626..ed68236 100644 --- a/nonebot_plugin_llmchat/conversation.py +++ b/nonebot_plugin_llmchat/conversation.py @@ -67,6 +67,8 @@ class ConversationService: "api_key": preset.api_key, "timeout": self.config.request_timeout, } + if preset.user_agent: + options["default_headers"] = {"User-Agent": preset.user_agent} if preset.proxy: options["http_client"] = httpx.AsyncClient(proxy=preset.proxy) return AsyncOpenAI(**options)