mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-25 05:01:01 +02:00
Logging strategy updates
This commit is contained in:
parent
d91a82d8d5
commit
1d9aa652e0
4 changed files with 15 additions and 16 deletions
|
|
@ -49,9 +49,6 @@ class Api:
|
||||||
|
|
||||||
url = f"{self.url}{path}"
|
url = f"{self.url}{path}"
|
||||||
|
|
||||||
# print("uri:", url)
|
|
||||||
# print(json.dumps(request, indent=4))
|
|
||||||
|
|
||||||
# Invoke the API, input is passed as JSON
|
# Invoke the API, input is passed as JSON
|
||||||
resp = requests.post(url, json=request, timeout=self.timeout)
|
resp = requests.post(url, json=request, timeout=self.timeout)
|
||||||
|
|
||||||
|
|
@ -59,8 +56,6 @@ class Api:
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
raise ProtocolException(f"Status code {resp.status_code}")
|
raise ProtocolException(f"Status code {resp.status_code}")
|
||||||
|
|
||||||
# print(resp.text)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Parse the response as JSON
|
# Parse the response as JSON
|
||||||
object = resp.json()
|
object = resp.json()
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ class Processor(AgentService):
|
||||||
|
|
||||||
await next(r)
|
await next(r)
|
||||||
|
|
||||||
print("Done.", flush=True)
|
logger.debug("React agent processing complete")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class ReverseGateway:
|
||||||
|
|
||||||
async def handle_message(self, message: str):
|
async def handle_message(self, message: str):
|
||||||
try:
|
try:
|
||||||
print(f"Received: {message}", flush=True)
|
logger.debug(f"Received message: {message}")
|
||||||
|
|
||||||
msg_data = json.loads(message)
|
msg_data = json.loads(message)
|
||||||
response = await self.dispatcher.handle_message(msg_data)
|
response = await self.dispatcher.handle_message(msg_data)
|
||||||
|
|
@ -228,15 +228,15 @@ def run():
|
||||||
pulsar_listener=args.pulsar_listener
|
pulsar_listener=args.pulsar_listener
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"Starting reverse gateway:")
|
logger.info(f"Starting reverse gateway:")
|
||||||
print(f" WebSocket URI: {gateway.url}")
|
logger.info(f" WebSocket URI: {gateway.url}")
|
||||||
print(f" Max workers: {args.max_workers}")
|
logger.info(f" Max workers: {args.max_workers}")
|
||||||
print(f" Pulsar host: {gateway.pulsar_host}")
|
logger.info(f" Pulsar host: {gateway.pulsar_host}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
asyncio.run(gateway.run())
|
asyncio.run(gateway.run())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nShutdown requested by user")
|
logger.info("Shutdown requested by user")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Fatal error: {e}")
|
logger.error(f"Fatal error: {e}", exc_info=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ import ibis
|
||||||
import json
|
import json
|
||||||
from jsonschema import validate
|
from jsonschema import validate
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# Module logger
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class PromptConfiguration:
|
class PromptConfiguration:
|
||||||
def __init__(self, system_template, global_terms={}, prompts={}):
|
def __init__(self, system_template, global_terms={}, prompts={}):
|
||||||
|
|
@ -101,7 +105,7 @@ class PromptManager:
|
||||||
|
|
||||||
async def invoke(self, id, input, llm):
|
async def invoke(self, id, input, llm):
|
||||||
|
|
||||||
print("Invoke...", flush=True)
|
logger.debug("Invoking prompt template...")
|
||||||
|
|
||||||
terms = self.terms | self.prompts[id].terms | input
|
terms = self.terms | self.prompts[id].terms | input
|
||||||
|
|
||||||
|
|
@ -123,13 +127,13 @@ class PromptManager:
|
||||||
try:
|
try:
|
||||||
obj = self.parse_json(resp)
|
obj = self.parse_json(resp)
|
||||||
except:
|
except:
|
||||||
print("Parse fail:", resp, flush=True)
|
logger.error(f"JSON parse failed: {resp}")
|
||||||
raise RuntimeError("JSON parse fail")
|
raise RuntimeError("JSON parse fail")
|
||||||
|
|
||||||
if self.prompts[id].schema:
|
if self.prompts[id].schema:
|
||||||
try:
|
try:
|
||||||
validate(instance=obj, schema=self.prompts[id].schema)
|
validate(instance=obj, schema=self.prompts[id].schema)
|
||||||
print("Validated", flush=True)
|
logger.debug("Schema validation successful")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(f"Schema validation fail: {e}")
|
raise RuntimeError(f"Schema validation fail: {e}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue