Rebase onto upstream (a4d95fd) #12

Closed
wylab wants to merge 144 commits from rebase-onto-upstream into main
Showing only changes of commit b1ffc65732 - Show all commits
+24
View File
@@ -5,10 +5,13 @@ which require Authorization: Bearer header instead of x-api-key.
""" """
import json import json
import logging
from typing import Any from typing import Any
import httpx import httpx
logger = logging.getLogger(__name__)
from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest from nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequest
from nanobot.providers.oauth_utils import get_auth_headers, get_claude_code_system_prefix from nanobot.providers.oauth_utils import get_auth_headers, get_claude_code_system_prefix
@@ -223,6 +226,12 @@ class AnthropicOAuthProvider(LLMProvider):
if tools: if tools:
payload["tools"] = tools payload["tools"] = tools
logger.info(
"Anthropic request: model=%s max_tokens=%d thinking=%s",
payload.get("model"), payload.get("max_tokens"),
payload.get("thinking", "disabled"),
)
response = await client.post( response = await client.post(
self._get_api_url(), self._get_api_url(),
headers=self._get_headers(), headers=self._get_headers(),
@@ -304,6 +313,21 @@ class AnthropicOAuthProvider(LLMProvider):
), ),
} }
# Log usage and thinking info
if thinking_blocks:
thinking_chars = sum(len(b.get("thinking", "")) for b in thinking_blocks)
logger.info(
"Anthropic response: %d thinking block(s) (%d chars), "
"input=%d output=%d tokens",
len(thinking_blocks), thinking_chars,
usage.get("prompt_tokens", 0), usage.get("completion_tokens", 0),
)
else:
logger.info(
"Anthropic response: no thinking blocks, input=%d output=%d tokens",
usage.get("prompt_tokens", 0), usage.get("completion_tokens", 0),
)
return LLMResponse( return LLMResponse(
content=text_content or None, content=text_content or None,
tool_calls=tool_calls, tool_calls=tool_calls,