Make LLM timeout configurable via AgentConfig (#37)
This commit is contained in:
@@ -28,6 +28,7 @@ class AgentConfig(BaseModel):
|
||||
temperature: float = Field(default=0.7, ge=0.0, le=2.0)
|
||||
max_tokens: Optional[int] = Field(default=None, description="Max tokens per response")
|
||||
max_iterations: int = Field(default=10, description="Max iterations per agent task")
|
||||
timeout: float = Field(default=120.0, description="HTTP timeout in seconds")
|
||||
|
||||
# Provider configuration
|
||||
provider: str = Field(default="minimax", description="LLM provider: minimax, openai, anthropic")
|
||||
|
||||
@@ -27,6 +27,7 @@ class LLMClient:
|
||||
model: str = "MiniMax/MiniMax-M2.1",
|
||||
base_url: Optional[str] = None,
|
||||
max_retries: int = 3,
|
||||
timeout: float = 120.0,
|
||||
):
|
||||
"""Initialize LLM client.
|
||||
|
||||
@@ -40,6 +41,7 @@ class LLMClient:
|
||||
self.api_key = api_key or os.environ.get("MINIMAX_API_KEY") or os.environ.get("OPENAI_API_KEY")
|
||||
self.provider = provider
|
||||
self.model = model
|
||||
self.timeout = timeout
|
||||
|
||||
# Normalize model name for MiniMax
|
||||
if provider == "minimax":
|
||||
@@ -57,7 +59,7 @@ class LLMClient:
|
||||
self.base_url = "https://api.openai.com/v1"
|
||||
|
||||
# Async client
|
||||
self._async_client = httpx.AsyncClient(timeout=120.0)
|
||||
self._async_client = httpx.AsyncClient(timeout=self.timeout)
|
||||
|
||||
# Initialize retry handler
|
||||
retry_config = RetryConfig(
|
||||
@@ -237,7 +239,7 @@ class LLMClient:
|
||||
f"{self.base_url}/v1/messages",
|
||||
headers={**headers, "Content-Type": "application/json"},
|
||||
json=payload,
|
||||
timeout=120,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
@@ -288,7 +290,7 @@ class LLMClient:
|
||||
f"{self.base_url}/chat/completions",
|
||||
headers=headers,
|
||||
json=payload,
|
||||
timeout=120,
|
||||
timeout=self.timeout,
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
@@ -307,4 +309,5 @@ def get_llm_client(config: Optional[Any] = None) -> LLMClient:
|
||||
api_key=cfg.agent.api_key,
|
||||
provider=cfg.agent.provider,
|
||||
model=cfg.agent.model,
|
||||
timeout=cfg.agent.timeout,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user