Skip to content
Merged
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 VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.5.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "arkruntime"
version = "0.4.0"
version = "0.5.0"
description = "Ark runtime SDK for Python"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
16 changes: 12 additions & 4 deletions src/arkruntime/resources/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def with_streaming_response(self) -> "FilesWithStreamingResponse":
def create(
self,
*,
file: FileTypes,
file: Optional[FileTypes] = None,
# AUTOGEN-START create-kwargs
purpose: Purpose,
preprocess_configs: Optional[PreprocessConfigsParam] = None,
Expand All @@ -84,9 +84,11 @@ def create(
Mutually exclusive with `file`.
tos: User-owned TOS bucket destination.
"""
if (file is None) == (url is None):
raise ValueError("Exactly one of `file` or `url` must be provided")

body = deepcopy_minimal(
{
"file": file,
# AUTOGEN-START create-body
"purpose": purpose,
"preprocess_configs": preprocess_configs,
Expand All @@ -96,6 +98,8 @@ def create(
# AUTOGEN-END create-body
}
)
if file is not None:
body["file"] = file
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
Expand Down Expand Up @@ -225,7 +229,7 @@ def with_streaming_response(self) -> "AsyncFilesWithStreamingResponse":
async def create(
self,
*,
file: FileTypes,
file: Optional[FileTypes] = None,
# AUTOGEN-START create-kwargs
purpose: Purpose,
preprocess_configs: Optional[PreprocessConfigsParam] = None,
Expand All @@ -238,9 +242,11 @@ async def create(
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None = None,
) -> FileObject:
if (file is None) == (url is None):
raise ValueError("Exactly one of `file` or `url` must be provided")

body = deepcopy_minimal(
{
"file": file,
# AUTOGEN-START create-body
"purpose": purpose,
"preprocess_configs": preprocess_configs,
Expand All @@ -250,6 +256,8 @@ async def create(
# AUTOGEN-END create-body
}
)
if file is not None:
body["file"] = file
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
Expand Down
2 changes: 1 addition & 1 deletion src/arkruntime/types/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
]

# Hand-written extras (preserved across regen via Makefile rsync --exclude=*_shim.py).
from ._init_extras_shim import * # noqa: F401,F403,E402
from ._init_extras_shim import * # noqa: F401,F403
2 changes: 1 addition & 1 deletion src/arkruntime/types/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
]

# Hand-written extras (preserved across regen via Makefile rsync --exclude=*_shim.py).
from ._init_extras_shim import * # noqa: F401,F403,E402
from ._init_extras_shim import * # noqa: F401,F403
2 changes: 1 addition & 1 deletion src/arkruntime/types/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@
]

# Hand-written extras (preserved across regen via Makefile rsync --exclude=*_shim.py).
from ._init_extras_shim import * # noqa: F401,F403,E402
from ._init_extras_shim import * # noqa: F401,F403
2 changes: 1 addition & 1 deletion src/arkruntime/types/skill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
]

# Hand-written extras (preserved across regen via Makefile rsync --exclude=*_shim.py).
from ._init_extras_shim import * # noqa: F401,F403,E402
from ._init_extras_shim import * # noqa: F401,F403
81 changes: 81 additions & 0 deletions tests/test_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) 2026 ByteDance Ltd. and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

import pytest

from arkruntime.resources.files.files import AsyncFiles, Files


class _SyncClient:
def __init__(self) -> None:
self.request: dict[str, object] | None = None

def post(self, *args: object, **kwargs: object) -> dict[str, object]:
self.request = {"args": args, **kwargs}
return {}

def post_without_retry(self, *args: object, **kwargs: object) -> dict[str, object]:
return self.post(*args, **kwargs)

def get(self, *args: object, **kwargs: object) -> dict[str, object]:
return {}

def delete(self, *args: object, **kwargs: object) -> dict[str, object]:
return {}

def get_api_list(self, *args: object, **kwargs: object) -> list[object]:
return []


class _AsyncClient:
def __init__(self) -> None:
self.request: dict[str, object] | None = None

async def post(self, *args: object, **kwargs: object) -> dict[str, object]:
self.request = {"args": args, **kwargs}
return {}

async def post_without_retry(self, *args: object, **kwargs: object) -> dict[str, object]:
return await self.post(*args, **kwargs)

async def get(self, *args: object, **kwargs: object) -> dict[str, object]:
return {}

async def delete(self, *args: object, **kwargs: object) -> dict[str, object]:
return {}

async def get_api_list(self, *args: object, **kwargs: object) -> list[object]:
return []


def test_create_from_url_does_not_treat_url_as_local_file() -> None:
client = _SyncClient()
Files(client).create(purpose="user_data", url="https://example.com/file.pdf")

assert client.request is not None
assert client.request["files"] == []
assert client.request["body"] == {
"purpose": "user_data",
"url": "https://example.com/file.pdf",
}


@pytest.mark.asyncio
async def test_async_create_from_url_does_not_treat_url_as_local_file() -> None:
client = _AsyncClient()
await AsyncFiles(client).create(purpose="user_data", url="https://example.com/file.pdf")

assert client.request is not None
assert client.request["files"] == []
assert client.request["body"] == {
"purpose": "user_data",
"url": "https://example.com/file.pdf",
}


@pytest.mark.parametrize("kwargs", [{}, {"file": b"data", "url": "https://example.com/file.pdf"}])
def test_create_requires_exactly_one_file_source(kwargs: dict[str, object]) -> None:
with pytest.raises(ValueError, match="Exactly one"):
Files(_SyncClient()).create(purpose="user_data", **kwargs)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading