mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 20:51:02 +02:00
Streaming in prompt service
This commit is contained in:
parent
606f181c55
commit
afffeef33b
1 changed files with 7 additions and 4 deletions
|
|
@ -131,18 +131,21 @@ class Processor(FlowProcessor):
|
||||||
if resp.error:
|
if resp.error:
|
||||||
raise RuntimeError(resp.error.message)
|
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
|
# Forward each chunk immediately
|
||||||
r = PromptResponse(
|
r = PromptResponse(
|
||||||
text=resp.response,
|
text=resp.response if resp.response else "",
|
||||||
object=None,
|
object=None,
|
||||||
error=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})
|
await flow("response").send(r, properties={"id": id})
|
||||||
|
|
||||||
# Return True when end_of_stream
|
# Return True when end_of_stream
|
||||||
return getattr(resp, 'end_of_stream', False)
|
return is_final
|
||||||
|
|
||||||
await client.request(
|
await client.request(
|
||||||
TextCompletionRequest(
|
TextCompletionRequest(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue