Skip to main content

Class: LLMChain

chains.LLMChain

Chain to run queries against LLMs.

Example

import { LLMChain } from "langchain/chains";
import { OpenAI } from "langchain/llms/openai";
import { PromptTemplate } from "langchain/prompts";
const prompt = PromptTemplate.fromTemplate("Tell me a {adjective} joke");
const llm = LLMChain({ llm: new OpenAI(), prompt });

Hierarchy

Implements

  • LLMChainInput

Constructors

constructor

new LLMChain(fields)

Parameters

NameType
fieldsLLMChainInput

Overrides

BaseChain.constructor

Defined in

langchain/src/chains/llm_chain.ts:54

Properties

callbackManager

callbackManager: CallbackManager

Implementation of

LLMChainInput.callbackManager

Inherited from

BaseChain.callbackManager

Defined in

langchain/src/chains/base.ts:25


llm

llm: BaseLanguageModel

Implementation of

LLMChainInput.llm

Defined in

langchain/src/chains/llm_chain.ts:44


memory

Optional memory: BaseMemory

Implementation of

LLMChainInput.memory

Inherited from

BaseChain.memory

Defined in

langchain/src/chains/base.ts:21


outputKey

outputKey: string = "text"

Implementation of

LLMChainInput.outputKey

Defined in

langchain/src/chains/llm_chain.ts:46


outputParser

Optional outputParser: BaseOutputParser

Implementation of

LLMChainInput.outputParser

Defined in

langchain/src/chains/llm_chain.ts:48


prompt

prompt: BasePromptTemplate

Implementation of

LLMChainInput.prompt

Defined in

langchain/src/chains/llm_chain.ts:42


verbose

verbose: boolean

Implementation of

LLMChainInput.verbose

Inherited from

BaseChain.verbose

Defined in

langchain/src/chains/base.ts:23

Accessors

inputKeys

get inputKeys(): string[]

Returns

string[]

Overrides

BaseChain.inputKeys

Defined in

langchain/src/chains/llm_chain.ts:50

Methods

_call

_call(values): Promise<ChainValues>

Run the core logic of this chain and return the output

Parameters

NameType
valuesChainValues

Returns

Promise<ChainValues>

Overrides

BaseChain._call

Defined in

langchain/src/chains/llm_chain.ts:85


_chainType

_chainType(): "llm_chain"

Return the string type key uniquely identifying this class of chain.

Returns

"llm_chain"

Overrides

BaseChain._chainType

Defined in

langchain/src/chains/llm_chain.ts:113


_getFinalOutput

_getFinalOutput(generations, promptValue): Promise<unknown>

Parameters

NameType
generationsGeneration[]
promptValueBasePromptValue

Returns

Promise<unknown>

Defined in

langchain/src/chains/llm_chain.ts:68


apply

apply(inputs): Promise<ChainValues>

Call the chain on all inputs in the list

Parameters

NameType
inputsChainValues[]

Returns

Promise<ChainValues>

Inherited from

BaseChain.apply

Defined in

langchain/src/chains/base.ts:109


call

call(values): Promise<ChainValues>

Run the core logic of this chain and add to output if desired.

Wraps _call and handles memory.

Parameters

NameType
valuesChainValues

Returns

Promise<ChainValues>

Inherited from

BaseChain.call

Defined in

langchain/src/chains/base.ts:79


predict

predict(values): Promise<string>

Format prompt with values and pass to LLM

Example

llm.predict({ adjective: "funny" })

Parameters

NameTypeDescription
valuesChainValueskeys to pass to prompt template

Returns

Promise<string>

Completion from LLM.

Defined in

langchain/src/chains/llm_chain.ts:108


run

run(input): Promise<string>

Parameters

NameType
inputany

Returns

Promise<string>

Inherited from

BaseChain.run

Defined in

langchain/src/chains/base.ts:55


serialize

serialize(): SerializedLLMChain

Return a json-like object representing this chain.

Returns

SerializedLLMChain

Overrides

BaseChain.serialize

Defined in

langchain/src/chains/llm_chain.ts:132


deserialize

Static deserialize(data): Promise<LLMChain>

Load a chain from a json-like object describing it.

Parameters

NameType
dataSerializedLLMChain

Returns

Promise<LLMChain>

Overrides

BaseChain.deserialize

Defined in

langchain/src/chains/llm_chain.ts:117