| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- """
- agent67.core.config — 配置与常量
- """
- from __future__ import annotations
- import os
- import shutil
- BANNER = """
- ╔══════════════════════════════════════════════════════════╗
- ║ 🐑 lambda — 你的个人助理 ║
- ║ powered by lambdagent ║
- ╠══════════════════════════════════════════════════════════╣
- ║ ║
- ║ 我可以帮你: ║
- ║ 💻 执行终端命令 📁 管理文件 ║
- ║ 🌐 控制浏览器 🚀 启动/切换应用 ║
- ║ 📊 查询系统信息 📸 截取屏幕 ║
- ║ ║
- ║ 输入 'exit' 退出 | 'trace' 查看执行追踪 ║
- ╚══════════════════════════════════════════════════════════╝
- """
- WAKE_WORD = "lambda"
- # 后端类型常量
- BACKEND_CLAUDE_CODE = "claude_code"
- BACKEND_OLLAMA = "ollama"
- BACKEND_API = "api"
- def detect_backend() -> tuple[str, bool, str]:
- """
- 检测可用的 LLM 后端。
- 返回: (model_name, use_api, backend_type)
- - backend_type="ollama" → 本地 Ollama (Qwen2.5, GLM-4, Llama3 等)
- - backend_type="claude_code" → Claude Code CLI (Max Plan, 无需 API Key)
- - backend_type="api" → 云端 API (Anthropic/DashScope/OpenAI)
- 优先级: Ollama (本地) > Claude Code CLI > Anthropic API > DashScope > OpenAI
- """
- # 1. 检测 Ollama 本地模型
- try:
- from .ollama_lam import ollama_available
- models = ollama_available()
- if models:
- # 优先选中文模型
- preferred = ["qwen2.5:7b", "qwen2.5:14b", "glm4:9b", "llama3.1:8b"]
- selected = None
- for p in preferred:
- if p in models:
- selected = p
- break
- if not selected:
- selected = models[0]
- print("✅ 使用 Ollama 本地模型 ({})".format(selected))
- print(" 可用模型: {}".format(", ".join(models[:5])))
- return selected, False, BACKEND_OLLAMA
- except Exception:
- pass
- # 2. 检测 Claude Code CLI
- if shutil.which("claude"):
- print("✅ 使用 Claude Code Max Plan (无需 API Key)")
- print(" 模型: claude sonnet (通过 claude CLI)")
- return "sonnet", False, BACKEND_CLAUDE_CODE
- # 3. 回退到 API 模式
- if os.environ.get("ANTHROPIC_API_KEY"):
- model = "claude-sonnet-4-20250514"
- print("✅ 使用 Anthropic API ({})".format(model))
- return model, True, BACKEND_API
- elif os.environ.get("DASHSCOPE_API_KEY"):
- model = "qwen-max"
- print("✅ 使用 DashScope API ({})".format(model))
- return model, True, BACKEND_API
- elif os.environ.get("OPENAI_API_KEY"):
- model = "gpt-4o"
- print("✅ 使用 OpenAI API ({})".format(model))
- return model, True, BACKEND_API
- return "", False, ""
|