anthropicclient

package
v0.1.6-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL = "https://api.anthropic.com/v1"
)

Variables

View Source
var ErrEmptyResponse = errors.New("empty response")

ErrEmptyResponse is returned when the Anthropic API returns an empty response.

Functions

This section is empty.

Types

type Client

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

Client is a client for the Anthropic API.

func New

func New(token string, model string, baseURL string, httpClient Doer, opts ...Option) (*Client, error)

New returns a new Anthropic client.

func (*Client) CreateCompletion

func (c *Client) CreateCompletion(ctx context.Context, r *CompletionRequest) (*Completion, error)

CreateCompletion creates a completion.

type Completion

type Completion struct {
	Text string `json:"text"`
}

Completion is a completion.

type CompletionRequest

type CompletionRequest struct {
	Model       string   `json:"model"`
	Prompt      string   `json:"prompt"`
	Temperature float64  `json:"temperature"`
	MaxTokens   int      `json:"max_tokens_to_sample,omitempty"`
	StopWords   []string `json:"stop_sequences,omitempty"`
	TopP        float64  `json:"top_p,omitempty"`
	Stream      bool     `json:"stream,omitempty"`

	// StreamingFunc is a function to be called for each chunk of a streaming response.
	// Return an error to stop streaming early.
	StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"`
}

CompletionRequest is a request to create a completion.

type CompletionResponsePayload

type CompletionResponsePayload struct {
	Completion string `json:"completion,omitempty"`
	LogID      string `json:"log_id,omitempty"`
	Model      string `json:"model,omitempty"`
	Stop       string `json:"stop,omitempty"`
	StopReason string `json:"stop_reason,omitempty"`
}

type Doer

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

Doer performs a HTTP request.

type Option

type Option func(*Client) error

Option is an option for the Anthropic client.

func WithHTTPClient

func WithHTTPClient(client Doer) Option

WithHTTPClient allows setting a custom HTTP client.

Jump to

Keyboard shortcuts

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