mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-12-03 12:23:02 +01:00
Enable prompt tracing only when PROMPTRACE_DIR env var set
Better to decouple prompt tracing from debug mode or verbosity level and require explicit, independent config to enable prompt tracing
This commit is contained in:
parent
9ab76ccaf1
commit
80df3bb8c4
1 changed files with 7 additions and 5 deletions
|
@ -291,7 +291,7 @@ def save_to_conversation_log(
|
||||||
user_message=q,
|
user_message=q,
|
||||||
)
|
)
|
||||||
|
|
||||||
if in_debug_mode() or state.verbose > 1:
|
if os.getenv("PROMPTRACE_DIR"):
|
||||||
merge_message_into_conversation_trace(q, chat_response, tracer)
|
merge_message_into_conversation_trace(q, chat_response, tracer)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -578,7 +578,7 @@ def commit_conversation_trace(
|
||||||
response: str | list[dict],
|
response: str | list[dict],
|
||||||
tracer: dict,
|
tracer: dict,
|
||||||
system_message: str | list[dict] = "",
|
system_message: str | list[dict] = "",
|
||||||
repo_path: str = "/tmp/promptrace",
|
repo_path: str = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Save trace of conversation step using git. Useful to visualize, compare and debug traces.
|
Save trace of conversation step using git. Useful to visualize, compare and debug traces.
|
||||||
|
@ -589,6 +589,11 @@ def commit_conversation_trace(
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Infer repository path from environment variable or provided path
|
||||||
|
repo_path = repo_path or os.getenv("PROMPTRACE_DIR")
|
||||||
|
if not repo_path:
|
||||||
|
return None
|
||||||
|
|
||||||
# Serialize session, system message and response to yaml
|
# Serialize session, system message and response to yaml
|
||||||
system_message_yaml = json.dumps(system_message, ensure_ascii=False, sort_keys=False)
|
system_message_yaml = json.dumps(system_message, ensure_ascii=False, sort_keys=False)
|
||||||
response_yaml = json.dumps(response, ensure_ascii=False, sort_keys=False)
|
response_yaml = json.dumps(response, ensure_ascii=False, sort_keys=False)
|
||||||
|
@ -601,9 +606,6 @@ def commit_conversation_trace(
|
||||||
# Extract chat metadata for session
|
# Extract chat metadata for session
|
||||||
uid, cid, mid = tracer.get("uid", "main"), tracer.get("cid", "main"), tracer.get("mid")
|
uid, cid, mid = tracer.get("uid", "main"), tracer.get("cid", "main"), tracer.get("mid")
|
||||||
|
|
||||||
# Infer repository path from environment variable or provided path
|
|
||||||
repo_path = os.getenv("PROMPTRACE_DIR", repo_path)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Prepare git repository
|
# Prepare git repository
|
||||||
os.makedirs(repo_path, exist_ok=True)
|
os.makedirs(repo_path, exist_ok=True)
|
||||||
|
|
Loading…
Reference in a new issue