47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Iterator
|
|
from contextlib import contextmanager
|
|
|
|
import pytest
|
|
from ragcore_sdk import RAGCoreAPIError, RAGCoreClient
|
|
|
|
from conftest import build_context_app, run_app
|
|
|
|
|
|
@contextmanager
|
|
def _client(app: object) -> Iterator[RAGCoreClient]:
|
|
with run_app(app) as base_url, RAGCoreClient(base_url=base_url, token="sdk-test-token") as client: # type: ignore[arg-type] # noqa: E501
|
|
yield client
|
|
|
|
|
|
def test_context_returns_typed_blocks_and_citations() -> None:
|
|
fixture = build_context_app()
|
|
with _client(fixture.app) as client:
|
|
response = client.context(query="refund", requested_space_ids=[fixture.space_id])
|
|
|
|
assert response.answerability.value in {
|
|
"answerable",
|
|
"partially_answerable",
|
|
"not_answerable",
|
|
"conflicting_evidence",
|
|
}
|
|
assert response.token_count >= 0
|
|
if response.blocks:
|
|
assert response.blocks[0].citation_ids
|
|
assert response.citations
|
|
|
|
|
|
def test_context_token_budget_below_minimum_raises_typed_problem() -> None:
|
|
fixture = build_context_app()
|
|
with _client(fixture.app) as client, pytest.raises(RAGCoreAPIError) as excinfo:
|
|
client.context(
|
|
query="refund",
|
|
requested_space_ids=[fixture.space_id],
|
|
max_context_tokens=1,
|
|
)
|
|
|
|
problem = excinfo.value.problem
|
|
assert problem.status == 422
|
|
assert problem.code == "VALIDATION_ERROR"
|