xtristan's picture
Release OpenJudgement-4B-Preview
eb2384f
Raw History Blame Contribute Delete
1.72 kB
from fastapi.testclient import TestClient
from serve import create_app
class FakeJudge:
model_name = 'test-preview'
def system_one(self, state, questions):
if state == 'invalid':
raise ValueError('Input exceeds configured context; nothing was truncated.')
return {'model': self.model_name, 'answers': {key: {'type': 'noul', 'noul': 0.75} for key in questions}}
def test_api_request_and_health():
with TestClient(create_app(loader=FakeJudge)) as client:
assert client.get('/health').json()['ready'] is True
response = client.post('/v1/judgments', json={'state': 'Evidence.', 'questions': {'q': {'type': 'noul', 'instructions': 'Supported?'}}})
assert response.status_code == 200
assert response.json()['answers']['q']['noul'] == 0.75
assert response.json()['timing']['inference_ms'] >= 0
def test_api_rejects_bad_requests_without_inference():
with TestClient(create_app(loader=FakeJudge)) as client:
assert client.post('/v1/judgments', json={'state': 'Evidence.', 'questions': {}}).status_code == 422
assert client.post('/v1/judgments', json={'state': 'invalid', 'questions': {'q': {}}}).status_code == 422
def test_examples_follow_native_contract():
import json
from pathlib import Path
from core import normalize_question
request = json.loads((Path(__file__).resolve().parents[1]/'examples/request.json').read_text())
assert {q['type'] for q in request['questions'].values()} == {'noul','choice','score'}
for question in request['questions'].values():
kind,instructions,candidates,keys = normalize_question(question)
assert instructions and len(candidates) == len(keys)