Skip to content

Commit e2578df

Browse files
authored
Update fake_openai_server.py
1 parent 3557b3f commit e2578df

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tests/fake_openai_server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
# Overridable non-streaming response body; None -> default "sync reply".
88
NON_STREAM_RESPONSE: dict | None = None
9+
# Overridable SSE chunk list for streaming responses; None -> the default
10+
# reasoning+content+tool-call script below.
11+
STREAM_CHUNKS: list[dict] | None = None
912
# Queue of non-streaming response bodies consumed in order; when
1013
# exhausted, NON_STREAM_RESPONSE / the default reply is used.
1114
NON_STREAM_SEQUENCE: list[dict] = []
@@ -22,6 +25,8 @@
2225
def reset_state() -> None:
2326
global NON_STREAM_RESPONSE
2427
NON_STREAM_RESPONSE = None
28+
global STREAM_CHUNKS
29+
STREAM_CHUNKS = None
2530
NON_STREAM_SEQUENCE.clear()
2631
STATUS_QUEUE.clear()
2732
REQUEST_BODIES.clear()
@@ -45,7 +50,10 @@ def do_POST(self):
4550
self.wfile.write(err)
4651
return
4752
stream = body.get("stream", False)
48-
if stream:
53+
if stream and STREAM_CHUNKS is not None:
54+
chunks = STREAM_CHUNKS
55+
data = "".join("data: " + json.dumps(c) + "\n\n" for c in chunks) + "data: [DONE]\n\n"
56+
elif stream:
4957
chunks = [
5058
{"choices": [{"delta": {"role": "assistant", "reasoning_content": "thinking"}}]},
5159
{"choices": [{"delta": {"reasoning_content": " hard"}}]},

0 commit comments

Comments
 (0)