From afffeef33b4f6ba78ecae7f78490e47ea9b3c784 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Tue, 25 Nov 2025 18:58:37 +0000 Subject: [PATCH] Streaming in prompt service --- trustgraph-flow/trustgraph/prompt/template/service.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trustgraph-flow/trustgraph/prompt/template/service.py b/trustgraph-flow/trustgraph/prompt/template/service.py index 8ae64391..5fc177d5 100755 --- a/trustgraph-flow/trustgraph/prompt/template/service.py +++ b/trustgraph-flow/trustgraph/prompt/template/service.py @@ -131,18 +131,21 @@ class Processor(FlowProcessor): if resp.error: raise RuntimeError(resp.error.message) - if resp.response: + is_final = getattr(resp, 'end_of_stream', False) + + # Always send a message if there's content OR if it's the final message + if resp.response or is_final: # Forward each chunk immediately r = PromptResponse( - text=resp.response, + text=resp.response if resp.response else "", object=None, error=None, - end_of_stream=getattr(resp, 'end_of_stream', False), + end_of_stream=is_final, ) await flow("response").send(r, properties={"id": id}) # Return True when end_of_stream - return getattr(resp, 'end_of_stream', False) + return is_final await client.request( TextCompletionRequest(