Skip to content

Commit

Permalink
Fix generator nesting (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Oct 18, 2023
1 parent 5a93297 commit 672720f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions python/langsmith/run_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@ async def async_generator_wrapper(
*args, run_tree=run_container["new_run"], **kwargs
)
else:
# TODO: Nesting is ambiguous if a nested traceable function is only
# called mid-generation. Need to explicitly accept run_tree to get
# around this.
async_gen_result = func(*args, **kwargs)
_PARENT_RUN_TREE.set(run_container["new_run"].parent_run)
_PROJECT_NAME.set(run_container["outer_project"])
_TAGS.set(run_container["outer_tags"])
_METADATA.set(run_container["outer_metadata"])
async for item in async_gen_result:
results.append(item)
yield item
Expand Down Expand Up @@ -398,7 +405,14 @@ def generator_wrapper(
*args, run_tree=run_container["new_run"], **kwargs
)
else:
# TODO: Nesting is ambiguous if a nested traceable function is only
# called mid-generation. Need to explicitly accept run_tree to get
# around this.
generator_result = func(*args, **kwargs)
_PARENT_RUN_TREE.set(run_container["new_run"].parent_run)
_PROJECT_NAME.set(run_container["outer_project"])
_TAGS.set(run_container["outer_tags"])
_METADATA.set(run_container["outer_metadata"])
for item in generator_result:
results.append(item)
yield item
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langsmith"
version = "0.0.45"
version = "0.0.46"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <support@langchain.dev>"]
license = "MIT"
Expand Down

0 comments on commit 672720f

Please sign in to comment.