Skip to content

Commit f7e2565

Browse files
CopilotBukeLy
andauthored
Add dedicated VLM model configuration and wire it through multi-tenant VLM creation (#10)
* Initial plan * 拆分VLM模型配置 Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> * 完善VLM配置独立化 Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> * 优化VLM密钥回退一致性 Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com>
1 parent c512812 commit f7e2565

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ LLM_API_KEY="your_llm_api_key_here"
1515
LLM_BASE_URL="https://ark.ap-southeast.bytepluses.com/api/v3"
1616
# 使用的模型名称
1717
LLM_MODEL=seed-1-6-250615
18+
# 用于多模态图片理解的 VLM 模型(必填,独立于 LLM_MODEL)
19+
VLM_MODEL=seed-1-6-250615
20+
# 可选:VLM 使用独立的密钥/域名(未设置时复用 LLM 配置)
21+
# VLM_API_KEY="your_vlm_api_key_here"
22+
# VLM_BASE_URL="https://api.example.com/v1"
1823
# LLM 供应商标识(ark/openai/claude)
1924
LLM_PROVIDER=ark
2025
# VLM 图片理解 API 超时时间(秒,默认 120 秒)
@@ -318,4 +323,3 @@ TZ=Asia/Shanghai
318323

319324
# --- Python 配置 ---
320325
PYTHONUNBUFFERED=1 # 禁用输出缓冲,实时查看日志
321-

src/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
重构原因: 统一配置管理,从服务商导向改为功能导向命名
99
"""
1010

11-
import os
1211
from typing import Optional
1312
from pydantic import Field
1413
from pydantic_settings import BaseSettings
@@ -22,6 +21,9 @@ class LLMConfig(BaseSettings):
2221
api_key: str = Field(..., description="LLM API Key")
2322
base_url: str = Field(..., description="LLM API Base URL")
2423
model: str = Field(default="seed-1-6-250615", description="LLM Model Name")
24+
vlm_model: str = Field(..., description="VLM Model Name", alias="VLM_MODEL")
25+
vlm_api_key: Optional[str] = Field(default=None, description="VLM API Key", alias="VLM_API_KEY")
26+
vlm_base_url: Optional[str] = Field(default=None, description="VLM API Base URL", alias="VLM_BASE_URL")
2527
vlm_timeout: int = Field(default=120, description="VLM Image Understanding Timeout (seconds)")
2628
timeout: int = Field(default=60, description="General LLM Timeout (seconds)")
2729

src/multi_tenant.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ def __init__(
4848
self._creation_locks: defaultdict = defaultdict(asyncio.Lock)
4949

5050
# 共享配置(从集中配置管理读取)
51-
self.ark_api_key = config.llm.api_key
52-
self.ark_base_url = config.llm.base_url
53-
self.ark_model = config.llm.model
51+
self.llm_api_key = config.llm.api_key
52+
self.llm_base_url = config.llm.base_url
53+
self.llm_model = config.llm.model
54+
self.vlm_model = config.llm.vlm_model
55+
self.vlm_api_key = config.llm.vlm_api_key or config.llm.api_key
56+
self.vlm_base_url = config.llm.vlm_base_url or config.llm.base_url
5457

5558
self.sf_api_key = config.embedding.api_key
5659
self.sf_base_url = config.embedding.base_url
@@ -85,9 +88,9 @@ def _create_llm_func(self, llm_config: Dict):
8588
import asyncio
8689

8790
# 从配置中提取参数(支持租户覆盖)
88-
model = llm_config.get("model", self.ark_model)
89-
api_key = llm_config.get("api_key", self.ark_api_key)
90-
base_url = llm_config.get("base_url", self.ark_base_url)
91+
model = llm_config.get("model", self.llm_model)
92+
api_key = llm_config.get("api_key", self.llm_api_key)
93+
base_url = llm_config.get("base_url", self.llm_base_url)
9194

9295
# 获取 RateLimiter 参数(租户可配置)
9396
# 注意:这里的 max_async 是 RateLimiter 的并发控制,不是 LightRAG 的
@@ -278,9 +281,9 @@ def _create_vision_model_func(self, llm_config: Dict):
278281
import aiohttp
279282

280283
# 从配置中提取参数(支持租户覆盖)
281-
model = llm_config.get("model", self.ark_model)
282-
api_key = llm_config.get("api_key", self.ark_api_key)
283-
base_url = llm_config.get("base_url", self.ark_base_url)
284+
model = llm_config.get("vlm_model", self.vlm_model)
285+
api_key = llm_config.get("vlm_api_key") or llm_config.get("api_key") or self.vlm_api_key
286+
base_url = llm_config.get("vlm_base_url") or llm_config.get("base_url") or self.vlm_base_url
284287
vlm_timeout = llm_config.get("vlm_timeout", self.vlm_timeout)
285288

286289
# 获取速率限制器(VLM 使用 LLM 的限制)
@@ -552,4 +555,4 @@ async def get_tenant_lightrag(tenant_id: str) -> LightRAG:
552555
LightRAG: 该租户的实例
553556
"""
554557
manager = get_multi_tenant_manager()
555-
return await manager.get_instance(tenant_id)
558+
return await manager.get_instance(tenant_id)

src/tenant_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ def _merge_llm_config(self, tenant_config: Optional[TenantConfigModel]) -> Dict[
301301
"""
302302
base = {
303303
"model": config.llm.model,
304+
"vlm_model": config.llm.vlm_model,
305+
"vlm_api_key": config.llm.vlm_api_key,
306+
"vlm_base_url": config.llm.vlm_base_url,
304307
"api_key": config.llm.api_key,
305308
"base_url": config.llm.base_url,
306309
"timeout": config.llm.timeout,

0 commit comments

Comments
 (0)