mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix: route Tiyuvta legacy completions through text handler
This commit is contained in:
parent
eab6281923
commit
f23bf2b953
4 changed files with 57 additions and 1 deletions
|
|
@ -838,6 +838,7 @@ openai_text_completion_compatible_providers: Final[list] = [ # providers that s
|
|||
"publicai",
|
||||
"synthetic",
|
||||
"tensormesh",
|
||||
"tiyuvta",
|
||||
"apertis",
|
||||
"nano-gpt",
|
||||
"poe",
|
||||
|
|
|
|||
|
|
@ -3723,6 +3723,7 @@ class LlmProviders(str, Enum):
|
|||
PARASAIL = "parasail"
|
||||
XIAOMI_MIMO = "xiaomi_mimo"
|
||||
TENSORMESH = "tensormesh"
|
||||
TIYUVTA = "tiyuvta"
|
||||
LIBERTAI = "libertai"
|
||||
PINSTRIPES = "pinstripes"
|
||||
DARKBLOOM = "darkbloom"
|
||||
|
|
|
|||
|
|
@ -2380,7 +2380,8 @@
|
|||
"moderations": false,
|
||||
"batches": false,
|
||||
"rerank": false,
|
||||
"a2a": false
|
||||
"a2a": false,
|
||||
"text_completion": true
|
||||
}
|
||||
},
|
||||
"together_ai": {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ Tests for JSON-based provider configuration system.
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
from typing import Final
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import httpx
|
||||
from openai import OpenAI
|
||||
|
||||
try:
|
||||
import pytest
|
||||
except ImportError:
|
||||
|
|
@ -20,6 +24,55 @@ sys.path.insert(0, workspace_path)
|
|||
import litellm
|
||||
|
||||
|
||||
@pytest.mark.parametrize("legacy", [True, False])
|
||||
def test_tiyuvta_routes_completion_endpoint(legacy: bool) -> None:
|
||||
def respond(request: httpx.Request) -> httpx.Response:
|
||||
endpoint: Final = "completions" if legacy else "chat/completions"
|
||||
assert str(request.url) == f"https://api.tiyuvta.ai/v1/{endpoint}"
|
||||
assert request.headers["authorization"] == "Bearer test-tiyuvta-key"
|
||||
payload: Final = json.loads(request.content)
|
||||
assert payload["model"] == "test-model"
|
||||
if legacy:
|
||||
assert payload["prompt"] == "Say hello"
|
||||
assert "messages" not in payload
|
||||
else:
|
||||
assert payload["messages"] == [{"role": "user", "content": "Say hello"}]
|
||||
assert "prompt" not in payload
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={
|
||||
"id": "completion-test",
|
||||
"object": "text_completion" if legacy else "chat.completion",
|
||||
"created": 1,
|
||||
"model": "test-model",
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
**({"text": "hello"} if legacy else {"message": {"role": "assistant", "content": "hello"}}),
|
||||
}
|
||||
],
|
||||
"usage": {"prompt_tokens": 2, "completion_tokens": 1, "total_tokens": 3},
|
||||
},
|
||||
)
|
||||
|
||||
with OpenAI(
|
||||
api_key="test-tiyuvta-key",
|
||||
base_url="https://api.tiyuvta.ai/v1",
|
||||
http_client=httpx.Client(transport=httpx.MockTransport(respond)),
|
||||
max_retries=0,
|
||||
) as client:
|
||||
response: Final = (
|
||||
litellm.text_completion(model="tiyuvta/test-model", prompt="Say hello", client=client)
|
||||
if legacy
|
||||
else litellm.completion(
|
||||
model="tiyuvta/test-model", messages=[{"role": "user", "content": "Say hello"}], client=client
|
||||
)
|
||||
)
|
||||
assert response.choices[0].finish_reason == "stop"
|
||||
assert (response.choices[0].text if legacy else response.choices[0].message.content) == "hello"
|
||||
|
||||
|
||||
class TestJSONProviderLoader:
|
||||
"""Test JSON provider loading and configuration"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue