Add id in error in tracer (#8944)

This commit is contained in:
William FH 2023-08-08 18:25:27 -07:00 committed by GitHub
parent 99b5a7226c
commit e3056340da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,7 +131,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
run_id_ = str(run_id) run_id_ = str(run_id)
llm_run = self.run_map.get(run_id_) llm_run = self.run_map.get(run_id_)
if llm_run is None or llm_run.run_type != "llm": 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( llm_run.events.append(
{ {
"name": "new_token", "name": "new_token",
@ -183,7 +183,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
run_id_ = str(run_id) run_id_ = str(run_id)
llm_run = self.run_map.get(run_id_) llm_run = self.run_map.get(run_id_)
if llm_run is None or llm_run.run_type != "llm": 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() llm_run.outputs = response.dict()
for i, generations in enumerate(response.generations): for i, generations in enumerate(response.generations):
for j, generation in enumerate(generations): for j, generation in enumerate(generations):
@ -211,7 +211,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
run_id_ = str(run_id) run_id_ = str(run_id)
llm_run = self.run_map.get(run_id_) llm_run = self.run_map.get(run_id_)
if llm_run is None or llm_run.run_type != "llm": 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.error = repr(error)
llm_run.end_time = datetime.utcnow() llm_run.end_time = datetime.utcnow()
llm_run.events.append({"name": "error", "time": llm_run.end_time}) llm_run.events.append({"name": "error", "time": llm_run.end_time})
@ -261,7 +261,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
raise TracerException("No run_id provided for on_chain_end callback.") raise TracerException("No run_id provided for on_chain_end callback.")
chain_run = self.run_map.get(str(run_id)) chain_run = self.run_map.get(str(run_id))
if chain_run is None: 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.outputs = outputs
chain_run.end_time = datetime.utcnow() chain_run.end_time = datetime.utcnow()
@ -281,7 +281,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
raise TracerException("No run_id provided for on_chain_error callback.") raise TracerException("No run_id provided for on_chain_error callback.")
chain_run = self.run_map.get(str(run_id)) chain_run = self.run_map.get(str(run_id))
if chain_run is None: 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.error = repr(error)
chain_run.end_time = datetime.utcnow() chain_run.end_time = datetime.utcnow()
@ -329,7 +329,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
raise TracerException("No run_id provided for on_tool_end callback.") raise TracerException("No run_id provided for on_tool_end callback.")
tool_run = self.run_map.get(str(run_id)) tool_run = self.run_map.get(str(run_id))
if tool_run is None or tool_run.run_type != "tool": 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.outputs = {"output": output}
tool_run.end_time = datetime.utcnow() tool_run.end_time = datetime.utcnow()
@ -349,7 +349,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
raise TracerException("No run_id provided for on_tool_error callback.") raise TracerException("No run_id provided for on_tool_error callback.")
tool_run = self.run_map.get(str(run_id)) tool_run = self.run_map.get(str(run_id))
if tool_run is None or tool_run.run_type != "tool": 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.error = repr(error)
tool_run.end_time = datetime.utcnow() tool_run.end_time = datetime.utcnow()
@ -404,7 +404,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
raise TracerException("No run_id provided for on_retriever_error callback.") raise TracerException("No run_id provided for on_retriever_error callback.")
retrieval_run = self.run_map.get(str(run_id)) retrieval_run = self.run_map.get(str(run_id))
if retrieval_run is None or retrieval_run.run_type != "retriever": 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.error = repr(error)
retrieval_run.end_time = datetime.utcnow() retrieval_run.end_time = datetime.utcnow()
@ -420,7 +420,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
raise TracerException("No run_id provided for on_retriever_end callback.") raise TracerException("No run_id provided for on_retriever_end callback.")
retrieval_run = self.run_map.get(str(run_id)) retrieval_run = self.run_map.get(str(run_id))
if retrieval_run is None or retrieval_run.run_type != "retriever": 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.outputs = {"documents": documents}
retrieval_run.end_time = datetime.utcnow() retrieval_run.end_time = datetime.utcnow()
retrieval_run.events.append({"name": "end", "time": retrieval_run.end_time}) retrieval_run.events.append({"name": "end", "time": retrieval_run.end_time})