mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
Remove unnecessary prompt-client logging (#741)
This commit is contained in:
parent
f1bb45cb25
commit
c479c9c63b
1 changed files with 3 additions and 20 deletions
|
|
@ -1,21 +1,16 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
|
||||||
|
|
||||||
from . request_response_spec import RequestResponse, RequestResponseSpec
|
from . request_response_spec import RequestResponse, RequestResponseSpec
|
||||||
from .. schema import PromptRequest, PromptResponse
|
from .. schema import PromptRequest, PromptResponse
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class PromptClient(RequestResponse):
|
class PromptClient(RequestResponse):
|
||||||
|
|
||||||
async def prompt(self, id, variables, timeout=600, streaming=False, chunk_callback=None):
|
async def prompt(self, id, variables, timeout=600, streaming=False, chunk_callback=None):
|
||||||
logger.info(f"DEBUG prompt_client: prompt called, id={id}, streaming={streaming}, chunk_callback={chunk_callback is not None}")
|
|
||||||
|
|
||||||
if not streaming:
|
if not streaming:
|
||||||
logger.info("DEBUG prompt_client: Non-streaming path")
|
|
||||||
# Non-streaming path
|
|
||||||
resp = await self.request(
|
resp = await self.request(
|
||||||
PromptRequest(
|
PromptRequest(
|
||||||
id = id,
|
id = id,
|
||||||
|
|
@ -36,39 +31,30 @@ class PromptClient(RequestResponse):
|
||||||
return json.loads(resp.object)
|
return json.loads(resp.object)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info("DEBUG prompt_client: Streaming path")
|
|
||||||
# Streaming path - just forward chunks, don't accumulate
|
|
||||||
last_text = ""
|
last_text = ""
|
||||||
last_object = None
|
last_object = None
|
||||||
|
|
||||||
async def forward_chunks(resp):
|
async def forward_chunks(resp):
|
||||||
nonlocal last_text, last_object
|
nonlocal last_text, last_object
|
||||||
logger.info(f"DEBUG prompt_client: forward_chunks called, resp.text={resp.text[:50] if resp.text else None}, end_of_stream={getattr(resp, 'end_of_stream', False)}")
|
|
||||||
|
|
||||||
if resp.error:
|
if resp.error:
|
||||||
logger.error(f"DEBUG prompt_client: Error in response: {resp.error.message}")
|
|
||||||
raise RuntimeError(resp.error.message)
|
raise RuntimeError(resp.error.message)
|
||||||
|
|
||||||
end_stream = getattr(resp, 'end_of_stream', False)
|
end_stream = getattr(resp, 'end_of_stream', False)
|
||||||
|
|
||||||
# Always call callback if there's text OR if it's the final message
|
|
||||||
if resp.text is not None:
|
if resp.text is not None:
|
||||||
last_text = resp.text
|
last_text = resp.text
|
||||||
# Call chunk callback if provided with both chunk and end_of_stream flag
|
|
||||||
if chunk_callback:
|
if chunk_callback:
|
||||||
logger.info(f"DEBUG prompt_client: Calling chunk_callback with end_of_stream={end_stream}")
|
|
||||||
if asyncio.iscoroutinefunction(chunk_callback):
|
if asyncio.iscoroutinefunction(chunk_callback):
|
||||||
await chunk_callback(resp.text, end_stream)
|
await chunk_callback(resp.text, end_stream)
|
||||||
else:
|
else:
|
||||||
chunk_callback(resp.text, end_stream)
|
chunk_callback(resp.text, end_stream)
|
||||||
elif resp.object:
|
elif resp.object:
|
||||||
logger.info(f"DEBUG prompt_client: Got object response")
|
|
||||||
last_object = resp.object
|
last_object = resp.object
|
||||||
|
|
||||||
logger.info(f"DEBUG prompt_client: Returning end_of_stream={end_stream}")
|
|
||||||
return end_stream
|
return end_stream
|
||||||
|
|
||||||
logger.info("DEBUG prompt_client: Creating PromptRequest")
|
|
||||||
req = PromptRequest(
|
req = PromptRequest(
|
||||||
id = id,
|
id = id,
|
||||||
terms = {
|
terms = {
|
||||||
|
|
@ -77,19 +63,16 @@ class PromptClient(RequestResponse):
|
||||||
},
|
},
|
||||||
streaming = True
|
streaming = True
|
||||||
)
|
)
|
||||||
logger.info(f"DEBUG prompt_client: About to call self.request with recipient, timeout={timeout}")
|
|
||||||
await self.request(
|
await self.request(
|
||||||
req,
|
req,
|
||||||
recipient=forward_chunks,
|
recipient=forward_chunks,
|
||||||
timeout=timeout
|
timeout=timeout
|
||||||
)
|
)
|
||||||
logger.info(f"DEBUG prompt_client: self.request returned, last_text={last_text[:50] if last_text else None}")
|
|
||||||
|
|
||||||
if last_text:
|
if last_text:
|
||||||
logger.info("DEBUG prompt_client: Returning last_text")
|
|
||||||
return last_text
|
return last_text
|
||||||
|
|
||||||
logger.info("DEBUG prompt_client: Returning parsed last_object")
|
|
||||||
return json.loads(last_object) if last_object else None
|
return json.loads(last_object) if last_object else None
|
||||||
|
|
||||||
async def extract_definitions(self, text, timeout=600):
|
async def extract_definitions(self, text, timeout=600):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue