Skip to contents

Generate text completions using Anthropic's API

Usage

create_completion_anthropic(
  prompt = list(list(role = "user", content = "Hello")),
  system = NULL,
  model = "claude-3-haiku-20240307",
  max_tokens = 1028,
  key = Sys.getenv("ANTHROPIC_API_KEY")
)

Arguments

prompt

The prompt for generating completions

system

A system messages to instruct the model. Defaults to NULL.

model

The model to use for generating text. By default, the function will try to use "claude-2.1".

max_tokens

The maximum number of tokens to generate. Defaults to 256.

key

The API key for accessing Anthropic's API. By default, the function will try to use the ANTHROPIC_API_KEY environment variable.

Value

A list with the generated completions and other information returned by the API.

Examples

if (FALSE) {
create_completion_anthropic(
  prompt = "\n\nHuman: Hello, world!\n\nAssistant:",
  model = "claude-3-haiku-20240307",
  max_tokens = 1028
)
}