Skip to content

Commit 8547164

Browse files
hassiebppetros94
andauthored
fix(llama-index): workflow integration (#1095) (#1097)
Co-authored-by: Petros Mitseas <petros_94@icloud.com>
1 parent 658210e commit 8547164

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

langfuse/llama_index/_span_handler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
)
1212

1313
from logging import getLogger
14+
from pydantic import BaseModel
15+
1416
from ._context import InstrumentorContext
1517

1618
logger = getLogger(__name__)
@@ -25,6 +27,7 @@
2527
StreamingResponse,
2628
AsyncStreamingResponse,
2729
)
30+
from llama_index.core.workflow import Context
2831

2932
except ImportError:
3033
raise ModuleNotFoundError(
@@ -243,6 +246,9 @@ def _parse_generation_input(
243246
def _parse_output_metadata(
244247
self, instance: Optional[Any], result: Optional[Any]
245248
) -> Tuple[Optional[Any], Optional[Any]]:
249+
if isinstance(result, BaseModel):
250+
return result.__dict__, None
251+
246252
if not result or isinstance(
247253
result,
248254
(Generator, AsyncGenerator, StreamingResponse, AsyncStreamingResponse),
@@ -289,4 +295,12 @@ def _parse_input(self, *, bound_args: inspect.BoundArguments):
289295
if "nodes" in arguments:
290296
return {"num_nodes": len(arguments["nodes"])}
291297

298+
# Remove Context since it is in not properly serialized
299+
ctx_key = None
300+
for arg, val in arguments.items():
301+
if isinstance(val, Context):
302+
ctx_key = arg
303+
if ctx_key in arguments:
304+
return {arg: val for arg, val in arguments.items() if arg != ctx_key}
305+
292306
return arguments

0 commit comments

Comments
 (0)