Skip to content

Commit bab374c

Browse files
committed
test: add multi endpoint with test
1 parent 9cf9736 commit bab374c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/unit/test_openai_embedding.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from httpx import ASGITransport, AsyncClient
2323

2424
import litserve as ls
25+
from litserve.specs.openai import OpenAISpec
2526
from litserve.specs.openai_embedding import OpenAIEmbeddingSpec
2627
from litserve.test_examples.openai_embedding_spec_example import (
2728
TestEmbedAPI,
@@ -50,6 +51,22 @@ async def test_openai_embedding_spec_with_single_input(openai_embedding_request_
5051
assert len(resp.json()["data"]) == 1, "Length of data should be 1"
5152
assert len(resp.json()["data"][0]["embedding"]) == 768, "Embedding length should be 768"
5253

54+
@pytest.mark.asyncio
55+
async def test_openai_embedding_spec_with_multi_endpoint(openai_embedding_request_data):
56+
spec_openai = OpenAISpec()
57+
spec_embedding = OpenAIEmbeddingSpec()
58+
server = ls.LitServer([TestEmbedAPI(spec=spec_openai),TestEmbedAPI(spec=spec_embedding)])
59+
with wrap_litserve_start(server) as server:
60+
async with LifespanManager(server.app) as manager, AsyncClient(
61+
transport=ASGITransport(app=manager.app), base_url="http://test"
62+
) as ac:
63+
resp = await ac.post("/v1/embeddings", json=openai_embedding_request_data, timeout=10)
64+
assert resp.status_code == 200, "Status code should be 200"
65+
assert resp.json()["object"] == "list", "Object should be list"
66+
assert resp.json()["data"][0]["index"] == 0, "Index should be 0"
67+
assert len(resp.json()["data"]) == 1, "Length of data should be 1"
68+
assert len(resp.json()["data"][0]["embedding"]) == 768, "Embedding length should be 768"
69+
5370

5471
@pytest.mark.asyncio
5572
async def test_openai_embedding_spec_with_multiple_inputs(openai_embedding_request_data_array):

0 commit comments

Comments
 (0)