anthropic

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 32 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

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

ConvertParametersToSchema converts parameters to Anthropic Schema format

func IsAnthropicDocumentMime

func IsAnthropicDocumentMime(mimeType string) bool

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

func IsImageMime

func IsImageMime(mimeType string) bool

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

func IsSupportedMime

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

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

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) Rerank

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

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

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

NewFileManager creates a new FileManager with the given client factory.

func (*FileManager) CachedCount

func (fm *FileManager) CachedCount() int

CachedCount returns the number of files currently cached.

func (*FileManager) Cleanup

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

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

CleanupAll removes all cached files from Anthropic.

func (*FileManager) Delete

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

Delete removes a file from Anthropic's storage.

func (*FileManager) GetOrUpload

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

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