feat: add Anthropic API provider support and missing env vars
- Add LLM_PROVIDER env var (openai/anthropic) to switch cloud backend - Use ChatAnthropic for anthropic provider with custom base_url - Add CONTEXT_MAX_TOKENS, CONTEXT_KEEP_RECENT, SESSIONS_DIR, HISTORY_MAX_SNAPSHOTS to .env and .env.example - Add langchain-anthropic dependency to requirements.txt Note: E2E testing blocked — the configured MiniMax API key (sk-cp-...) returns 401 across all endpoints (Anthropic and OpenAI). The API key may be expired or lack text-generation model access.
This commit is contained in:
+12
-1
@@ -1,4 +1,4 @@
|
||||
"""大语言模型工厂:支持 OpenAI 兼容的云端 API 和本地 Ollama。"""
|
||||
"""大语言模型工厂:支持 OpenAI 兼容的云端 API、Anthropic 兼容 API 和本地 Ollama。"""
|
||||
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
@@ -13,6 +13,17 @@ def get_llm():
|
||||
|
||||
model = os.getenv("LOCAL_LLM_MODEL", "qwen2.5-coder:7b")
|
||||
return ChatOllama(model=model, temperature=0.1)
|
||||
|
||||
provider = os.getenv("LLM_PROVIDER", "openai")
|
||||
if provider == "anthropic":
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
|
||||
return ChatAnthropic(
|
||||
model=os.getenv("LLM_MODEL", "claude-sonnet-4-6"),
|
||||
api_key=os.getenv("OPENAI_API_KEY"),
|
||||
base_url=os.getenv("OPENAI_BASE_URL", "https://api.anthropic.com"),
|
||||
temperature=0.1,
|
||||
)
|
||||
else:
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
|
||||
Reference in New Issue
Block a user