Home / Function/ agenerate() — langchain Function Reference

agenerate() — langchain Function Reference

Architecture documentation for the agenerate() function in llm.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  926fd9b4_0102_a6de_8f35_2fe1bcf91155["agenerate()"]
  ccf50fe1_4990_cf19_1e2d_25efe83f53c5["LLMChain"]
  926fd9b4_0102_a6de_8f35_2fe1bcf91155 -->|defined in| ccf50fe1_4990_cf19_1e2d_25efe83f53c5
  6d160283_10a9_3468_0269_f458545a9fa6["aapply()"]
  6d160283_10a9_3468_0269_f458545a9fa6 -->|calls| 926fd9b4_0102_a6de_8f35_2fe1bcf91155
  6863402d_6621_7d8a_f622_2b781f3a6f69["_acall()"]
  6863402d_6621_7d8a_f622_2b781f3a6f69 -->|calls| 926fd9b4_0102_a6de_8f35_2fe1bcf91155
  5fbfd29a_5361_2eb2_3d24_d46ae6a681e4["aprep_prompts()"]
  926fd9b4_0102_a6de_8f35_2fe1bcf91155 -->|calls| 5fbfd29a_5361_2eb2_3d24_d46ae6a681e4
  style 926fd9b4_0102_a6de_8f35_2fe1bcf91155 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/llm.py lines 147–172

    async def agenerate(
        self,
        input_list: list[dict[str, Any]],
        run_manager: AsyncCallbackManagerForChainRun | None = None,
    ) -> LLMResult:
        """Generate LLM result from inputs."""
        prompts, stop = await self.aprep_prompts(input_list, run_manager=run_manager)
        callbacks = run_manager.get_child() if run_manager else None
        if isinstance(self.llm, BaseLanguageModel):
            return await self.llm.agenerate_prompt(
                prompts,
                stop,
                callbacks=callbacks,
                **self.llm_kwargs,
            )
        results = await self.llm.bind(stop=stop, **self.llm_kwargs).abatch(
            cast("list", prompts),
            {"callbacks": callbacks},
        )
        generations: list[list[Generation]] = []
        for res in results:
            if isinstance(res, BaseMessage):
                generations.append([ChatGeneration(message=res)])
            else:
                generations.append([Generation(text=res)])
        return LLMResult(generations=generations)

Subdomains

Called By

Frequently Asked Questions

What does agenerate() do?
agenerate() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/llm.py.
Where is agenerate() defined?
agenerate() is defined in libs/langchain/langchain_classic/chains/llm.py at line 147.
What does agenerate() call?
agenerate() calls 1 function(s): aprep_prompts.
What calls agenerate()?
agenerate() is called by 2 function(s): _acall, aapply.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free