mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 12:41:02 +02:00
Fix structural errors
This commit is contained in:
parent
75f12b4c9c
commit
62cd7c20fe
2 changed files with 29 additions and 15 deletions
|
|
@ -189,13 +189,17 @@ class AsyncSocketFlowInstance:
|
||||||
request.update(kwargs)
|
request.update(kwargs)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
async for chunk in self.client._send_request_streaming("text-completion", self.flow_id, request):
|
return self._text_completion_streaming(request)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
result = await self.client._send_request("text-completion", self.flow_id, request)
|
result = await self.client._send_request("text-completion", self.flow_id, request)
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
async def _text_completion_streaming(self, request):
|
||||||
|
"""Helper for streaming text completion"""
|
||||||
|
async for chunk in self.client._send_request_streaming("text-completion", self.flow_id, request):
|
||||||
|
if hasattr(chunk, 'content'):
|
||||||
|
yield chunk.content
|
||||||
|
|
||||||
async def graph_rag(self, question: str, user: str, collection: str,
|
async def graph_rag(self, question: str, user: str, collection: str,
|
||||||
max_subgraph_size: int = 1000, max_subgraph_count: int = 5,
|
max_subgraph_size: int = 1000, max_subgraph_count: int = 5,
|
||||||
max_entity_distance: int = 3, streaming: bool = False, **kwargs):
|
max_entity_distance: int = 3, streaming: bool = False, **kwargs):
|
||||||
|
|
@ -212,13 +216,17 @@ class AsyncSocketFlowInstance:
|
||||||
request.update(kwargs)
|
request.update(kwargs)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
async for chunk in self.client._send_request_streaming("graph-rag", self.flow_id, request):
|
return self._graph_rag_streaming(request)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
result = await self.client._send_request("graph-rag", self.flow_id, request)
|
result = await self.client._send_request("graph-rag", self.flow_id, request)
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
async def _graph_rag_streaming(self, request):
|
||||||
|
"""Helper for streaming graph RAG"""
|
||||||
|
async for chunk in self.client._send_request_streaming("graph-rag", self.flow_id, request):
|
||||||
|
if hasattr(chunk, 'content'):
|
||||||
|
yield chunk.content
|
||||||
|
|
||||||
async def document_rag(self, question: str, user: str, collection: str,
|
async def document_rag(self, question: str, user: str, collection: str,
|
||||||
doc_limit: int = 10, streaming: bool = False, **kwargs):
|
doc_limit: int = 10, streaming: bool = False, **kwargs):
|
||||||
"""Document RAG with optional streaming"""
|
"""Document RAG with optional streaming"""
|
||||||
|
|
@ -232,13 +240,17 @@ class AsyncSocketFlowInstance:
|
||||||
request.update(kwargs)
|
request.update(kwargs)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
async for chunk in self.client._send_request_streaming("document-rag", self.flow_id, request):
|
return self._document_rag_streaming(request)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
result = await self.client._send_request("document-rag", self.flow_id, request)
|
result = await self.client._send_request("document-rag", self.flow_id, request)
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
async def _document_rag_streaming(self, request):
|
||||||
|
"""Helper for streaming document RAG"""
|
||||||
|
async for chunk in self.client._send_request_streaming("document-rag", self.flow_id, request):
|
||||||
|
if hasattr(chunk, 'content'):
|
||||||
|
yield chunk.content
|
||||||
|
|
||||||
async def prompt(self, id: str, variables: Dict[str, str], streaming: bool = False, **kwargs):
|
async def prompt(self, id: str, variables: Dict[str, str], streaming: bool = False, **kwargs):
|
||||||
"""Execute prompt with optional streaming"""
|
"""Execute prompt with optional streaming"""
|
||||||
request = {
|
request = {
|
||||||
|
|
@ -249,13 +261,17 @@ class AsyncSocketFlowInstance:
|
||||||
request.update(kwargs)
|
request.update(kwargs)
|
||||||
|
|
||||||
if streaming:
|
if streaming:
|
||||||
async for chunk in self.client._send_request_streaming("prompt", self.flow_id, request):
|
return self._prompt_streaming(request)
|
||||||
if hasattr(chunk, 'content'):
|
|
||||||
yield chunk.content
|
|
||||||
else:
|
else:
|
||||||
result = await self.client._send_request("prompt", self.flow_id, request)
|
result = await self.client._send_request("prompt", self.flow_id, request)
|
||||||
return result.get("response", "")
|
return result.get("response", "")
|
||||||
|
|
||||||
|
async def _prompt_streaming(self, request):
|
||||||
|
"""Helper for streaming prompt"""
|
||||||
|
async for chunk in self.client._send_request_streaming("prompt", self.flow_id, request):
|
||||||
|
if hasattr(chunk, 'content'):
|
||||||
|
yield chunk.content
|
||||||
|
|
||||||
async def graph_embeddings_query(self, text: str, user: str, collection: str, limit: int = 10, **kwargs):
|
async def graph_embeddings_query(self, text: str, user: str, collection: str, limit: int = 10, **kwargs):
|
||||||
"""Query graph embeddings for semantic search"""
|
"""Query graph embeddings for semantic search"""
|
||||||
request = {
|
request = {
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,7 @@ class BulkClient:
|
||||||
if loop.is_running():
|
if loop.is_running():
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
except Runtime
|
except RuntimeError:
|
||||||
|
|
||||||
Error:
|
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue