anthropic

package
v0.0.104 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HumanPrompt is the string used to indicate a human message in the conversation.
	HumanPrompt = "\n\nHuman:"

	// AIPrompt is the string used to indicate an assistant message in the conversation.
	AIPrompt = "\n\nAssistant:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the Anthropic API client.

func New

func New(apiKey string, optFns ...func(o *Options)) *Client

New creates a new instance of the Anthropic API client with the given API key and optional configuration options.

func (*Client) CreateCompletion added in v0.0.56

func (c *Client) CreateCompletion(ctx context.Context, request *CompletionRequest) (*CompletionResponse, error)

CreateCompletion sends a text completion request to the Anthropic API and returns the response.

type CompletionRequest

type CompletionRequest struct {
	// The input prompt for the completion.
	Prompt string `json:"prompt"`
	// The temperature for randomness in sampling.
	Temperature float32 `json:"temperature,omitempty"`
	// The maximum number of tokens to sample.
	MaxTokens int `json:"max_tokens_to_sample"`
	// List of strings to stop generation at.
	Stop []string `json:"stop_sequences"`
	// The number of highest probability tokens to use in sampling.
	TopK int `json:"top_k,omitempty"`
	// The cumulative probability for nucleus sampling.
	TopP float32 `json:"top_p,omitempty"`
	// The model to use for completion.
	Model string `json:"model"`
	// Additional tags for the completion.
	Tags map[string]string `json:"tags,omitempty"`
	// Flag to enable streaming response.
	Stream bool `json:"stream"`
}

CompletionRequest represents a request to the Anthropic API for text completion.

type CompletionResponse

type CompletionResponse struct {
	// The generated completion text.
	Completion string `json:"completion"`
	// The stop sequence that caused generation to stop.
	Stop string `json:"stop"`
	// The reason for stopping generation.
	StopReason string `json:"stop_reason"`
	// Flag indicating if the generated completion was truncated.
	Truncated bool `json:"truncated"`
	// The exception message if an error occurred during generation.
	Exception string `json:"exception"`
	// The log ID for the API request.
	LogID string `json:"log_id"`
}

CompletionResponse represents the response from the Anthropic API for text completion.

type HTTPClient added in v0.0.56

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is an interface for making HTTP requests.

type Options

type Options struct {
	// The base URL of the Anthropic API.
	APIUrl string

	// The version of the Anthropic API to use.
	Version string

	// The SDK identifier used in the API requests.
	SDK string

	// The HTTP client to use for making API requests.
	HTTPClient HTTPClient
}

Options represents the configuration options for the Anthropic client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL