Class MultiPromptChain

A class that represents a multi-prompt chain in the LangChain framework. It extends the MultiRouteChain class and provides additional functionality specific to multi-prompt chains.

Example

const multiPromptChain = MultiPromptChain.fromLLMAndPrompts(new ChatOpenAI(), {
promptNames: ["physics", "math", "history"],
promptDescriptions: [
"Good for answering questions about physics",
"Good for answering math questions",
"Good for answering questions about history",
],
promptTemplates: [
`You are a very smart physics professor. Here is a question:\n{input}\n`,
`You are a very good mathematician. Here is a question:\n{input}\n`,
`You are a very smart history professor. Here is a question:\n{input}\n`,
],
});
const result = await multiPromptChain.call({
input: "What is the speed of light?",
});

Hierarchy

Constructors

Properties

defaultChain: BaseChain<ChainValues, ChainValues>
destinationChains: {
    [name: string]: BaseChain;
}

Type declaration

routerChain: RouterChain
silentErrors: boolean = false
memory?: BaseMemory

Accessors

  • get inputKeys(): string[]
  • Returns string[]

  • get outputKeys(): string[]
  • Returns string[]

Methods

  • Call the chain on all inputs in the list

    Parameters

    • inputs: ChainValues[]
    • Optional config: (BaseCallbackConfig | Callbacks)[]

    Returns Promise<ChainValues[]>

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

    Wraps _call and handles memory.

    Parameters

    • values: ChainValues & {
          signal?: AbortSignal;
          timeout?: number;
      }
    • Optional config: BaseCallbackConfig | Callbacks
    • Optional tags: string[]

      Deprecated

    Returns Promise<ChainValues>

  • Invoke the chain with the provided input and returns the output.

    Parameters

    • input: ChainValues

      Input values for the chain run.

    • Optional config: BaseCallbackConfig

      Optional configuration for the Runnable.

    Returns Promise<ChainValues>

    Promise that resolves with the output of the chain run.

  • Parameters

    • inputs: Record<string, unknown>
    • outputs: Record<string, unknown>
    • returnOnlyOutputs: boolean = false

    Returns Promise<Record<string, unknown>>

  • Parameters

    • input: any
    • Optional config: BaseCallbackConfig | Callbacks

    Returns Promise<string>

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

    Parameters

    Returns Promise<BaseChain<ChainValues, ChainValues>>

  • A static method that creates an instance of MultiPromptChain from a BaseLanguageModel and a set of prompts. It takes in optional parameters for the default chain and additional options.

    Parameters

    • llm: BaseLanguageModel<any, BaseLanguageModelCallOptions>

      A BaseLanguageModel instance.

    • __namedParameters: {
          promptDescriptions: string[];
          promptNames: string[];
          promptTemplates: string[] | PromptTemplate<any, any>[];
          conversationChainOpts?: Omit<LLMChainInput<string, LLMType>, "llm" | "outputKey">;
          defaultChain?: BaseChain<ChainValues, ChainValues>;
          llmChainOpts?: Omit<LLMChainInput<string, LLMType>, "llm" | "prompt">;
          multiRouteChainOpts?: Omit<MultiRouteChainInput, "defaultChain">;
      }
      • promptDescriptions: string[]
      • promptNames: string[]
      • promptTemplates: string[] | PromptTemplate<any, any>[]
      • Optional conversationChainOpts?: Omit<LLMChainInput<string, LLMType>, "llm" | "outputKey">
      • Optional defaultChain?: BaseChain<ChainValues, ChainValues>
      • Optional llmChainOpts?: Omit<LLMChainInput<string, LLMType>, "llm" | "prompt">
      • Optional multiRouteChainOpts?: Omit<MultiRouteChainInput, "defaultChain">

    Returns MultiPromptChain

    An instance of MultiPromptChain.

  • Parameters

    • llm: BaseLanguageModel<any, BaseLanguageModelCallOptions>
    • promptNames: string[]
    • promptDescriptions: string[]
    • promptTemplates: string[] | PromptTemplate<any, any>[]
    • Optional defaultChain: BaseChain<ChainValues, ChainValues>
    • Optional options: Omit<MultiRouteChainInput, "defaultChain">

    Returns MultiPromptChain

    Deprecated

    Use fromLLMAndPrompts instead

Generated using TypeDoc