Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.8"
".": "0.1.0-alpha.9"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.9 (2025-01-05)

Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.1.0-alpha.8...v0.1.0-alpha.9)

### Features

* **api:** update via SDK Studio ([#37](https://github.com/mixedbread-ai/mixedbread-python/issues/37)) ([10c8c52](https://github.com/mixedbread-ai/mixedbread-python/commit/10c8c528a68b765bbc5c01d0cca990c5c52544d2))

## 0.1.0-alpha.8 (2025-01-05)

Full Changelog: [v0.1.0-alpha.7...v0.1.0-alpha.8](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.1.0-alpha.7...v0.1.0-alpha.8)
Expand Down
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Methods:
- <code title="post /v1/files/{file_id}">client.files.<a href="./src/mixedbread/resources/files.py">update</a>(file_id, \*\*<a href="src/mixedbread/types/file_update_params.py">params</a>) -> <a href="./src/mixedbread/types/file_object.py">FileObject</a></code>
- <code title="get /v1/files">client.files.<a href="./src/mixedbread/resources/files.py">list</a>(\*\*<a href="src/mixedbread/types/file_list_params.py">params</a>) -> <a href="./src/mixedbread/types/file_object.py">SyncPage[FileObject]</a></code>
- <code title="delete /v1/files/{file_id}">client.files.<a href="./src/mixedbread/resources/files.py">delete</a>(file_id) -> <a href="./src/mixedbread/types/file_delete_response.py">FileDeleteResponse</a></code>
- <code title="get /v1/files/{file_id}/content">client.files.<a href="./src/mixedbread/resources/files.py">content</a>(file_id) -> BinaryAPIResponse</code>

# VectorStores

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mixedbread"
version = "0.1.0-alpha.8"
version = "0.1.0-alpha.9"
description = "The official Python library for the mixedbread API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/mixedbread/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "mixedbread"
__version__ = "0.1.0-alpha.8" # x-release-please-version
__version__ = "0.1.0-alpha.9" # x-release-please-version
104 changes: 104 additions & 0 deletions src/mixedbread/resources/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
BinaryAPIResponse,
AsyncBinaryAPIResponse,
StreamedBinaryAPIResponse,
AsyncStreamedBinaryAPIResponse,
to_raw_response_wrapper,
to_streamed_response_wrapper,
async_to_raw_response_wrapper,
to_custom_raw_response_wrapper,
async_to_streamed_response_wrapper,
to_custom_streamed_response_wrapper,
async_to_custom_raw_response_wrapper,
async_to_custom_streamed_response_wrapper,
)
from ..pagination import SyncPage, AsyncPage
from .._base_client import AsyncPaginator, make_request_options
Expand Down Expand Up @@ -274,6 +282,46 @@ def delete(
cast_to=FileDeleteResponse,
)

def content(
self,
file_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> BinaryAPIResponse:
"""
Download a specific file by its ID.

Args: file_id: The ID of the file to download.

Returns: FileStreamResponse: The response containing the file to be downloaded.

Args:
file_id: The ID of the file to download

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
if not file_id:
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
return self._get(
f"/v1/files/{file_id}/content",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=BinaryAPIResponse,
)


class AsyncFilesResource(AsyncAPIResource):
@cached_property
Expand Down Expand Up @@ -519,6 +567,46 @@ async def delete(
cast_to=FileDeleteResponse,
)

async def content(
self,
file_id: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> AsyncBinaryAPIResponse:
"""
Download a specific file by its ID.

Args: file_id: The ID of the file to download.

Returns: FileStreamResponse: The response containing the file to be downloaded.

Args:
file_id: The ID of the file to download

extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
if not file_id:
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
return await self._get(
f"/v1/files/{file_id}/content",
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=AsyncBinaryAPIResponse,
)


class FilesResourceWithRawResponse:
def __init__(self, files: FilesResource) -> None:
Expand All @@ -539,6 +627,10 @@ def __init__(self, files: FilesResource) -> None:
self.delete = to_raw_response_wrapper(
files.delete,
)
self.content = to_custom_raw_response_wrapper(
files.content,
BinaryAPIResponse,
)


class AsyncFilesResourceWithRawResponse:
Expand All @@ -560,6 +652,10 @@ def __init__(self, files: AsyncFilesResource) -> None:
self.delete = async_to_raw_response_wrapper(
files.delete,
)
self.content = async_to_custom_raw_response_wrapper(
files.content,
AsyncBinaryAPIResponse,
)


class FilesResourceWithStreamingResponse:
Expand All @@ -581,6 +677,10 @@ def __init__(self, files: FilesResource) -> None:
self.delete = to_streamed_response_wrapper(
files.delete,
)
self.content = to_custom_streamed_response_wrapper(
files.content,
StreamedBinaryAPIResponse,
)


class AsyncFilesResourceWithStreamingResponse:
Expand All @@ -602,3 +702,7 @@ def __init__(self, files: AsyncFilesResource) -> None:
self.delete = async_to_streamed_response_wrapper(
files.delete,
)
self.content = async_to_custom_streamed_response_wrapper(
files.content,
AsyncStreamedBinaryAPIResponse,
)
120 changes: 120 additions & 0 deletions tests/api_resources/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
import os
from typing import Any, cast

import httpx
import pytest
from respx import MockRouter

from mixedbread import Mixedbread, AsyncMixedbread
from tests.utils import assert_matches_type
from mixedbread.types import FileObject, FileDeleteResponse
from mixedbread._response import (
BinaryAPIResponse,
AsyncBinaryAPIResponse,
StreamedBinaryAPIResponse,
AsyncStreamedBinaryAPIResponse,
)
from mixedbread.pagination import SyncPage, AsyncPage

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
Expand Down Expand Up @@ -200,6 +208,62 @@ def test_path_params_delete(self, client: Mixedbread) -> None:
"",
)

@parametrize
@pytest.mark.respx(base_url=base_url)
def test_method_content(self, client: Mixedbread, respx_mock: MockRouter) -> None:
respx_mock.get("/v1/files/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/content").mock(
return_value=httpx.Response(200, json={"foo": "bar"})
)
file = client.files.content(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
assert file.is_closed
assert file.json() == {"foo": "bar"}
assert cast(Any, file.is_closed) is True
assert isinstance(file, BinaryAPIResponse)

@parametrize
@pytest.mark.respx(base_url=base_url)
def test_raw_response_content(self, client: Mixedbread, respx_mock: MockRouter) -> None:
respx_mock.get("/v1/files/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/content").mock(
return_value=httpx.Response(200, json={"foo": "bar"})
)

file = client.files.with_raw_response.content(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)

assert file.is_closed is True
assert file.http_request.headers.get("X-Stainless-Lang") == "python"
assert file.json() == {"foo": "bar"}
assert isinstance(file, BinaryAPIResponse)

@parametrize
@pytest.mark.respx(base_url=base_url)
def test_streaming_response_content(self, client: Mixedbread, respx_mock: MockRouter) -> None:
respx_mock.get("/v1/files/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/content").mock(
return_value=httpx.Response(200, json={"foo": "bar"})
)
with client.files.with_streaming_response.content(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
) as file:
assert not file.is_closed
assert file.http_request.headers.get("X-Stainless-Lang") == "python"

assert file.json() == {"foo": "bar"}
assert cast(Any, file.is_closed) is True
assert isinstance(file, StreamedBinaryAPIResponse)

assert cast(Any, file.is_closed) is True

@parametrize
@pytest.mark.respx(base_url=base_url)
def test_path_params_content(self, client: Mixedbread) -> None:
with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
client.files.with_raw_response.content(
"",
)


class TestAsyncFiles:
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
Expand Down Expand Up @@ -385,3 +449,59 @@ async def test_path_params_delete(self, async_client: AsyncMixedbread) -> None:
await async_client.files.with_raw_response.delete(
"",
)

@parametrize
@pytest.mark.respx(base_url=base_url)
async def test_method_content(self, async_client: AsyncMixedbread, respx_mock: MockRouter) -> None:
respx_mock.get("/v1/files/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/content").mock(
return_value=httpx.Response(200, json={"foo": "bar"})
)
file = await async_client.files.content(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)
assert file.is_closed
assert await file.json() == {"foo": "bar"}
assert cast(Any, file.is_closed) is True
assert isinstance(file, AsyncBinaryAPIResponse)

@parametrize
@pytest.mark.respx(base_url=base_url)
async def test_raw_response_content(self, async_client: AsyncMixedbread, respx_mock: MockRouter) -> None:
respx_mock.get("/v1/files/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/content").mock(
return_value=httpx.Response(200, json={"foo": "bar"})
)

file = await async_client.files.with_raw_response.content(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
)

assert file.is_closed is True
assert file.http_request.headers.get("X-Stainless-Lang") == "python"
assert await file.json() == {"foo": "bar"}
assert isinstance(file, AsyncBinaryAPIResponse)

@parametrize
@pytest.mark.respx(base_url=base_url)
async def test_streaming_response_content(self, async_client: AsyncMixedbread, respx_mock: MockRouter) -> None:
respx_mock.get("/v1/files/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/content").mock(
return_value=httpx.Response(200, json={"foo": "bar"})
)
async with async_client.files.with_streaming_response.content(
"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
) as file:
assert not file.is_closed
assert file.http_request.headers.get("X-Stainless-Lang") == "python"

assert await file.json() == {"foo": "bar"}
assert cast(Any, file.is_closed) is True
assert isinstance(file, AsyncStreamedBinaryAPIResponse)

assert cast(Any, file.is_closed) is True

@parametrize
@pytest.mark.respx(base_url=base_url)
async def test_path_params_content(self, async_client: AsyncMixedbread) -> None:
with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
await async_client.files.with_raw_response.content(
"",
)