File tree Expand file tree Collapse file tree 3 files changed +407
-77
lines changed
tests/v1/entrypoints/openai/responses Expand file tree Collapse file tree 3 files changed +407
-77
lines changed Original file line number Diff line number Diff line change 2
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
3
4
4
import openai # use the official client for correctness check
5
+ import openai .types .responses as openai_responses_types
5
6
import pytest
6
7
7
8
@@ -86,3 +87,18 @@ async def test_logprobs(client: openai.AsyncOpenAI):
86
87
outputs = response .output
87
88
assert outputs [- 1 ].content [- 1 ].logprobs
88
89
assert len (outputs [- 1 ].content [- 1 ].logprobs [0 ].top_logprobs ) == 5
90
+
91
+
92
+ @pytest .mark .asyncio
93
+ async def test_streaming (client : openai .AsyncOpenAI ):
94
+ stream = await client .responses .create (
95
+ input = "What is 13 * 24?" ,
96
+ stream = True ,
97
+ )
98
+ events = [event async for event in stream ]
99
+ assert isinstance (events [0 ], openai_responses_types .ResponseCreatedEvent )
100
+ assert any (
101
+ isinstance (event , openai_responses_types .ResponseTextDeltaEvent )
102
+ for event in events )
103
+ assert isinstance (events [- 1 ],
104
+ openai_responses_types .ResponseCompletedEvent )
Original file line number Diff line number Diff line change @@ -49,9 +49,19 @@ class SimpleContext(ConversationContext):
49
49
50
50
def __init__ (self ):
51
51
self .last_output = None
52
+ self .num_prompt_tokens = 0
53
+ self .num_output_tokens = 0
54
+ self .num_cached_tokens = 0
55
+ # todo num_reasoning_tokens is not implemented yet.
56
+ self .num_reasoning_tokens = 0
52
57
53
58
def append_output (self , output ) -> None :
54
59
self .last_output = output
60
+ if not isinstance (output , RequestOutput ):
61
+ raise ValueError ("SimpleContext only supports RequestOutput." )
62
+ self .num_prompt_tokens = len (output .prompt_token_ids or [])
63
+ self .num_cached_tokens = output .num_cached_tokens or 0
64
+ self .num_output_tokens += len (output .outputs [0 ].token_ids or [])
55
65
56
66
def need_builtin_tool_call (self ) -> bool :
57
67
return False
You can’t perform that action at this time.
0 commit comments