mirror of
https://github.com/farcasclaudiu/TradingAgents.git
synced 2026-06-22 09:01:24 +03:00
d4dadb82fc
Models added: - OpenAI: GPT-5.2, GPT-5.1, GPT-5, GPT-5 Mini, GPT-5 Nano, GPT-4.1 - Anthropic: Claude Opus 4.5/4.1, Claude Sonnet 4.5/4, Claude Haiku 4.5 - Google: Gemini 3 Pro/Flash, Gemini 2.5 Flash/Flash Lite - xAI: Grok 4, Grok 4.1 Fast (Reasoning/Non-Reasoning) Configs updated: - Add unified thinking_level for Gemini (maps to thinking_level for Gemini 3, thinking_budget for Gemini 2.5; handles Pro's lack of "minimal" support) - Add OpenAI reasoning_effort configuration - Add NormalizedChatGoogleGenerativeAI for consistent response handling Fixes: - Fix Bull/Bear researcher display truncation - Replace ChromaDB with BM25 for memory retrieval
66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
from typing import Any, Optional
|
|
|
|
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
|
from .base_client import BaseLLMClient
|
|
from .validators import validate_model
|
|
|
|
|
|
class NormalizedChatGoogleGenerativeAI(ChatGoogleGenerativeAI):
|
|
"""ChatGoogleGenerativeAI with normalized content output.
|
|
|
|
Gemini 3 models return content as list: [{'type': 'text', 'text': '...'}]
|
|
This normalizes to string for consistent downstream handling.
|
|
"""
|
|
|
|
def _normalize_content(self, response):
|
|
content = response.content
|
|
if isinstance(content, list):
|
|
texts = [
|
|
item.get("text", "") if isinstance(item, dict) and item.get("type") == "text"
|
|
else item if isinstance(item, str) else ""
|
|
for item in content
|
|
]
|
|
response.content = "\n".join(t for t in texts if t)
|
|
return response
|
|
|
|
def invoke(self, input, config=None, **kwargs):
|
|
return self._normalize_content(super().invoke(input, config, **kwargs))
|
|
|
|
|
|
class GoogleClient(BaseLLMClient):
|
|
"""Client for Google Gemini 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 ChatGoogleGenerativeAI instance."""
|
|
llm_kwargs = {"model": self.model}
|
|
|
|
for key in ("timeout", "max_retries", "google_api_key"):
|
|
if key in self.kwargs:
|
|
llm_kwargs[key] = self.kwargs[key]
|
|
|
|
# Map thinking_level to appropriate API param based on model
|
|
# Gemini 3 Pro: low, high
|
|
# Gemini 3 Flash: minimal, low, medium, high
|
|
# Gemini 2.5: thinking_budget (0=disable, -1=dynamic)
|
|
thinking_level = self.kwargs.get("thinking_level")
|
|
if thinking_level:
|
|
model_lower = self.model.lower()
|
|
if "gemini-3" in model_lower:
|
|
# Gemini 3 Pro doesn't support "minimal", use "low" instead
|
|
if "pro" in model_lower and thinking_level == "minimal":
|
|
thinking_level = "low"
|
|
llm_kwargs["thinking_level"] = thinking_level
|
|
else:
|
|
# Gemini 2.5: map to thinking_budget
|
|
llm_kwargs["thinking_budget"] = -1 if thinking_level == "high" else 0
|
|
|
|
return NormalizedChatGoogleGenerativeAI(**llm_kwargs)
|
|
|
|
def validate_model(self) -> bool:
|
|
"""Validate model for Google."""
|
|
return validate_model("google", self.model)
|