Skip to content

Commit

Permalink
Add id in error
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Aug 9, 2023
1 parent 95cf7de commit 331692e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions libs/langchain/langchain/callbacks/tracers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def on_llm_new_token(
run_id_ = str(run_id)
llm_run = self.run_map.get(run_id_)
if llm_run is None or llm_run.run_type != "llm":
raise TracerException("No LLM Run found to be traced")
raise TracerException(f"No LLM Run found to be traced for {run_id}")
llm_run.events.append(
{
"name": "new_token",
Expand Down Expand Up @@ -183,7 +183,7 @@ def on_llm_end(self, response: LLMResult, *, run_id: UUID, **kwargs: Any) -> Non
run_id_ = str(run_id)
llm_run = self.run_map.get(run_id_)
if llm_run is None or llm_run.run_type != "llm":
raise TracerException("No LLM Run found to be traced")
raise TracerException(f"No LLM Run found to be traced for {run_id}")
llm_run.outputs = response.dict()
for i, generations in enumerate(response.generations):
for j, generation in enumerate(generations):
Expand Down Expand Up @@ -211,7 +211,7 @@ def on_llm_error(
run_id_ = str(run_id)
llm_run = self.run_map.get(run_id_)
if llm_run is None or llm_run.run_type != "llm":
raise TracerException("No LLM Run found to be traced")
raise TracerException(f"No LLM Run found to be traced for {run_id}")
llm_run.error = repr(error)
llm_run.end_time = datetime.utcnow()
llm_run.events.append({"name": "error", "time": llm_run.end_time})
Expand Down Expand Up @@ -261,7 +261,7 @@ def on_chain_end(
raise TracerException("No run_id provided for on_chain_end callback.")
chain_run = self.run_map.get(str(run_id))
if chain_run is None:
raise TracerException("No chain Run found to be traced")
raise TracerException(f"No chain Run found to be traced for {run_id}")

chain_run.outputs = outputs
chain_run.end_time = datetime.utcnow()
Expand All @@ -281,7 +281,7 @@ def on_chain_error(
raise TracerException("No run_id provided for on_chain_error callback.")
chain_run = self.run_map.get(str(run_id))
if chain_run is None:
raise TracerException("No chain Run found to be traced")
raise TracerException(f"No chain Run found to be traced for {run_id}")

chain_run.error = repr(error)
chain_run.end_time = datetime.utcnow()
Expand Down Expand Up @@ -329,7 +329,7 @@ def on_tool_end(self, output: str, *, run_id: UUID, **kwargs: Any) -> None:
raise TracerException("No run_id provided for on_tool_end callback.")
tool_run = self.run_map.get(str(run_id))
if tool_run is None or tool_run.run_type != "tool":
raise TracerException("No tool Run found to be traced")
raise TracerException(f"No tool Run found to be traced for {run_id}")

tool_run.outputs = {"output": output}
tool_run.end_time = datetime.utcnow()
Expand All @@ -349,7 +349,7 @@ def on_tool_error(
raise TracerException("No run_id provided for on_tool_error callback.")
tool_run = self.run_map.get(str(run_id))
if tool_run is None or tool_run.run_type != "tool":
raise TracerException("No tool Run found to be traced")
raise TracerException(f"No tool Run found to be traced for {run_id}")

tool_run.error = repr(error)
tool_run.end_time = datetime.utcnow()
Expand Down Expand Up @@ -404,7 +404,7 @@ def on_retriever_error(
raise TracerException("No run_id provided for on_retriever_error callback.")
retrieval_run = self.run_map.get(str(run_id))
if retrieval_run is None or retrieval_run.run_type != "retriever":
raise TracerException("No retriever Run found to be traced")
raise TracerException(f"No retriever Run found to be traced for {run_id}")

retrieval_run.error = repr(error)
retrieval_run.end_time = datetime.utcnow()
Expand All @@ -420,7 +420,7 @@ def on_retriever_end(
raise TracerException("No run_id provided for on_retriever_end callback.")
retrieval_run = self.run_map.get(str(run_id))
if retrieval_run is None or retrieval_run.run_type != "retriever":
raise TracerException("No retriever Run found to be traced")
raise TracerException(f"No retriever Run found to be traced for {run_id}")
retrieval_run.outputs = {"documents": documents}
retrieval_run.end_time = datetime.utcnow()
retrieval_run.events.append({"name": "end", "time": retrieval_run.end_time})
Expand Down

0 comments on commit 331692e

Please sign in to comment.