File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77# Overridable non-streaming response body; None -> default "sync reply".
88NON_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.
1114NON_STREAM_SEQUENCE : list [dict ] = []
2225def 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" }}]},
You can’t perform that action at this time.
0 commit comments