Class Chain

java.lang.Object
com.hw.langchain.chains.base.Chain
Direct Known Subclasses:
AgentExecutor, ApiChain, BaseCombineDocumentsChain, BaseRetrievalQA, LLMChain, LLMMathChain, SQLDatabaseChain, SQLDatabaseSequentialChain

public abstract class Chain extends Object
Base interface that all chains should implement.
Author:
HamaWhite
  • Field Details

  • Constructor Details

    • Chain

      public Chain()
  • Method Details

    • chainType

      public abstract String chainType()
    • inputKeys

      public abstract List<String> inputKeys()
      Retrieves the list of input keys that this chain expects.
      Returns:
      the list of input keys
    • outputKeys

      public abstract List<String> outputKeys()
      Retrieves the list of output keys that this chain expects.
      Returns:
      the list of output keys
    • innerCall

      protected abstract Map<String,String> innerCall(Map<String,Object> inputs)
      Runs the logic of this chain and returns the output.
      Parameters:
      inputs - the inputs to be processed by the chain
      Returns:
      a map containing the output generated by the chain
    • asyncInnerCall

      protected reactor.core.publisher.Flux<Map<String,String>> asyncInnerCall(Map<String,Object> inputs)
      Runs the logic of this chain and returns the async output.
      Parameters:
      inputs - the inputs to be processed by the chain
      Returns:
      a map flux containing the output generated event by the chain
    • call

      public Map<String,String> call(Object input, boolean returnOnlyOutputs)
      Run the logic of this chain and add to output if desired.
      Parameters:
      input - single input if chain expects only one param.
      returnOnlyOutputs - boolean for whether to return only outputs in the response. If True, only new keys generated by this chain will be returned. If False, both input keys and new keys generated by this chain will be returned. Defaults to False.
    • call

      public Map<String,String> call(Map<String,Object> inputs, boolean returnOnlyOutputs)
      Run the logic of this chain and add to output if desired.
      Parameters:
      inputs - Dictionary of inputs.
      returnOnlyOutputs - boolean for whether to return only outputs in the response. If True, only new keys generated by this chain will be returned. If False, both input keys and new keys generated by this chain will be returned. Defaults to False.
    • asyncCall

      public reactor.core.publisher.Flux<Map<String,String>> asyncCall(Object input, boolean returnOnlyOutputs)
    • asyncCall

      public reactor.core.publisher.Flux<Map<String,String>> asyncCall(Map<String,Object> inputs, boolean returnOnlyOutputs)
    • prepInputs

      public Map<String,Object> prepInputs(Map<String,Object> inputs)
      Validate and prep inputs.
    • run

      public String run(Object args)
      Run the chain as text in, text out
    • run

      public String run(Map<String,Object> args)
      Run the chain as multiple variables, text out.
    • asyncRun

      public reactor.core.publisher.Flux<String> asyncRun(Object args)
      Run the chain as text in, text out async
    • asyncRun

      public reactor.core.publisher.Flux<String> asyncRun(Map<String,Object> args)
      Run the chain as multiple variables, text out async.