Add embedding preview
This commit is contained in:
@@ -300,3 +300,53 @@ class TestLLMModelAPI:
|
||||
|
||||
response = client.post(f"/api/llm/{model_id}/preview", json={"message": " "})
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_preview_embedding_model_success(self, client, monkeypatch):
|
||||
"""Test embedding model preview endpoint returns embedding summary."""
|
||||
from app.routers import llm as llm_router
|
||||
|
||||
embedding_model_data = {
|
||||
"id": "preview-emb",
|
||||
"name": "Preview Embedding",
|
||||
"vendor": "OpenAI",
|
||||
"type": "embedding",
|
||||
"base_url": "https://api.openai.com/v1",
|
||||
"api_key": "test-key",
|
||||
"model_name": "text-embedding-3-small"
|
||||
}
|
||||
create_response = client.post("/api/llm", json=embedding_model_data)
|
||||
model_id = create_response.json()["id"]
|
||||
|
||||
class DummyResponse:
|
||||
status_code = 200
|
||||
|
||||
def json(self):
|
||||
return {"data": [{"embedding": [0.1, 0.2, 0.3, 0.4]}], "usage": {"total_tokens": 7}}
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return '{"ok":true}'
|
||||
|
||||
class DummyClient:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def post(self, url, json=None, headers=None):
|
||||
assert url.endswith("/embeddings")
|
||||
assert json["input"] == "hello embedding"
|
||||
assert headers["Authorization"] == "Bearer test-key"
|
||||
return DummyResponse()
|
||||
|
||||
monkeypatch.setattr(llm_router.httpx, "Client", DummyClient)
|
||||
|
||||
response = client.post(f"/api/llm/{model_id}/preview", json={"message": "hello embedding"})
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["success"] is True
|
||||
assert "dims=4" in data["reply"]
|
||||
|
||||
Reference in New Issue
Block a user