Skip to content

Commit

Permalink
remove dupe events (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 authored May 30, 2024
1 parent e17da94 commit 278daaf
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions agentops/partners/langchain_callback_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ def on_llm_error(
**kwargs: Any,
) -> Any:
llm_event: LLMEvent = self.events.llm[str(run_id)]
self.ao_client.record(llm_event)

error_event = ErrorEvent(trigger_event=llm_event, exception=error)
self.ao_client.record(error_event)

Expand Down Expand Up @@ -135,8 +133,6 @@ def on_llm_end(
"completion_tokens"
]

self.ao_client.record(llm_event)

if len(response.generations) == 0:
# TODO: more descriptive error
error_event = ErrorEvent(
Expand All @@ -145,6 +141,8 @@ def on_llm_end(
details="on_llm_end: No generations",
)
self.ao_client.record(error_event)
else:
self.ao_client.record(llm_event)

@debug_print_function_params
def on_chain_start(
Expand Down Expand Up @@ -192,8 +190,6 @@ def on_chain_error(
**kwargs: Any,
) -> Any:
action_event: ActionEvent = self.events.chain[str(run_id)]
self.ao_client.record(action_event)

error_event = ErrorEvent(trigger_event=action_event, exception=error)
self.ao_client.record(error_event)

Expand Down Expand Up @@ -234,7 +230,6 @@ def on_tool_end(
tool_event: ToolEvent = self.events.tool[str(run_id)]
tool_event.end_timestamp = get_ISO_time()
tool_event.returns = output
self.ao_client.record(tool_event)

# Tools are capable of failing `on_tool_end` quietly.
# This is a workaround to make sure we can log it as an error.
Expand All @@ -256,8 +251,6 @@ def on_tool_error(
**kwargs: Any,
) -> Any:
tool_event: ToolEvent = self.events.tool[str(run_id)]
self.ao_client.record(tool_event)

error_event = ErrorEvent(trigger_event=tool_event, exception=error)
self.ao_client.record(error_event)

Expand Down Expand Up @@ -311,8 +304,6 @@ def on_retriever_error(
**kwargs: Any,
) -> None:
action_event: ActionEvent = self.events.retriever[str(run_id)]
self.ao_client.record(action_event)

error_event = ErrorEvent(trigger_event=action_event, exception=error)
self.ao_client.record(error_event)

Expand Down Expand Up @@ -455,8 +446,6 @@ async def on_llm_error(
**kwargs: Any,
) -> Any:
llm_event: LLMEvent = self.events.llm[str(run_id)]
self.ao_client.record(llm_event)

error_event = ErrorEvent(trigger_event=llm_event, exception=error)
self.ao_client.record(error_event)

Expand All @@ -483,16 +472,17 @@ async def on_llm_end(
llm_event.completion_tokens = response.llm_output["token_usage"][
"completion_tokens"
]
self.ao_client.record(llm_event)

if len(response.generations) == 0:
# TODO: more descriptive error
error_event = ErrorEvent(
trigger_event=self.events.llm[str(run_id)],
trigger_event=llm_event,
error_type="NoGenerations",
details="on_llm_end: No generations",
)
self.ao_client.record(error_event)
else:
self.ao_client.record(llm_event)

@debug_print_function_params
async def on_chain_start(
Expand Down Expand Up @@ -540,8 +530,6 @@ async def on_chain_error(
**kwargs: Any,
) -> Any:
action_event: ActionEvent = self.events.chain[str(run_id)]
self.ao_client.record(action_event)

error_event = ErrorEvent(trigger_event=action_event, exception=error)
self.ao_client.record(error_event)

Expand Down Expand Up @@ -582,7 +570,6 @@ async def on_tool_end(
tool_event: ToolEvent = self.events.tool[str(run_id)]
tool_event.end_timestamp = get_ISO_time()
tool_event.returns = output
self.ao_client.record(tool_event)

# Tools are capable of failing `on_tool_end` quietly.
# This is a workaround to make sure we can log it as an error.
Expand All @@ -593,6 +580,8 @@ async def on_tool_end(
details=output,
)
self.ao_client.record(error_event)
else:
self.ao_client.record(tool_event)

@debug_print_function_params
async def on_tool_error(
Expand All @@ -604,8 +593,6 @@ async def on_tool_error(
**kwargs: Any,
) -> Any:
tool_event: ToolEvent = self.events.tool[str(run_id)]
self.ao_client.record(tool_event)

error_event = ErrorEvent(trigger_event=tool_event, exception=error)
self.ao_client.record(error_event)

Expand Down Expand Up @@ -659,8 +646,6 @@ async def on_retriever_error(
**kwargs: Any,
) -> None:
action_event: ActionEvent = self.events.retriever[str(run_id)]
self.ao_client.record(action_event)

error_event = ErrorEvent(trigger_event=action_event, exception=error)
self.ao_client.record(error_event)

Expand Down

0 comments on commit 278daaf

Please sign in to comment.