MCPcopy
hub / github.com/openai/openai-python / test_parse_max_tokens_reached

Function test_parse_max_tokens_reached

tests/lib/chat/test_completions.py:526–551  ·  view source on GitHub ↗
(client: OpenAI, respx_mock: MockRouter)

Source from the content-addressed store, hash-verified

524
525@pytest.mark.respx(base_url=base_url)
526def test_parse_max_tokens_reached(client: OpenAI, respx_mock: MockRouter) -> None:
527 class Location(BaseModel):
528 city: str
529 temperature: float
530 units: Literal["c", "f"]
531
532 with pytest.raises(openai.LengthFinishReasonError):
533 make_snapshot_request(
534 lambda c: c.chat.completions.parse(
535 model="gpt-4o-2024-08-06",
536 messages=[
537 {
538 "role": "user",
539 "content": "What's the weather like in SF?",
540 },
541 ],
542 max_tokens=1,
543 response_format=Location,
544 ),
545 content_snapshot=snapshot(
546 '{"id": "chatcmpl-ABfvvX7eB1KsfeZj8VcF3z7G7SbaA", "object": "chat.completion", "created": 1727346163, "model": "gpt-4o-2024-08-06", "choices": [{"index": 0, "message": {"role": "assistant", "content": "{\\"", "refusal": null}, "logprobs": null, "finish_reason": "length"}], "usage": {"prompt_tokens": 79, "completion_tokens": 1, "total_tokens": 80, "completion_tokens_details": {"reasoning_tokens": 0}}, "system_fingerprint": "fp_7568d46099"}'
547 ),
548 path="/chat/completions",
549 mock_client=client,
550 respx_mock=respx_mock,
551 )
552
553
554@pytest.mark.respx(base_url=base_url)

Callers

nothing calls this directly

Calls 2

make_snapshot_requestFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected