mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-11 23:35:25 -05:00
Compare commits
4 Commits
feat/mcp-b
...
fix/enable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdeefb8621 | ||
|
|
ba6d585170 | ||
|
|
90eac56525 | ||
|
|
75f8772f8a |
@@ -93,6 +93,18 @@ class ChatConfig(BaseSettings):
|
|||||||
description="Name of the prompt in Langfuse to fetch",
|
description="Name of the prompt in Langfuse to fetch",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Extended thinking configuration for Claude models
|
||||||
|
thinking_enabled: bool = Field(
|
||||||
|
default=True,
|
||||||
|
description="Enable extended thinking for Claude models via OpenRouter",
|
||||||
|
)
|
||||||
|
thinking_budget_tokens: int = Field(
|
||||||
|
default=10000,
|
||||||
|
ge=1000,
|
||||||
|
le=100000,
|
||||||
|
description="Maximum tokens for extended thinking (budget_tokens for Claude)",
|
||||||
|
)
|
||||||
|
|
||||||
@field_validator("api_key", mode="before")
|
@field_validator("api_key", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_api_key(cls, v):
|
def get_api_key(cls, v):
|
||||||
|
|||||||
@@ -80,6 +80,19 @@ settings = Settings()
|
|||||||
client = openai.AsyncOpenAI(api_key=config.api_key, base_url=config.base_url)
|
client = openai.AsyncOpenAI(api_key=config.api_key, base_url=config.base_url)
|
||||||
|
|
||||||
|
|
||||||
|
def _apply_thinking_config(extra_body: dict[str, Any], model: str) -> None:
|
||||||
|
"""Apply extended thinking configuration for Anthropic models via OpenRouter.
|
||||||
|
|
||||||
|
OpenRouter's reasoning API expects either:
|
||||||
|
- {"max_tokens": N} for explicit token budget
|
||||||
|
- {"effort": "high"} for automatic budget
|
||||||
|
|
||||||
|
See: https://openrouter.ai/docs/reasoning-tokens
|
||||||
|
"""
|
||||||
|
if config.thinking_enabled and "anthropic" in model.lower():
|
||||||
|
extra_body["reasoning"] = {"max_tokens": config.thinking_budget_tokens}
|
||||||
|
|
||||||
|
|
||||||
langfuse = get_client()
|
langfuse = get_client()
|
||||||
|
|
||||||
# Redis key prefix for tracking running long-running operations
|
# Redis key prefix for tracking running long-running operations
|
||||||
@@ -1066,6 +1079,9 @@ async def _stream_chat_chunks(
|
|||||||
:128
|
:128
|
||||||
] # OpenRouter limit
|
] # OpenRouter limit
|
||||||
|
|
||||||
|
# Enable extended thinking for Anthropic models via OpenRouter
|
||||||
|
_apply_thinking_config(extra_body, model)
|
||||||
|
|
||||||
api_call_start = time_module.perf_counter()
|
api_call_start = time_module.perf_counter()
|
||||||
stream = await client.chat.completions.create(
|
stream = await client.chat.completions.create(
|
||||||
model=model,
|
model=model,
|
||||||
@@ -1829,6 +1845,9 @@ async def _generate_llm_continuation(
|
|||||||
if session_id:
|
if session_id:
|
||||||
extra_body["session_id"] = session_id[:128]
|
extra_body["session_id"] = session_id[:128]
|
||||||
|
|
||||||
|
# Enable extended thinking for Anthropic models via OpenRouter
|
||||||
|
_apply_thinking_config(extra_body, config.model)
|
||||||
|
|
||||||
retry_count = 0
|
retry_count = 0
|
||||||
last_error: Exception | None = None
|
last_error: Exception | None = None
|
||||||
response = None
|
response = None
|
||||||
@@ -1959,6 +1978,9 @@ async def _generate_llm_continuation_with_streaming(
|
|||||||
if session_id:
|
if session_id:
|
||||||
extra_body["session_id"] = session_id[:128]
|
extra_body["session_id"] = session_id[:128]
|
||||||
|
|
||||||
|
# Enable extended thinking for Anthropic models via OpenRouter
|
||||||
|
_apply_thinking_config(extra_body, config.model)
|
||||||
|
|
||||||
# Make streaming LLM call (no tools - just text response)
|
# Make streaming LLM call (no tools - just text response)
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user