| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- """
- agent67.core.config — 配置与常量
- """
- from __future__ import annotations
- import os
- import shutil
- BANNER = """
- ╔══════════════════════════════════════════════════════════╗
- ║ 🐂 lambda v3 — Java/Python 全栈 + ML 专家 ║
- ║ powered by lambdagent (42 tools + PaaS services) ║
- ╠══════════════════════════════════════════════════════════╣
- ║ ║
- ║ 📁 文件/代码编辑 🔍 代码搜索 (6种语言) ║
- ║ 💻 Shell + Git 🌐 Web 搜索/获取 ║
- ║ 📓 Notebook/文档生成 🧠 知识库 + OCR ║
- ║ 🧪 自动化测试 💾 持久记忆 + 学习 ║
- ║ 📋 任务/调度/通知 🖥️ 系统/浏览器/截屏 ║
- ║ ║
- ║ exit 退出 | trace 追踪 | stats 统计 | history 历史 ║
- ╚══════════════════════════════════════════════════════════╝
- """
- 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 大模型 (≥30B, 首选)
- - backend_type="claude_code" → Claude Code CLI (Max Plan, 无需 API Key)
- - backend_type="api" → 云端 API (Anthropic/DashScope/OpenAI)
- - backend_type="ollama" → 本地 Ollama 小模型 (fallback)
- 优先级: Ollama 大模型(≥30B) > Claude Code > API > Ollama 小模型
- """
- # 强模型名单(≥30B 参数,本地运行优先)
- STRONG_MODELS = [
- "qwen2.5-coder:32b", "qwen2.5:32b", "qwen2.5:72b",
- "deepseek-coder-v2:33b", "codellama:34b",
- "llama3.1:70b", "mixtral:8x7b",
- ]
- # 弱模型名单(fallback)
- WEAK_MODELS = [
- "qwen2.5-coder:7b", "qwen2.5:14b", "qwen2.5:7b",
- "glm4:9b", "llama3.1:8b", "deepseek-coder:6.7b",
- ]
- # 1. 检测 Ollama 大模型(本地、隐私、免费、够强)
- try:
- from .ollama_lam import ollama_available
- models = ollama_available()
- if models:
- for m in STRONG_MODELS:
- if m in models:
- print("✅ 使用 Ollama 本地大模型 ({})".format(m))
- print(" 可用模型: {}".format(", ".join(models[:5])))
- return m, 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
- # 4. Ollama 小模型 (fallback)
- try:
- from .ollama_lam import ollama_available
- models = ollama_available()
- if models:
- selected = None
- for m in WEAK_MODELS:
- if m in models:
- selected = m
- break
- if not selected:
- selected = models[0]
- print("⚠️ 使用 Ollama 小模型 ({}) — 能力有限".format(selected))
- print(" 可用模型: {}".format(", ".join(models[:5])))
- return selected, False, BACKEND_OLLAMA
- except Exception:
- pass
- return "", False, ""
|