Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Fix "argument of type 'NoneType' is not iterable" error in LangChainTracer #26576

Merged
merged 6 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def invoke(
inheritable_metadata=config.get("metadata"),
)
run_manager = callback_manager.on_chain_start(
dumpd(self), input, name=config.get("run_name")
dumpd(self), input, name=config.get("run_name") or self.get_name()
)

files = _convert_file_ids_into_attachments(kwargs.get("file_ids", []))
Expand Down Expand Up @@ -437,7 +437,7 @@ async def ainvoke(
inheritable_metadata=config.get("metadata"),
)
run_manager = callback_manager.on_chain_start(
dumpd(self), input, name=config.get("run_name")
dumpd(self), input, name=config.get("run_name") or self.get_name()
)

files = _convert_file_ids_into_attachments(kwargs.get("file_ids", []))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ def test_callback_manager_configure_context_vars(
assert cb.completion_tokens == 1
assert cb.total_cost > 0
wait_for_all_tracers()
assert LangChainTracer._persist_run_single.call_count == 1 # type: ignore
assert LangChainTracer._persist_run_single.call_count == 4 # type: ignore
4 changes: 3 additions & 1 deletion libs/core/langchain_core/tracers/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ class Run(BaseRunV2):
@root_validator(pre=True)
def assign_name(cls, values: dict) -> dict:
"""Assign name to the run."""
if values.get("name") is None:
if values.get("name") is None and values["serialized"] is not None:
if "name" in values["serialized"]:
values["name"] = values["serialized"]["name"]
elif "id" in values["serialized"]:
values["name"] = values["serialized"]["id"][-1]
if values.get("name") is None:
values["name"] = "Unnamed"
if values.get("events") is None:
values["events"] = []
return values
Expand Down
4 changes: 2 additions & 2 deletions libs/langchain/langchain/agents/openai_assistant/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def invoke(
inheritable_metadata=config.get("metadata"),
)
run_manager = callback_manager.on_chain_start(
dumpd(self), input, name=config.get("run_name")
dumpd(self), input, name=config.get("run_name") or self.get_name()
)
try:
# Being run within AgentExecutor and there are tool outputs to submit.
Expand Down Expand Up @@ -429,7 +429,7 @@ async def ainvoke(
inheritable_metadata=config.get("metadata"),
)
run_manager = callback_manager.on_chain_start(
dumpd(self), input, name=config.get("run_name")
dumpd(self), input, name=config.get("run_name") or self.get_name()
)
try:
# Being run within AgentExecutor and there are tool outputs to submit.
Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/langchain/chains/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def apply(
run_manager = callback_manager.on_chain_start(
None,
{"input_list": input_list},
name=self.get_name(),
)
try:
response = self.generate(input_list, run_manager=run_manager)
Expand All @@ -262,6 +263,7 @@ async def aapply(
run_manager = await callback_manager.on_chain_start(
None,
{"input_list": input_list},
name=self.get_name(),
)
try:
response = await self.agenerate(input_list, run_manager=run_manager)
Expand Down
Loading