{"repo": "anhen-1117/mathmodelpro", "files": {"backend/app/core/llm/__init__.py": {"b18a60a0a35ae98712995f5927a62a6baa02d670": {"t": 1786068483.1716566, "n": 1880, "h": "fde174b247ee451e", "c": "\"\"\"V1 LLM 桥接层 — 重新导出到新架构 infrastructure/llm.py\"\"\"\n\nfrom dataclasses import dataclass, field\nfrom app.infrastructure.llm import LLMAdapter, create_llm, LLMResponse as InfraResponse\nfrom app.config import AgentConfig\n\n\n# ── V1 兼容类型 ──────────────────────────────────────\n\n@dataclass\nclass Message:\n role: str\n content: str\n\n\nLLMResponse = InfraResponse # 直接复用\n\n\nclass BaseLLM:\n \"\"\"V1 LLM 基类兼容\"\"\"\n def __init__(self, config: AgentConfig):\n self._adapter = LLMAdapter(config)\n\n async def chat(self, messages: list):\n return await self._adapter.chat([{\"role\": m.role, \"content\": m.content} for m in messages] if isinstance(messages[0], Message) else messages)\n\n async def chat_stream(self, messages: list):\n async for chunk in self._adapter.chat_stream(messages):\n yield chunk\n\n @staticmethod\n def format_messages(system: str = \"\", user: str = \"\", history: list = None):\n msgs = []\n if system:\n msgs.append({\"role\": \"system\", \"content\": system})\n if history:\n msgs.extend(history)\n if user:\n msgs.append({\"role\": \"user\", \"content\": user})\n return msgs\n\n\n# ── V1 工厂兼容 ──────────────────────────────────────\n\nclass LLMFactory:\n @staticmethod\n def create(api_key=\"\", base_url=None, model=\"deepseek-chat\", api_type=\"openai\"):\n return LLMAdapter(AgentConfig(\n api_key=api_key, base_url=base_url or \"https://api.deepseek.com\",\n model_id=model, api_type=api_type,\n ))\n\n @staticmethod\n def create_from_config(config: dict):\n return LLMAdapter(AgentConfig(\n api_key=config.get(\"apiKey\", \"\"),\n base_url=config.get(\"baseUrl\", \"https://api.deepseek.com\"),\n model_id=config.get(\"modelId\", \"deepseek-chat\"),\n api_type=config.get(\"apiType\", \"openai\"),\n ))\n\nllm = None\n\n"}}}}