anthropic

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package anthropic implements the Anthropic provider.

Index

Constants

View Source
const Name = "anthropic"

Name of the provider.

Variables

This section is empty.

Functions

func Get

func Get() provider.IProvider

Get returns a setup MongoDB, or set it up.

func ProcessResponse

func ProcessResponse(resp ResponseBody) (string, error)

ProcessResponse processes the response from the API.

func Set

func Set(s provider.IProvider)

Set sets the provider, primarily used for testing.

Types

type Anthropic

type Anthropic struct {
	*provider.Provider

	// Endpoint of the LLM provider.
	Endpoint string `json:"url" validate:"required"`

	// Token of the LLM provider.
	Token string `json:"-" validate:"required"`
	// contains filtered or unexported fields
}

Anthropic provider definition.

func New

func New(
	options ...provider.ClientFunc,
) (*Anthropic, error)

New creates a new Anthropic provider.

func NewDefault

func NewDefault(options ...provider.ClientFunc) (*Anthropic, error)

NewDefault creates a new Anthropic provider with default values.

func (*Anthropic) Completion

func (p *Anthropic) Completion(ctx context.Context, options ...provider.Func) (string, error)

Completion generates a completion using the provider API. Optionally pass WithResponseBody to unmarshal the response body. It will always return the original, unparsed response body, if no error.

NOTE: Not all options are available for all providers.

func (*Anthropic) GetClient

func (p *Anthropic) GetClient() any

GetClient returns the client.

type Content

type Content struct {
	Text string `json:"text"`
	Type string `json:"type"`
}

Content definition.

type RequestBody

type RequestBody struct {
	Messages []message.Message `json:"messages"`
	Model    string            `json:"model"`
	Stream   bool              `json:"stream"`

	MaxTokens   int     `json:"max_tokens,omitempty"`
	System      string  `json:"system,omitempty"`
	Temperature float64 `json:"temperature,omitempty"`
	TopK        int     `json:"top_k,omitempty"`
	TopP        float64 `json:"top_p,omitempty"`
}

RequestBody represents the request body for the API.

type ResponseBody

type ResponseBody struct {
	Content      []Content `json:"content"`
	ID           string    `json:"id"`
	Model        string    `json:"model"`
	Role         string    `json:"role"`
	StopReason   string    `json:"stop_reason"`
	StopSequence any       `json:"stop_sequence"`
	Type         string    `json:"type"`
	Usage        Usage     `json:"usage"`
}

ResponseBody represents the response body from the API.

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage definition.

Jump to

Keyboard shortcuts

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