Documentation
¶
Index ¶
- Variables
- func ConvertParametersToSchema(params any) (anthropic.ToolInputSchemaParam, error)
- func IsAnthropicDocumentMime(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) 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 ¶
func ConvertParametersToSchema(params any) (anthropic.ToolInputSchemaParam, error)
ConvertParametersToSchema converts parameters to Anthropic Schema format
func IsAnthropicDocumentMime ¶
IsAnthropicDocumentMime returns true if the MIME type is a document type supported by Anthropic.
func IsImageMime ¶
IsImageMime returns true if the MIME type is an image type supported by Anthropic.
func IsSupportedMime ¶
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 ¶
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 ¶
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 ¶
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.