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:
Debanjum 2024-11-20 11:50:55 -08:00
parent 9ab76ccaf1
commit 80df3bb8c4

View file

@ -291,7 +291,7 @@ def save_to_conversation_log(
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)
logger.info(
@ -578,7 +578,7 @@ def commit_conversation_trace(
response: str | list[dict],
tracer: dict,
system_message: str | list[dict] = "",
repo_path: str = "/tmp/promptrace",
repo_path: str = None,
) -> str:
"""
Save trace of conversation step using git. Useful to visualize, compare and debug traces.
@ -589,6 +589,11 @@ def commit_conversation_trace(
except ImportError:
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
system_message_yaml = json.dumps(system_message, 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
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:
# Prepare git repository
os.makedirs(repo_path, exist_ok=True)