mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 04:31:02 +02:00
Fix non-streaming failure in API
This commit is contained in:
parent
aacc96064f
commit
69f10e50b3
1 changed files with 17 additions and 13 deletions
|
|
@ -275,13 +275,17 @@ class SocketFlowInstance:
|
||||||
result = self.client._send_request_sync("text-completion", self.flow_id, request, streaming)
|
result = self.client._send_request_sync("text-completion", self.flow_id, request, streaming)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
# For text completion, yield just the content
|
# For text completion, return generator that yields content
|
||||||
for chunk in result:
|
return self._text_completion_generator(result)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
def _text_completion_generator(self, result: Iterator[StreamingChunk]) -> Iterator[str]:
|
||||||
|
"""Generator for text completion streaming"""
|
||||||
|
for chunk in result:
|
||||||
|
if hasattr(chunk, 'content'):
|
||||||
|
yield chunk.content
|
||||||
|
|
||||||
def graph_rag(
|
def graph_rag(
|
||||||
self,
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
|
|
@ -308,9 +312,7 @@ class SocketFlowInstance:
|
||||||
result = self.client._send_request_sync("graph-rag", self.flow_id, request, streaming)
|
result = self.client._send_request_sync("graph-rag", self.flow_id, request, streaming)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
for chunk in result:
|
return self._rag_generator(result)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
|
@ -336,12 +338,16 @@ class SocketFlowInstance:
|
||||||
result = self.client._send_request_sync("document-rag", self.flow_id, request, streaming)
|
result = self.client._send_request_sync("document-rag", self.flow_id, request, streaming)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
for chunk in result:
|
return self._rag_generator(result)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
def _rag_generator(self, result: Iterator[StreamingChunk]) -> Iterator[str]:
|
||||||
|
"""Generator for RAG streaming (graph-rag and document-rag)"""
|
||||||
|
for chunk in result:
|
||||||
|
if hasattr(chunk, 'content'):
|
||||||
|
yield chunk.content
|
||||||
|
|
||||||
def prompt(
|
def prompt(
|
||||||
self,
|
self,
|
||||||
id: str,
|
id: str,
|
||||||
|
|
@ -360,9 +366,7 @@ class SocketFlowInstance:
|
||||||
result = self.client._send_request_sync("prompt", self.flow_id, request, streaming)
|
result = self.client._send_request_sync("prompt", self.flow_id, request, streaming)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
for chunk in result:
|
return self._rag_generator(result)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue