Skip to content

Latest commit

 

History

History
269 lines (173 loc) · 17.2 KB

README.md

File metadata and controls

269 lines (173 loc) · 17.2 KB

Files

(files)

Overview

Files API

Available Operations

upload

Upload a file that can be used across various endpoints.

The size of individual files can be a maximum of 512 MB. The Fine-tuning API only supports .jsonl files.

Please contact us if you need to increase these storage limits.

Example Usage

from mistralai import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.files.upload(file={
        "file_name": "example.file",
        "content": open("example.file", "rb"),
    })

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
file models.File ✔️ The File object (not file name) to be uploaded.
To upload a file and specify a custom file name you should format your request as such:
bash<br/> file=@path/to/your/file.jsonl;filename=custom_name.jsonl<br/>
Otherwise, you can just keep the original file name:
bash<br/> file=@path/to/your/file.jsonl<br/>
purpose Optional[models.FilePurpose] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.UploadFileOut

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

list

Returns a list of files that belong to the user's organization.

Example Usage

from mistralai import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.files.list()

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
page Optional[int] N/A
page_size Optional[int] N/A
sample_type List[models.SampleType] N/A
source List[models.Source] N/A
search OptionalNullable[str] N/A
purpose OptionalNullable[models.FilePurpose] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ListFilesOut

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

retrieve

Returns information about a specific file.

Example Usage

from mistralai import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.files.retrieve(file_id="<value>")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
file_id str ✔️ N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.RetrieveFileOut

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

delete

Delete a file.

Example Usage

from mistralai import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.files.delete(file_id="<value>")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
file_id str ✔️ N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.DeleteFileOut

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

download

Download a file

Example Usage

from mistralai import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.files.download(file_id="<id>")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
file_id str ✔️ N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

httpx.Response

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*

get_signed_url

Get Signed Url

Example Usage

from mistralai import Mistral
import os

with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.files.get_signed_url(file_id="<id>")

    assert res is not None

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
file_id str ✔️ N/A
expiry Optional[int] Number of hours before the url becomes invalid. Defaults to 24h
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.FileSignedURL

Errors

Error Type Status Code Content Type
models.SDKError 4XX, 5XX */*