mirror of
https://github.com/farcasclaudiu/TradingAgents.git
synced 2026-06-29 07:01:17 +03:00
feat: add multi-provider LLM support with factory pattern
- Add tradingagents/llm_clients/ with unified factory pattern - Support OpenAI, Anthropic, Google, xAI, OpenRouter, Ollama, vLLM - Replace direct LLM imports in trading_graph.py with create_llm_client() - Handle provider-specific params (reasoning_effort, thinking_config)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from typing import Any, Optional
|
||||
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
|
||||
from .base_client import BaseLLMClient
|
||||
from .validators import validate_model
|
||||
|
||||
|
||||
class AnthropicClient(BaseLLMClient):
|
||||
"""Client for Anthropic Claude models."""
|
||||
|
||||
def __init__(self, model: str, base_url: Optional[str] = None, **kwargs):
|
||||
super().__init__(model, base_url, **kwargs)
|
||||
|
||||
def get_llm(self) -> Any:
|
||||
"""Return configured ChatAnthropic instance."""
|
||||
llm_kwargs = {
|
||||
"model": self.model,
|
||||
"max_tokens": self.kwargs.get("max_tokens", 4096),
|
||||
}
|
||||
|
||||
for key in ("timeout", "max_retries", "api_key"):
|
||||
if key in self.kwargs:
|
||||
llm_kwargs[key] = self.kwargs[key]
|
||||
|
||||
if "thinking_config" in self.kwargs:
|
||||
llm_kwargs["thinking"] = self.kwargs["thinking_config"]
|
||||
|
||||
return ChatAnthropic(**llm_kwargs)
|
||||
|
||||
def validate_model(self) -> bool:
|
||||
"""Validate model for Anthropic."""
|
||||
return validate_model("anthropic", self.model)
|
||||
Reference in New Issue
Block a user