langchain.js
    Preparing search index...

    Chain that generates key insights/facts of a user based on a a chat conversation with an AI.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    chatHistoryKey: string = "chat_history"
    jsonOutputParser: JsonOutputFunctionsParser
    llm: ChatOpenAI

    The LLM to use

    memory?: any
    retriever: BaseRetrieverInterface

    The retriever to use for retrieving stored thoughts and insights.

    stringOutputParser: StringOutputParser
    thoughtsKey: string = "thoughts"

    Accessors

    • get inputKeys(): string[]

      Returns string[]

    • get lc_namespace(): string[]

      Returns string[]

    • get outputKeys(): string[]

      Returns string[]

    Methods

    • This method processes a chat history to generate insights about the user.

      Parameters

      • values: ChainValues

        The input values for the chain. It should contain a key for chat history.

      • OptionalrunManager: any

        Optional callback manager for the chain run.

      Returns Promise<ChainValues>

      A promise that resolves to a list of insights about the user.

      If the chat history key is not found in the input values or if the chat history is not an array of BaseMessages.

      The method performs the following steps:

      1. Checks if the chat history key is present in the input values and if the chat history is an array of BaseMessages.
      2. Breaks the chat history into chunks of messages.
      3. For each chunk, it generates an initial prediction for the user's next message.
      4. For each prediction, it generates insights and prediction violations, and regenerates the prediction based on the violations.
      5. For each set of messages, it generates a fact/insight about the user. The method returns a list of these insights.
    • Return the string type key uniquely identifying this class of chain.

      Returns string

    • Parameters

      • values: any

      Returns Promise<any>

    • Parameters

      • inputs: ChainValues[]
      • Optionalconfig: any[]

      Returns Promise<ChainValues[]>

      Use .batch() instead. Will be removed in 0.2.0.

      Call the chain on all inputs in the list

    • Parameters

      • values: any
      • Optionalconfig: any
      • Optionaltags: string[]

      Returns Promise<ChainValues>

      Use .invoke() instead. Will be removed in 0.2.0.

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

      Wraps _call and handles memory.

    • This method breaks down the chat history into chunks of messages. Each chunk consists of a sequence of messages ending with an AI message and the subsequent user response, if any.

      Parameters

      • chatHistory: BaseMessage[]

        The chat history to be chunked.

      Returns MessageChunkResult[]

      An array of message chunks. Each chunk includes a sequence of messages and the subsequent user response.

      The method iterates over the chat history and pushes each message into a temporary array. When it encounters an AI message, it checks for a subsequent user message. If a user message is found, it is considered as the user response to the AI message. If no user message is found after the AI message, the user response is undefined. The method then pushes the chunk (sequence of messages and user response) into the result array. This process continues until all messages in the chat history have been processed.

    • Parameters

      • chatHistory: BaseMessage[]

      Returns string

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

      Parameters

      • input: ChainValues

        Input values for the chain run.

      • Optionaloptions: any

      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

      • strings: string[]

      Returns string[]

    • Parameters

      • input: any
      • Optionalconfig: any

      Returns Promise<string>

      Use .invoke() instead. Will be removed in 0.2.0.

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

      Parameters

      Returns Promise<BaseChain<ChainValues, ChainValues>>

    • Static method that creates a ViolationOfExpectationsChain instance from a ChatOpenAI and retriever. It also accepts optional options to customize the chain.

      Parameters

      • llm: ChatOpenAI

        The ChatOpenAI instance.

      • retriever: BaseRetrieverInterface

        The retriever used for similarity search.

      • Optionaloptions: Partial<Omit<ViolationOfExpectationsChainInput, "llm" | "retriever">>

        Optional options to customize the chain.

      Returns ViolationOfExpectationsChain

      A new instance of ViolationOfExpectationsChain.

    • Returns string