arun() — langchain Function Reference
Architecture documentation for the arun() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 828a059e_0651_7a7b_b6ed_b72325d8ef5f["arun()"] f3cef70e_11b0_61c9_7ec0_7308f4b45056["Chain"] 828a059e_0651_7a7b_b6ed_b72325d8ef5f -->|defined in| f3cef70e_11b0_61c9_7ec0_7308f4b45056 db96fd56_b96b_a600_1f9e_fb81937f4570["acall()"] 828a059e_0651_7a7b_b6ed_b72325d8ef5f -->|calls| db96fd56_b96b_a600_1f9e_fb81937f4570 style 828a059e_0651_7a7b_b6ed_b72325d8ef5f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/base.py lines 654–733
async def arun(
self,
*args: Any,
callbacks: Callbacks = None,
tags: list[str] | None = None,
metadata: dict[str, Any] | None = None,
**kwargs: Any,
) -> Any:
"""Convenience method for executing chain.
The main difference between this method and `Chain.__call__` is that this
method expects inputs to be passed directly in as positional arguments or
keyword arguments, whereas `Chain.__call__` expects a single input dictionary
with all the inputs
Args:
*args: If the chain expects a single input, it can be passed in as the
sole positional argument.
callbacks: Callbacks to use for this chain run. These will be called in
addition to callbacks passed to the chain during construction, but only
these runtime callbacks will propagate to calls to other objects.
tags: List of string tags to pass to all callbacks. These will be passed in
addition to tags passed to the chain during construction, but only
these runtime tags will propagate to calls to other objects.
metadata: Optional metadata associated with the chain.
**kwargs: If the chain expects multiple inputs, they can be passed in
directly as keyword arguments.
Returns:
The chain output.
Example:
```python
# Suppose we have a single-input chain that takes a 'question' string:
await chain.arun("What's the temperature in Boise, Idaho?")
# -> "The temperature in Boise is..."
# Suppose we have a multi-input chain that takes a 'question' string
# and 'context' string:
question = "What's the temperature in Boise, Idaho?"
context = "Weather report for Boise, Idaho on 07/03/23..."
await chain.arun(question=question, context=context)
# -> "The temperature in Boise is..."
```
"""
if len(self.output_keys) != 1:
msg = (
f"`run` not supported when there is not exactly "
f"one output key. Got {self.output_keys}."
)
raise ValueError(msg)
if args and not kwargs:
if len(args) != 1:
msg = "`run` supports only one positional argument."
raise ValueError(msg)
return (
await self.acall(
args[0],
callbacks=callbacks,
tags=tags,
metadata=metadata,
)
)[self.output_keys[0]]
if kwargs and not args:
return (
await self.acall(
kwargs,
callbacks=callbacks,
tags=tags,
metadata=metadata,
)
)[self.output_keys[0]]
msg = (
f"`run` supported with either positional arguments or keyword arguments"
f" but not both. Got args: {args} and kwargs: {kwargs}."
)
raise ValueError(msg)
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does arun() do?
arun() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/base.py.
Where is arun() defined?
arun() is defined in libs/langchain/langchain_classic/chains/base.py at line 654.
What does arun() call?
arun() calls 1 function(s): acall.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free