mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Add better exception handling in the prompt trace logic, use default value from parameters
This commit is contained in:
parent
8af9dc3ee1
commit
fd71a4b086
1 changed files with 9 additions and 9 deletions
|
@ -358,7 +358,7 @@ def commit_conversation_trace(
|
|||
response: str | list[dict],
|
||||
tracer: dict,
|
||||
system_message: str | list[dict] = "",
|
||||
repo_path: str = "/tmp/khoj_promptrace",
|
||||
repo_path: str = "/tmp/promptrace",
|
||||
) -> str:
|
||||
"""
|
||||
Save trace of conversation step using git. Useful to visualize, compare and debug traces.
|
||||
|
@ -380,7 +380,7 @@ def commit_conversation_trace(
|
|||
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) or "/tmp/promptrace"
|
||||
repo_path = os.getenv("PROMPTRACE_DIR", repo_path)
|
||||
|
||||
try:
|
||||
# Prepare git repository
|
||||
|
@ -456,11 +456,11 @@ Metadata
|
|||
logger.debug(f"Saved conversation trace to repo at {repo_path}")
|
||||
return repo_path
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to add conversation trace to repo: {str(e)}")
|
||||
logger.error(f"Failed to add conversation trace to repo: {str(e)}", exc_info=True)
|
||||
return None
|
||||
|
||||
|
||||
def merge_message_into_conversation_trace(query: str, response: str, tracer: dict, repo_path=None) -> bool:
|
||||
def merge_message_into_conversation_trace(query: str, response: str, tracer: dict, repo_path="/tmp/promptrace") -> bool:
|
||||
"""
|
||||
Merge the message branch into its parent conversation branch.
|
||||
|
||||
|
@ -474,14 +474,14 @@ def merge_message_into_conversation_trace(query: str, response: str, tracer: dic
|
|||
bool: True if merge was successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Infer repository path from environment variable or provided path
|
||||
repo_path = os.getenv("PROMPTRACE_DIR", repo_path) or "/tmp/promptrace"
|
||||
repo = Repo(repo_path)
|
||||
|
||||
# Extract branch names
|
||||
msg_branch = f"m_{tracer['mid']}"
|
||||
conv_branch = f"c_{tracer['cid']}"
|
||||
|
||||
# Infer repository path from environment variable or provided path
|
||||
repo_path = os.getenv("PROMPTRACE_DIR", repo_path)
|
||||
repo = Repo(repo_path)
|
||||
|
||||
# Checkout conversation branch
|
||||
repo.heads[conv_branch].checkout()
|
||||
|
||||
|
@ -508,5 +508,5 @@ Metadata
|
|||
logger.debug(f"Successfully merged {msg_branch} into {conv_branch}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to merge message {msg_branch} into conversation {conv_branch}: {str(e)}")
|
||||
logger.error(f"Failed to merge message {msg_branch} into conversation {conv_branch}: {str(e)}", exc_info=True)
|
||||
return False
|
||||
|
|
Loading…
Reference in a new issue