From 8cb88ee790e2783cf81df29b8c01f855ced7545d Mon Sep 17 00:00:00 2001 From: Hassieb Pakzad <68423100+hassiebp@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:05:23 -0300 Subject: [PATCH] fix(langchain): batch run to update trace outputs (#920) --- langfuse/callback/langchain.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/langfuse/callback/langchain.py b/langfuse/callback/langchain.py index f4bf9dd9..30466e46 100644 --- a/langfuse/callback/langchain.py +++ b/langfuse/callback/langchain.py @@ -837,6 +837,14 @@ def _update_trace_and_remove_state( else: self.trace = self.trace.update(output=output, **kwargs) + elif parent_run_id is None and self.langfuse is not None: + """ + For batch runs, self.trace.id == str(run_id) only for the last run + For the rest of the runs, the trace must be manually updated + The check for self.langfuse ensures that no stateful client was provided by the user + """ + self.langfuse.trace(id=str(run_id)).update(output=output, **kwargs) + if not keep_state: del self.runs[run_id]