mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-04 08:28:36 +00:00
fix(providers): use canonical OpenRouter app URL
This commit is contained in:
parent
55405f6cd6
commit
7f3de6ea3e
@ -14,14 +14,10 @@ from typing import Any
|
||||
import httpx
|
||||
from loguru import logger
|
||||
|
||||
from nanobot.providers.openrouter_attribution import OPENROUTER_ATTRIBUTION_HEADERS
|
||||
from nanobot.providers.registry import find_by_name
|
||||
from nanobot.utils.helpers import detect_image_mime
|
||||
|
||||
_OPENROUTER_ATTRIBUTION_HEADERS = {
|
||||
"HTTP-Referer": "https://github.com/HKUDS/nanobot",
|
||||
"X-OpenRouter-Title": "nanobot",
|
||||
"X-OpenRouter-Categories": "cli-agent,personal-agent",
|
||||
}
|
||||
_DEFAULT_TIMEOUT_S = 120.0
|
||||
_AIHUBMIX_TIMEOUT_S = 300.0
|
||||
_AIHUBMIX_ASPECT_RATIO_SIZES = {
|
||||
@ -305,7 +301,7 @@ class OpenRouterImageGenerationClient(ImageGenerationProvider):
|
||||
headers = {
|
||||
"Authorization": f"Bearer {self.api_key}",
|
||||
"Content-Type": "application/json",
|
||||
**_OPENROUTER_ATTRIBUTION_HEADERS,
|
||||
**OPENROUTER_ATTRIBUTION_HEADERS,
|
||||
**self.extra_headers,
|
||||
}
|
||||
url = f"{self.api_base}/chat/completions"
|
||||
|
||||
@ -35,6 +35,7 @@ from nanobot.providers.openai_responses import (
|
||||
convert_tools,
|
||||
parse_response_output,
|
||||
)
|
||||
from nanobot.providers.openrouter_attribution import OPENROUTER_ATTRIBUTION_HEADERS
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from openai import AsyncOpenAI as AsyncOpenAIType
|
||||
@ -54,11 +55,6 @@ _ALNUM = string.ascii_letters + string.digits
|
||||
|
||||
_STANDARD_TC_KEYS = frozenset({"id", "type", "index", "function"})
|
||||
_STANDARD_FN_KEYS = frozenset({"name", "arguments"})
|
||||
_DEFAULT_OPENROUTER_HEADERS = {
|
||||
"HTTP-Referer": "https://github.com/HKUDS/nanobot",
|
||||
"X-OpenRouter-Title": "nanobot",
|
||||
"X-OpenRouter-Categories": "cli-agent,personal-agent",
|
||||
}
|
||||
_KIMI_K3_MODEL = "kimi-k3"
|
||||
_KIMI_THINKING_MODELS: frozenset[str] = frozenset({
|
||||
"kimi-k2.5",
|
||||
@ -450,7 +446,7 @@ class OpenAICompatProvider(LLMProvider):
|
||||
self._effective_base = effective_base
|
||||
self._default_headers = {"x-session-affinity": uuid.uuid4().hex}
|
||||
if _uses_openrouter_attribution(spec, effective_base):
|
||||
self._default_headers.update(_DEFAULT_OPENROUTER_HEADERS)
|
||||
self._default_headers.update(OPENROUTER_ATTRIBUTION_HEADERS)
|
||||
if extra_headers:
|
||||
self._default_headers.update(extra_headers)
|
||||
self._api_key_for_client = api_key or "no-key"
|
||||
|
||||
7
nanobot/providers/openrouter_attribution.py
Normal file
7
nanobot/providers/openrouter_attribution.py
Normal file
@ -0,0 +1,7 @@
|
||||
"""Shared OpenRouter app attribution headers."""
|
||||
|
||||
OPENROUTER_ATTRIBUTION_HEADERS = {
|
||||
"HTTP-Referer": "https://nanobot.wiki",
|
||||
"X-OpenRouter-Title": "nanobot",
|
||||
"X-OpenRouter-Categories": "cli-agent,personal-agent",
|
||||
}
|
||||
@ -142,6 +142,9 @@ async def test_openrouter_image_generation_payload_and_response(tmp_path: Path)
|
||||
call = fake.calls[0]
|
||||
assert call["url"] == "https://openrouter.ai/api/v1/chat/completions"
|
||||
assert call["headers"]["Authorization"] == "Bearer sk-or-test"
|
||||
assert call["headers"]["HTTP-Referer"] == "https://nanobot.wiki"
|
||||
assert call["headers"]["X-OpenRouter-Title"] == "nanobot"
|
||||
assert call["headers"]["X-OpenRouter-Categories"] == "cli-agent,personal-agent"
|
||||
assert call["headers"]["X-Test"] == "1"
|
||||
body = call["json"]
|
||||
assert body["modalities"] == ["image", "text"]
|
||||
|
||||
@ -485,7 +485,7 @@ async def test_openrouter_sets_default_attribution_headers() -> None:
|
||||
await provider._ensure_client()
|
||||
|
||||
headers = mock_client_cls.call_args.kwargs["default_headers"]
|
||||
assert headers["HTTP-Referer"] == "https://github.com/HKUDS/nanobot"
|
||||
assert headers["HTTP-Referer"] == "https://nanobot.wiki"
|
||||
assert headers["X-OpenRouter-Title"] == "nanobot"
|
||||
assert headers["X-OpenRouter-Categories"] == "cli-agent,personal-agent"
|
||||
assert "x-session-affinity" in headers
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user