Class ChatAnthropic<CallOptions>

Wrapper around Anthropic large language models.

To use you should have the @anthropic-ai/sdk package installed, with the ANTHROPIC_API_KEY environment variable set.

Remarks

Any parameters that are valid to be passed to anthropic.complete can be passed through invocationKwargs, even if not explicitly available on this class.

Type Parameters

Hierarchy

Implements

Constructors

Properties

CallOptions: CallOptions
ParsedCallOptions: Omit<CallOptions, never>
caller: AsyncCaller

The async caller should be used by subclasses to make any async calls, which will thus benefit from the concurrency and retry logic.

clientOptions: ClientOptions

Overridable Anthropic ClientOptions

maxTokensToSample: number = 2048

A maximum number of tokens to generate before stopping.

modelName: string = "claude-2"

Model name to use

streaming: boolean = false

Whether to stream the results or not

temperature: number = 1

Amount of randomness injected into the response. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and temp closer to 1 for creative and generative tasks.

topK: number = -1

Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Defaults to -1, which disables it.

topP: number = -1

Does nucleus sampling, in which we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. Defaults to -1, which disables it. Note that you should either alter temperature or top_p, but not both.

verbose: boolean

Whether to print out response text.

anthropicApiKey?: string

Anthropic API key

apiUrl?: string
callbacks?: Callbacks
invocationKwargs?: Kwargs

Holds any additional parameters that are valid to pass to anthropic.complete that are not explicitly specified on this class.

metadata?: Record<string, unknown>
stopSequences?: string[]

A list of strings upon which to stop generating. You probably want ["\n\nHuman:"], as that's the cue for the next turn in the dialog agent.

tags?: string[]
batchClient: Anthropic
lc_runnable: boolean = true
streamingClient: Anthropic

Accessors

Methods

  • Generates chat based on the input messages.

    Parameters

    • messages: BaseMessageLike[][]

      An array of arrays of BaseMessage instances.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<LLMResult>

    A Promise that resolves to an LLMResult.

  • Get the identifying parameters for the model

    Returns {
        model_name: string;
    }

    • model_name: string
  • Predicts the next message based on a text input.

    Parameters

    • text: string

      The text input.

    • Optional options: string[] | CallOptions

      The call options or an array of stop sequences.

    • Optional callbacks: Callbacks

      The callbacks for the language model.

    Returns Promise<string>

    A Promise that resolves to a string.

  • Stream all output from a runnable, as reported to the callback system. This includes all inner runs of LLMs, Retrievers, Tools, etc. Output is streamed as Log objects, which include a list of jsonpatch ops that describe how the state of the run has changed in each step, and the final state of the run. The jsonpatch ops can be applied in order to construct state.

    Parameters

    • input: BaseLanguageModelInput
    • Optional options: Partial<CallOptions>
    • Optional streamOptions: Omit<LogStreamCallbackHandlerInput, "autoClose">

    Returns AsyncGenerator<RunLogPatch, any, unknown>

  • Helper method to transform an Iterator of Input values into an Iterator of Output values, with callbacks. Use this to implement stream() or transform() in Runnable subclasses.

    Type Parameters

    Parameters

    • inputGenerator: AsyncGenerator<I, any, unknown>
    • transformer: ((generator, runManager?, options?) => AsyncGenerator<O, any, unknown>)
        • (generator, runManager?, options?): AsyncGenerator<O, any, unknown>
        • Parameters

          • generator: AsyncGenerator<I, any, unknown>
          • Optional runManager: CallbackManagerForChainRun
          • Optional options: Partial<CallOptions>

          Returns AsyncGenerator<O, any, unknown>

    • Optional options: CallOptions & {
          runType?: string;
      }

    Returns AsyncGenerator<O, any, unknown>

  • Creates a streaming request with retry.

    Parameters

    • request: Object

      The parameters for creating a completion.

    Returns Promise<Stream<Completion>>

    A streaming request.

Generated using TypeDoc