| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- """
- agent67.core.config — 配置与常量
- """
- from __future__ import annotations
- import os
- import shutil
- BANNER = """
- ╔══════════════════════════════════════════════════════════╗
- ║ 🐑 lambda v2 — 个人助理 + 编程助手 ║
- ║ powered by lambdagent (21 built-in tools) ║
- ╠══════════════════════════════════════════════════════════╣
- ║ ║
- ║ 📁 文件读写编辑 🔍 代码搜索 ║
- ║ 💻 Shell 执行 🔀 Git 工作流 ║
- ║ 🌐 Web 搜索/获取 📓 Notebook 编辑 ║
- ║ 🚀 应用/浏览器控制 📊 系统信息/截屏 ║
- ║ 📋 任务管理 🧪 自动化测试 ║
- ║ ║
- ║ 输入 'exit' 退出 | 'trace' 追踪 | 'stats' 统计 ║
- ╚══════════════════════════════════════════════════════════╝
- """
- 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="claude_code" → Claude Code CLI (Max Plan, 无需 API Key, 最强)
- - backend_type="api" → 云端 API (Anthropic/DashScope/OpenAI)
- - backend_type="ollama" → 本地 Ollama (Qwen2.5, GLM-4 等, 能力较弱)
- 优先级: Claude Code CLI > API > Ollama
- (Claude Code 能力最强且免费,优先使用)
- """
- # 1. 检测 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
- # 2. 云端 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
- # 3. Ollama 本地模型 (fallback, 能力较弱)
- try:
- from .ollama_lam import ollama_available
- models = ollama_available()
- if models:
- preferred = ["qwen2.5:32b", "qwen2.5:14b", "glm4:9b", "qwen2.5:7b", "llama3.1:8b"]
- selected = None
- for p in preferred:
- if p in models:
- selected = p
- break
- if not selected:
- selected = models[0]
- print("⚠️ 使用 Ollama 本地模型 ({}) — 能力有限,推荐安装 Claude Code".format(selected))
- print(" 可用模型: {}".format(", ".join(models[:5])))
- return selected, False, BACKEND_OLLAMA
- except Exception:
- pass
- return "", False, ""
|