Behaviour for uploading files to LLM providers.
Provides a unified interface for uploading files to OpenAI, Anthropic,
and Google Gemini. Each provider returns a LangChain.FileUploader.FileResult
containing the file reference needed for subsequent API calls.
Usage
# OpenAI
{:ok, uploader} = LangChain.FileUploader.FileOpenAI.new(%{api_key: "sk-..."})
{:ok, result} = LangChain.FileUploader.upload(uploader, file_bytes, %{
filename: "doc.pdf",
mime_type: "application/pdf"
})
result.file_id
#=> "file-abc123"
# Google Gemini
{:ok, uploader} = LangChain.FileUploader.FileGoogle.new(%{api_key: "AI..."})
{:ok, result} = LangChain.FileUploader.upload(uploader, file_bytes, %{
filename: "doc.pdf",
mime_type: "application/pdf"
})
result.file_uri
#=> "https://generativelanguage.googleapis.com/v1beta/files/..."File Metadata
The file_meta map passed to upload/3 accepts the following keys:
:filename(required) - The name to give the uploaded file.:mime_type(required) - The MIME type of the file content.:purpose- Provider-specific purpose string. Used by OpenAI (e.g."user_data","assistants"). Ignored by other providers.:display_name- A human-readable display name. Used by Google. Falls back to:filenameif not provided.
Summary
Callbacks
Delete a previously uploaded file by its ID or URI.
Retrieve metadata for a previously uploaded file by its ID.
List files previously uploaded to the provider.
Upload file bytes to the provider and return a FileResult on success.
Functions
Delete a file using any configured uploader implementation.
Retrieve file metadata using any configured uploader implementation.
List files using any configured uploader implementation.
Upload a file using any configured uploader implementation.
Types
@type delete_result() :: :ok | {:error, LangChain.LangChainError.t()}
@type get_result() :: {:ok, LangChain.FileUploader.FileResult.t()} | {:error, LangChain.LangChainError.t()}
@type list_result() :: {:ok, [LangChain.FileUploader.FileResult.t()]} | {:error, LangChain.LangChainError.t()}
@type upload_result() :: {:ok, LangChain.FileUploader.FileResult.t()} | {:error, LangChain.LangChainError.t()}
Callbacks
@callback delete( config :: struct(), file_ref :: LangChain.FileUploader.FileResult.t() | String.t() ) :: delete_result()
Delete a previously uploaded file by its ID or URI.
@callback get( config :: struct(), file_ref :: LangChain.FileUploader.FileResult.t() | String.t() ) :: get_result()
Retrieve metadata for a previously uploaded file by its ID.
@callback list(config :: struct()) :: list_result()
List files previously uploaded to the provider.
@callback upload(config :: struct(), file_bytes :: binary(), file_meta :: file_meta()) :: upload_result()
Upload file bytes to the provider and return a FileResult on success.
Functions
@spec delete( struct(), LangChain.FileUploader.FileResult.t() | String.t() ) :: delete_result()
Delete a file using any configured uploader implementation.
Returns an error if the provider does not implement delete/2.
@spec get( struct(), LangChain.FileUploader.FileResult.t() | String.t() ) :: get_result()
Retrieve file metadata using any configured uploader implementation.
Returns an error if the provider does not implement get/2.
@spec list(struct()) :: list_result()
List files using any configured uploader implementation.
Returns an error if the provider does not implement list/1.
@spec upload(struct(), binary(), file_meta()) :: upload_result()
Upload a file using any configured uploader implementation.
Delegates to the provider module's upload/3 callback.