mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
add basic validation tests for e2e responses create endpoint
This commit is contained in:
parent
e9f3d97eb0
commit
63783383e7
1 changed files with 31 additions and 2 deletions
|
|
@ -29,8 +29,21 @@ def validate_response(response):
|
|||
Validate basic response structure from OpenAI responses API
|
||||
"""
|
||||
assert response is not None
|
||||
assert isinstance(response.choices[0].message.content, str)
|
||||
assert hasattr(response, "choices")
|
||||
assert len(response.choices) > 0
|
||||
assert hasattr(response.choices[0], "message")
|
||||
assert hasattr(response.choices[0].message, "content")
|
||||
assert isinstance(response.choices[0].message.content, str)
|
||||
assert hasattr(response, "id")
|
||||
assert isinstance(response.id, str)
|
||||
assert hasattr(response, "model")
|
||||
assert isinstance(response.model, str)
|
||||
assert hasattr(response, "created")
|
||||
assert isinstance(response.created, int)
|
||||
assert hasattr(response, "usage")
|
||||
assert hasattr(response.usage, "prompt_tokens")
|
||||
assert hasattr(response.usage, "completion_tokens")
|
||||
assert hasattr(response.usage, "total_tokens")
|
||||
|
||||
|
||||
def validate_stream_chunk(chunk):
|
||||
|
|
@ -38,7 +51,23 @@ def validate_stream_chunk(chunk):
|
|||
Validate streaming chunk structure from OpenAI responses API
|
||||
"""
|
||||
assert chunk is not None
|
||||
assert isinstance(chunk.choices[0].delta.content, str)
|
||||
assert hasattr(chunk, "choices")
|
||||
assert len(chunk.choices) > 0
|
||||
assert hasattr(chunk.choices[0], "delta")
|
||||
|
||||
# Some chunks might not have content in the delta
|
||||
if (
|
||||
hasattr(chunk.choices[0].delta, "content")
|
||||
and chunk.choices[0].delta.content is not None
|
||||
):
|
||||
assert isinstance(chunk.choices[0].delta.content, str)
|
||||
|
||||
assert hasattr(chunk, "id")
|
||||
assert isinstance(chunk.id, str)
|
||||
assert hasattr(chunk, "model")
|
||||
assert isinstance(chunk.model, str)
|
||||
assert hasattr(chunk, "created")
|
||||
assert isinstance(chunk.created, int)
|
||||
|
||||
|
||||
def test_basic_response():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue