Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 83 additions & 142 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,116 +1317,61 @@ def inner(request_headers=None):

@pytest.fixture
def streaming_chat_completions_model_response():
return [
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
role="assistant"
),
finish_reason=None,
),
],
),
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
content="Tes"
),
finish_reason=None,
),
],
),
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
content="t r"
),
finish_reason=None,
),
],
),
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
content="esp"
),
finish_reason=None,
),
],
),
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
content="ons"
def inner(
usage: "openai.types.CompletionUsage",
message_contents: "Iterator[str]",
):
return [
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
role="assistant"
),
finish_reason=None,
),
finish_reason=None,
),
],
),
*[
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
content=message_content
),
finish_reason=None,
),
],
)
for message_content in message_contents
],
),
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(
content="e"
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(),
finish_reason="stop",
),
finish_reason=None,
),
],
),
openai.types.chat.ChatCompletionChunk(
id="chatcmpl-test",
object="chat.completion.chunk",
created=10000000,
model="gpt-3.5-turbo",
choices=[
openai.types.chat.chat_completion_chunk.Choice(
index=0,
delta=openai.types.chat.chat_completion_chunk.ChoiceDelta(),
finish_reason="stop",
),
],
usage=openai.types.CompletionUsage(
prompt_tokens=10,
completion_tokens=20,
total_tokens=30,
],
usage=usage,
),
),
]
]

return inner


@pytest.fixture
Expand Down Expand Up @@ -1479,42 +1424,38 @@ def openai_embedding_model_response():

@pytest.fixture
def nonstreaming_responses_model_response():
return openai.types.responses.Response(
id="resp_123",
output=[
openai.types.responses.ResponseOutputMessage(
id="msg_123",
type="message",
status="completed",
content=[
openai.types.responses.ResponseOutputText(
text="Hello, how can I help you?",
type="output_text",
annotations=[],
)
],
role="assistant",
)
],
parallel_tool_calls=False,
tool_choice="none",
tools=[],
created_at=10000000,
model="gpt-4",
object="response",
usage=openai.types.responses.ResponseUsage(
input_tokens=10,
input_tokens_details=openai.types.responses.response_usage.InputTokensDetails(
cached_tokens=4,
cache_write_tokens=6,
),
output_tokens=20,
output_tokens_details=openai.types.responses.response_usage.OutputTokensDetails(
reasoning_tokens=5,
),
total_tokens=30,
),
)
def inner(
message_contents: "Iterator[str]",
usage: "openai.types.responses.ResponseUsage",
):
return openai.types.responses.Response(
id="resp_123",
output=[
openai.types.responses.ResponseOutputMessage(
id="msg_123",
type="message",
status="completed",
content=[
openai.types.responses.ResponseOutputText(
text=message_content,
type="output_text",
annotations=[],
)
],
role="assistant",
)
for message_content in message_contents
],
parallel_tool_calls=False,
tool_choice="none",
tools=[],
created_at=10000000,
model="gpt-4",
object="response",
usage=usage,
)

return inner


@pytest.fixture
Expand Down
16 changes: 15 additions & 1 deletion tests/integrations/langchain/test_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,21 @@ def test_langchain_create_agent(
)

model_response = get_model_response(
nonstreaming_responses_model_response,
nonstreaming_responses_model_response(
message_contents=("Hello, how can I help you?",),
usage=ResponseUsage(
input_tokens=10,
input_tokens_details=InputTokensDetails(
cached_tokens=4,
cache_write_tokens=6,
),
output_tokens=20,
output_tokens_details=OutputTokensDetails(
reasoning_tokens=5,
),
total_tokens=30,
),
),
serialize_pydantic=True,
request_headers={
"X-Stainless-Raw-Response": "True",
Expand Down
18 changes: 16 additions & 2 deletions tests/integrations/litellm/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,14 @@ def test_streaming_chat_completion(

model_response = get_model_response(
server_side_event_chunks(
streaming_chat_completions_model_response,
streaming_chat_completions_model_response(
usage=CompletionUsage(
prompt_tokens=10,
completion_tokens=20,
total_tokens=30,
),
message_contents=("Tes", "t r", "esp", "ons", "e"),
),
include_event_type=False,
),
request_headers={"X-Stainless-Raw-Response": "true"},
Expand Down Expand Up @@ -713,7 +720,14 @@ async def test_async_streaming_chat_completion(
model_response = get_model_response(
async_iterator(
server_side_event_chunks(
streaming_chat_completions_model_response,
streaming_chat_completions_model_response(
usage=CompletionUsage(
prompt_tokens=10,
completion_tokens=20,
total_tokens=30,
),
message_contents=("Tes", "t r", "esp", "ons", "e"),
Comment thread
cursor[bot] marked this conversation as resolved.
),
include_event_type=False,
),
),
Expand Down
Loading
Loading