Documentation
¶
Index ¶
- Variables
- func ConvertParametersToSchema(params any) (anthropic.ToolInputSchemaParam, error)
- func IsDocumentMime(mimeType string) bool
- func IsImageMime(mimeType string) bool
- func IsSupportedMime(mimeType string) bool
- type Client
- func (c *Client) CleanupFiles(ctx context.Context) error
- func (c *Client) CreateChatCompletionStream(ctx context.Context, messages []chat.Message, requestTools []tools.Tool) (chat.MessageStream, error)
- func (c *Client) FileManager() *FileManager
- func (c *Client) ID() string
- func (c *Client) Rerank(ctx context.Context, query string, documents []types.Document, criteria string) ([]float64, error)
- type FileManager
- func (fm *FileManager) CachedCount() int
- func (fm *FileManager) Cleanup(ctx context.Context, ttl time.Duration) error
- func (fm *FileManager) CleanupAll(ctx context.Context) error
- func (fm *FileManager) Delete(ctx context.Context, fileID string) error
- func (fm *FileManager) GetOrUpload(ctx context.Context, filePath string) (*UploadedFile, error)
- type UploadedFile
Constants ¶
This section is empty.
Variables ¶
var ErrFileManagerNotInitialized = errors.New("file manager not initialized")
ErrFileManagerNotInitialized is returned when file operations are attempted without a FileManager.
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
IsDocumentMime returns true if the MIME type is a document type supported by Anthropic.
func IsImageMime ¶ added in v1.20.6
IsImageMime returns true if the MIME type is an image type supported by Anthropic.
func IsSupportedMime ¶ added in v1.20.6
IsSupportedMime returns true if the MIME type is supported by Anthropic's Files API.
Types ¶
type Client ¶
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
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) 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
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
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.