anthropic

package
v1.20.6 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileManagerNotInitialized = errors.New("file manager not initialized")

ErrFileManagerNotInitialized is returned when file operations are attempted without a FileManager.

View Source
var ErrUnsupportedFileType = errors.New("unsupported file type for Anthropic Files API")

ErrUnsupportedFileType is returned when a file type is not supported by the Files API.

Functions

func ConvertParametersToSchema added in v1.7.0

func ConvertParametersToSchema(params any) (anthropic.ToolInputSchemaParam, error)

ConvertParametersToSchema converts parameters to Anthropic Schema format

func IsDocumentMime added in v1.20.6

func IsDocumentMime(mimeType string) bool

IsDocumentMime returns true if the MIME type is a document type supported by Anthropic.

func IsImageMime added in v1.20.6

func IsImageMime(mimeType string) bool

IsImageMime returns true if the MIME type is an image type supported by Anthropic.

func IsSupportedMime added in v1.20.6

func IsSupportedMime(mimeType string) bool

IsSupportedMime returns true if the MIME type is supported by Anthropic's Files API.

Types

type Client

type Client struct {
	base.Config
	// contains filtered or unexported fields
}

Client represents an Anthropic client wrapper implementing provider.Provider It holds the anthropic client and model config

func NewClient

func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (*Client, error)

NewClient creates a new Anthropic client from the provided configuration

func (*Client) CleanupFiles added in v1.20.6

func (c *Client) CleanupFiles(ctx context.Context) error

CleanupFiles removes all files uploaded during this session from Anthropic's storage.

func (*Client) CreateChatCompletionStream

func (c *Client) CreateChatCompletionStream(
	ctx context.Context,
	messages []chat.Message,
	requestTools []tools.Tool,
) (chat.MessageStream, error)

CreateChatCompletionStream creates a streaming chat completion request

func (*Client) FileManager added in v1.20.6

func (c *Client) FileManager() *FileManager

FileManager returns the file manager for this client, allowing external cleanup. Returns nil if file uploads are not supported or not initialized.

func (*Client) ID

func (c *Client) ID() string

func (*Client) Rerank added in v1.8.2

func (c *Client) Rerank(ctx context.Context, query string, documents []types.Document, criteria string) ([]float64, error)

Rerank scores documents by relevance to the query using Anthropic's Beta Messages API with structured outputs. It returns relevance scores in the same order as input documents.

type FileManager added in v1.20.6

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

FileManager manages file uploads to Anthropic's Files API. It provides deduplication, caching, and TTL-based cleanup. Thread-safe for concurrent use.

func NewFileManager added in v1.20.6

func NewFileManager(clientFn func(context.Context) (anthropic.Client, error)) *FileManager

NewFileManager creates a new FileManager with the given client factory.

func (*FileManager) CachedCount added in v1.20.6

func (fm *FileManager) CachedCount() int

CachedCount returns the number of files currently cached.

func (*FileManager) Cleanup added in v1.20.6

func (fm *FileManager) Cleanup(ctx context.Context, ttl time.Duration) error

Cleanup removes files older than the specified TTL from both Anthropic and the cache.

func (*FileManager) CleanupAll added in v1.20.6

func (fm *FileManager) CleanupAll(ctx context.Context) error

CleanupAll removes all cached files from Anthropic.

func (*FileManager) Delete added in v1.20.6

func (fm *FileManager) Delete(ctx context.Context, fileID string) error

Delete removes a file from Anthropic's storage.

func (*FileManager) GetOrUpload added in v1.20.6

func (fm *FileManager) GetOrUpload(ctx context.Context, filePath string) (*UploadedFile, error)

GetOrUpload returns an existing upload for the file or uploads it if not cached. Files are deduplicated by content hash AND MIME type, so identical files with different extensions will be uploaded separately. Concurrent calls for the same file will wait for a single upload to complete.

type UploadedFile added in v1.20.6

type UploadedFile struct {
	FileID      string
	Filename    string
	MimeType    string
	SizeBytes   int64
	UploadedAt  time.Time
	LocalPath   string
	ContentHash string
}

UploadedFile represents a file that has been uploaded to Anthropic.

Jump to

Keyboard shortcuts

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