Skip to content

Commit b6c0785

Browse files
fix mismatched response format w/wo streaming guardrails (#568)
* fix mismatched response format w/wo streaming guardrails * fix & debug * fix & rm debug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 25174c0 commit b6c0785

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

comps/cores/mega/orchestrator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ async def schedule(self, initial_inputs: Dict, llm_parameters: LLMParams = LLMPa
7272
downstreams.remove(downstream)
7373
except re.error as e:
7474
print("Pattern invalid! Operation cancelled.")
75+
if len(downstreams) == 0 and llm_parameters.streaming:
76+
# turn the response to a StreamingResponse
77+
# to make the response uniform to UI
78+
def fake_stream(text):
79+
yield "data: b'" + text + "'\n\n"
80+
yield "data: [DONE]\n\n"
81+
82+
self.dump_outputs(
83+
node,
84+
StreamingResponse(fake_stream(response["text"]), media_type="text/event-stream"),
85+
result_dict,
86+
)
7587

7688
for d_node in downstreams:
7789
if all(i in result_dict for i in runtime_graph.predecessors(d_node)):

0 commit comments

Comments
 (0)