mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
feat(providers): expose Tsubasa in the dashboard and endpoint catalog
This commit is contained in:
parent
82bcc602c3
commit
3839daa7d3
7 changed files with 215 additions and 21 deletions
|
|
@ -2227,6 +2227,13 @@
|
|||
"interactions": true
|
||||
}
|
||||
},
|
||||
"tsubasa": {
|
||||
"display_name": "Tsubasa (`tsubasa`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/tsubasa",
|
||||
"endpoints": {
|
||||
"chat_completions": true
|
||||
}
|
||||
},
|
||||
"v0": {
|
||||
"display_name": "V0 (`v0`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/v0",
|
||||
|
|
|
|||
|
|
@ -3207,6 +3207,34 @@
|
|||
],
|
||||
"default_model_placeholder": "gpt-3.5-turbo"
|
||||
},
|
||||
{
|
||||
"provider": "Tsubasa",
|
||||
"provider_display_name": "Tsubasa",
|
||||
"litellm_provider": "tsubasa",
|
||||
"credential_fields": [
|
||||
{
|
||||
"key": "api_key",
|
||||
"label": "API Key",
|
||||
"placeholder": null,
|
||||
"tooltip": "Your Tsubasa API key",
|
||||
"required": true,
|
||||
"field_type": "password",
|
||||
"options": null,
|
||||
"default_value": null
|
||||
},
|
||||
{
|
||||
"key": "api_base",
|
||||
"label": "API Base",
|
||||
"placeholder": "https://api.tsubasa.sh/v1",
|
||||
"tooltip": "Optional: override the Tsubasa API base URL",
|
||||
"required": false,
|
||||
"field_type": "text",
|
||||
"options": null,
|
||||
"default_value": "https://api.tsubasa.sh/v1"
|
||||
}
|
||||
],
|
||||
"default_model_placeholder": "tsubasa/tsubasa-pro"
|
||||
},
|
||||
{
|
||||
"provider": "V0",
|
||||
"provider_display_name": "V0",
|
||||
|
|
|
|||
|
|
@ -2573,6 +2573,13 @@
|
|||
"interactions": true
|
||||
}
|
||||
},
|
||||
"tsubasa": {
|
||||
"display_name": "Tsubasa (`tsubasa`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/tsubasa",
|
||||
"endpoints": {
|
||||
"chat_completions": true
|
||||
}
|
||||
},
|
||||
"v0": {
|
||||
"display_name": "V0 (`v0`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/v0",
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ from typing import Final
|
|||
|
||||
import httpx
|
||||
import pytest
|
||||
from openai import AsyncOpenAI, OpenAI
|
||||
|
||||
from litellm import LlmProviders, completion
|
||||
from litellm import AuthenticationError, LlmProviders, RateLimitError, UnsupportedParamsError, acompletion, completion
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
from litellm.utils import ProviderConfigManager, get_model_info
|
||||
from litellm.utils import ProviderConfigManager, get_model_info, supports_response_schema
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model_id", ("tsubasa-fast", "tsubasa-pro"))
|
||||
|
|
@ -40,20 +41,20 @@ def test_tsubasa_routes_named_models_and_resolves_credentials(model_id: str, mon
|
|||
|
||||
@pytest.mark.parametrize("model_id", ("tsubasa-fast", "tsubasa-pro"))
|
||||
@pytest.mark.parametrize("stream", (False, True))
|
||||
def test_tsubasa_chat_transport(model_id: str, stream: bool, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("TSUBASA_API_KEY", "test-credential")
|
||||
registration = JSONProviderRegistry.get("tsubasa")
|
||||
def test_tsubasa_chat_transport(model_id: str, stream: bool) -> None:
|
||||
registration: Final = JSONProviderRegistry.get("tsubasa")
|
||||
assert registration is not None
|
||||
|
||||
def send(_client: httpx.Client, request: httpx.Request, **_kwargs: object) -> httpx.Response:
|
||||
def respond(request: httpx.Request) -> httpx.Response:
|
||||
assert str(request.url) == f"{registration.base_url}/chat/completions"
|
||||
assert request.headers["authorization"] == "Bearer test-credential"
|
||||
body = json.loads(request.content)
|
||||
assert body["model"] == model_id
|
||||
assert body["messages"] == [{"role": "user", "content": "Hello"}]
|
||||
assert body["max_tokens"] == 32
|
||||
assert set(body) <= {"model", "messages", "max_tokens", "stream", "stream_options"}
|
||||
result = {
|
||||
assert json.loads(request.content) == {
|
||||
"model": model_id,
|
||||
"messages": [{"role": "user", "content": "Hello"}],
|
||||
"max_tokens": 32,
|
||||
**({"stream": True, "stream_options": {"include_usage": True}} if stream else {}),
|
||||
}
|
||||
result: Final = {
|
||||
"id": "chatcmpl-contract",
|
||||
"created": 1,
|
||||
"model": model_id,
|
||||
|
|
@ -76,12 +77,107 @@ def test_tsubasa_chat_transport(model_id: str, stream: bool, monkeypatch: pytest
|
|||
)
|
||||
return httpx.Response(200, request=request, json=result)
|
||||
|
||||
monkeypatch.setattr(httpx.Client, "send", send)
|
||||
result = completion(
|
||||
model=f"tsubasa/{model_id}", messages=[{"role": "user", "content": "Hello"}], max_tokens=32, stream=stream
|
||||
)
|
||||
if stream:
|
||||
assert "".join(chunk.choices[0].delta.content or "" for chunk in result if chunk.choices) == "Hello"
|
||||
else:
|
||||
assert result.choices[0].message.content == "Hello"
|
||||
assert result.usage.total_tokens == 2
|
||||
with httpx.Client(transport=httpx.MockTransport(respond)) as client:
|
||||
result: Final = completion(
|
||||
model=f"tsubasa/{model_id}",
|
||||
messages=[{"role": "user", "content": "Hello"}],
|
||||
api_key="test-credential",
|
||||
max_completion_tokens=32,
|
||||
stream=stream,
|
||||
stream_options={"include_usage": True} if stream else None,
|
||||
client=OpenAI(api_key="test-credential", base_url=registration.base_url, http_client=client),
|
||||
)
|
||||
if stream:
|
||||
chunks: Final = tuple(result)
|
||||
assert "".join(chunk.choices[0].delta.content or "" for chunk in chunks if chunk.choices) == "Hello"
|
||||
assert chunks[-1].usage.total_tokens == 2
|
||||
else:
|
||||
assert result.choices[0].message.content == "Hello"
|
||||
assert result.usage.total_tokens == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status, error", ((401, AuthenticationError), (429, RateLimitError)))
|
||||
def test_tsubasa_preserves_upstream_error_status(status: int, error: type[Exception]) -> None:
|
||||
registration: Final = JSONProviderRegistry.get("tsubasa")
|
||||
assert registration is not None
|
||||
|
||||
def respond(request: httpx.Request) -> httpx.Response:
|
||||
return httpx.Response(status, request=request, json={"error": {"message": "Request rejected"}})
|
||||
|
||||
with httpx.Client(transport=httpx.MockTransport(respond)) as client, pytest.raises(error) as raised:
|
||||
completion(
|
||||
model="tsubasa/tsubasa-pro",
|
||||
messages=[{"role": "user", "content": "Hello"}],
|
||||
api_key="test-credential",
|
||||
num_retries=0,
|
||||
client=OpenAI(api_key="test-credential", base_url=registration.base_url, http_client=client, max_retries=0),
|
||||
)
|
||||
assert raised.value.status_code == status
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model_id", ("tsubasa-fast", "tsubasa-pro"))
|
||||
def test_tsubasa_rejects_tools_while_qualification_is_pending(model_id: str) -> None:
|
||||
with pytest.raises(UnsupportedParamsError, match="tools"):
|
||||
completion(
|
||||
model=f"tsubasa/{model_id}",
|
||||
messages=[{"role": "user", "content": "Hello"}],
|
||||
api_key="test-credential",
|
||||
tools=[{"type": "function", "function": {"name": "get_weather", "parameters": {"type": "object"}}}],
|
||||
)
|
||||
|
||||
|
||||
async def test_tsubasa_forwards_json_schema_without_declaring_qualified_support() -> None:
|
||||
registration: Final = JSONProviderRegistry.get("tsubasa")
|
||||
assert registration is not None
|
||||
response_format: Final = {
|
||||
"type": "json_schema",
|
||||
"json_schema": {
|
||||
"name": "answer",
|
||||
"strict": True,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {"answer": {"type": "string"}},
|
||||
"required": ["answer"],
|
||||
"additionalProperties": False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def respond(request: httpx.Request) -> httpx.Response:
|
||||
assert str(request.url) == f"{registration.base_url}/chat/completions"
|
||||
assert request.headers["authorization"] == "Bearer test-credential"
|
||||
assert json.loads(request.content) == {
|
||||
"model": "tsubasa-pro",
|
||||
"messages": [{"role": "user", "content": "Hello"}],
|
||||
"response_format": response_format,
|
||||
}
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"id": "chatcmpl-contract",
|
||||
"created": 1,
|
||||
"model": "tsubasa-pro",
|
||||
"object": "chat.completion",
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": '{"answer":"Hello"}',
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(respond)) as client:
|
||||
result: Final = await acompletion(
|
||||
model="tsubasa/tsubasa-pro",
|
||||
messages=[{"role": "user", "content": "Hello"}],
|
||||
response_format=response_format,
|
||||
api_key="test-credential",
|
||||
client=AsyncOpenAI(api_key="test-credential", base_url=registration.base_url, http_client=client),
|
||||
)
|
||||
assert json.loads(result.choices[0].message.content) == {"answer": "Hello"}
|
||||
assert supports_response_schema("tsubasa/tsubasa-pro") is False
|
||||
|
|
|
|||
38
tests/unit/proxy/public_endpoints/test_provider_fields.py
Normal file
38
tests/unit/proxy/public_endpoints/test_provider_fields.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from typing import Final
|
||||
|
||||
import httpx
|
||||
from fastapi import FastAPI
|
||||
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
from litellm.proxy.public_endpoints.public_endpoints import router
|
||||
from litellm.types.proxy.public_endpoints.public_endpoints import ProviderCreateInfo, SupportedEndpointsResponse
|
||||
from litellm.utils import get_model_info
|
||||
|
||||
|
||||
async def test_tsubasa_dashboard_fields_resolve_to_a_registered_model() -> None:
|
||||
app: Final = FastAPI()
|
||||
app.include_router(router)
|
||||
async with httpx.AsyncClient(transport=httpx.ASGITransport(app), base_url="http://test") as client:
|
||||
response: Final = await client.get("/public/providers/fields")
|
||||
endpoints_response: Final = await client.get("/public/endpoints")
|
||||
assert response.status_code == 200, response.text
|
||||
providers: Final = tuple(ProviderCreateInfo.model_validate(entry) for entry in response.json())
|
||||
matches: Final = tuple(provider for provider in providers if provider.litellm_provider == "tsubasa")
|
||||
assert len(matches) == 1
|
||||
provider: Final = matches[0]
|
||||
assert provider.provider == provider.provider_display_name == "Tsubasa"
|
||||
assert provider.default_model_placeholder is not None
|
||||
assert get_model_info(provider.default_model_placeholder)["litellm_provider"] == provider.litellm_provider
|
||||
registration: Final = JSONProviderRegistry.get(provider.litellm_provider)
|
||||
assert registration is not None
|
||||
assert {
|
||||
field.key: (field.field_type, field.required, field.default_value) for field in provider.credential_fields
|
||||
} == {
|
||||
"api_key": ("password", True, None),
|
||||
"api_base": ("text", False, registration.base_url),
|
||||
}
|
||||
assert endpoints_response.status_code == 200, endpoints_response.text
|
||||
endpoints: Final = SupportedEndpointsResponse.model_validate(endpoints_response.json()).endpoints
|
||||
assert [
|
||||
endpoint.key for endpoint in endpoints if any(p.slug == provider.litellm_provider for p in endpoint.providers)
|
||||
] == ["chat_completions"]
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import providerFields from "../../../../litellm/proxy/public_endpoints/provider_create_fields.json";
|
||||
import {
|
||||
Providers,
|
||||
getPlaceholder,
|
||||
|
|
@ -9,6 +10,19 @@ import {
|
|||
} from "./provider_info_helpers";
|
||||
|
||||
describe("provider_info_helpers", () => {
|
||||
it("resolves the Tsubasa dashboard selection to its models and placeholder", () => {
|
||||
const provider = providerFields.find((entry) => entry.litellm_provider === "tsubasa")!;
|
||||
const models = {
|
||||
"tsubasa/tsubasa-fast": { litellm_provider: provider.litellm_provider },
|
||||
"tsubasa/tsubasa-pro": { litellm_provider: provider.litellm_provider },
|
||||
"openai/gpt-4o": { litellm_provider: "openai" },
|
||||
};
|
||||
|
||||
expect(getProviderModels(provider.provider, models)).toEqual(["tsubasa/tsubasa-fast", "tsubasa/tsubasa-pro"]);
|
||||
expect(getPlaceholder(provider.provider)).toBe(provider.default_model_placeholder);
|
||||
expect(getProviderLogoAndName(provider.litellm_provider).displayName).toBe(provider.provider_display_name);
|
||||
});
|
||||
|
||||
describe("getProviderLogoAndName", () => {
|
||||
it("should return empty logo and dash display name when providerValue is empty", () => {
|
||||
const result = getProviderLogoAndName("");
|
||||
|
|
@ -195,6 +209,7 @@ describe("provider_info_helpers", () => {
|
|||
Providers.PG_VECTOR,
|
||||
Providers.PREDIBASE,
|
||||
Providers.Sail,
|
||||
Providers.Tsubasa,
|
||||
Providers.WANDB,
|
||||
Providers.ZAI,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ export enum Providers {
|
|||
TogetherAI = "TogetherAI",
|
||||
TOPAZ = "Topaz",
|
||||
Triton = "Triton",
|
||||
Tsubasa = "Tsubasa",
|
||||
V0 = "V0",
|
||||
VERCEL_AI_GATEWAY = "Vercel Ai Gateway",
|
||||
Vertex_AI = "Vertex AI (Anthropic, Gemini, etc.)",
|
||||
|
|
@ -289,6 +290,7 @@ export const provider_map: Record<string, string> = {
|
|||
TogetherAI: "together_ai",
|
||||
TOPAZ: "topaz",
|
||||
Triton: "triton",
|
||||
Tsubasa: "tsubasa",
|
||||
V0: "v0",
|
||||
VERCEL_AI_GATEWAY: "vercel_ai_gateway",
|
||||
Vertex_AI: "vertex_ai",
|
||||
|
|
@ -453,6 +455,7 @@ const providerPlaceholderMap: Partial<Record<Providers, string>> = {
|
|||
[Providers.Sail]: "sail/openai/gpt-oss-120b",
|
||||
[Providers.SCX_AI]: "scx-ai/GLM-5.2",
|
||||
[Providers.Snowflake]: "snowflake/mistral-7b",
|
||||
[Providers.Tsubasa]: "tsubasa/tsubasa-pro",
|
||||
[Providers.Vertex_AI]: "gemini-pro",
|
||||
[Providers.VolcEngine]: "volcengine/<any-model-on-volcengine>",
|
||||
[Providers.Voyage]: "voyage/",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue