Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.1.0-alpha.12 #66

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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 .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ USER vscode
RUN curl -sSf https://rye.astral.sh/get | RYE_VERSION="0.35.0" RYE_INSTALL_OPTION="--yes" bash
ENV PATH=/home/vscode/.rye/shims:$PATH

RUN echo "[[ -d .venv ]] && source .venv/bin/activate" >> /home/vscode/.bashrc
RUN echo "[[ -d .venv ]] && source .venv/bin/activate || export PATH=\$PATH" >> /home/vscode/.bashrc
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
}
}
}
},
"features": {
"ghcr.io/devcontainers/features/node:1": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
Expand Down
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.11"
".": "0.1.0-alpha.12"
}
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## 0.1.0-alpha.12 (2025-02-22)

Full Changelog: [v0.1.0-alpha.11...v0.1.0-alpha.12](https://github.com/cleanlab/codex-python/compare/v0.1.0-alpha.11...v0.1.0-alpha.12)

### Features

* **api:** api update ([#60](https://github.com/cleanlab/codex-python/issues/60)) ([f28da42](https://github.com/cleanlab/codex-python/commit/f28da423ea6350df2422a6b3c984044686cb4674))
* **api:** api update ([#67](https://github.com/cleanlab/codex-python/issues/67)) ([5697955](https://github.com/cleanlab/codex-python/commit/569795521774bd2ac303dcaf8058e791f1af501c))
* **client:** allow passing `NotGiven` for body ([#70](https://github.com/cleanlab/codex-python/issues/70)) ([f022d08](https://github.com/cleanlab/codex-python/commit/f022d082ad3e07ba3600c0d9e8becefad96ca175))
* **client:** send `X-Stainless-Read-Timeout` header ([#63](https://github.com/cleanlab/codex-python/issues/63)) ([5904ed6](https://github.com/cleanlab/codex-python/commit/5904ed630f3dce437f3eb0f248d6a96b7c237e19))


### Bug Fixes

* asyncify on non-asyncio runtimes ([#69](https://github.com/cleanlab/codex-python/issues/69)) ([dc7519f](https://github.com/cleanlab/codex-python/commit/dc7519f876a99cdb58f4b634de45989e44c53c88))
* **client:** mark some request bodies as optional ([f022d08](https://github.com/cleanlab/codex-python/commit/f022d082ad3e07ba3600c0d9e8becefad96ca175))


### Chores

* **internal:** bummp ruff dependency ([#62](https://github.com/cleanlab/codex-python/issues/62)) ([123ccca](https://github.com/cleanlab/codex-python/commit/123ccca213572048ca6678900414e746516a9de1))
* **internal:** change default timeout to an int ([#61](https://github.com/cleanlab/codex-python/issues/61)) ([66fc9b7](https://github.com/cleanlab/codex-python/commit/66fc9b758ba38b160b7d6b17b94f294f248e0ecd))
* **internal:** fix devcontainers setup ([#71](https://github.com/cleanlab/codex-python/issues/71)) ([9ec8473](https://github.com/cleanlab/codex-python/commit/9ec847324c47ab63d9cf39d50f392367585065cf))
* **internal:** fix type traversing dictionary params ([#64](https://github.com/cleanlab/codex-python/issues/64)) ([648fc48](https://github.com/cleanlab/codex-python/commit/648fc489ce7f9827bfc2354e93d470b6e4b7e1bf))
* **internal:** minor type handling changes ([#65](https://github.com/cleanlab/codex-python/issues/65)) ([27aa5db](https://github.com/cleanlab/codex-python/commit/27aa5db50e0aa13eb2c4d88196a4ac70681ae808))
* **internal:** update client tests ([#68](https://github.com/cleanlab/codex-python/issues/68)) ([9297d25](https://github.com/cleanlab/codex-python/commit/9297d25f8f6e59af3fa610539d9736f5f0af2fe2))
* **internal:** version bump ([#58](https://github.com/cleanlab/codex-python/issues/58)) ([d032df2](https://github.com/cleanlab/codex-python/commit/d032df2296313bf0d2b2712672756ed185afb0e0))

## 0.1.0-alpha.11 (2025-01-30)

Full Changelog: [v0.1.0-alpha.10...v0.1.0-alpha.11](https://github.com/cleanlab/codex-python/compare/v0.1.0-alpha.10...v0.1.0-alpha.11)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "codex-sdk"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12"
description = "Internal SDK used within cleanlab-codex package. Refer to https://pypi.org/project/cleanlab-codex/ instead."
dynamic = ["readme"]
license = "MIT"
Expand Down Expand Up @@ -177,7 +177,7 @@ select = [
"T201",
"T203",
# misuse of typing.TYPE_CHECKING
"TCH004",
"TC004",
# import rules
"TID251",
]
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pytz==2023.3.post1
# via dirty-equals
respx==0.22.0
rich==13.7.1
ruff==0.6.9
ruff==0.9.4
setuptools==68.2.2
# via nodeenv
six==1.16.0
Expand Down
4 changes: 2 additions & 2 deletions scripts/utils/ruffen-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _md_match(match: Match[str]) -> str:
with _collect_error(match):
code = format_code_block(code)
code = textwrap.indent(code, match["indent"])
return f'{match["before"]}{code}{match["after"]}'
return f"{match['before']}{code}{match['after']}"

def _pycon_match(match: Match[str]) -> str:
code = ""
Expand Down Expand Up @@ -97,7 +97,7 @@ def finish_fragment() -> None:
def _md_pycon_match(match: Match[str]) -> str:
code = _pycon_match(match)
code = textwrap.indent(code, match["indent"])
return f'{match["before"]}{code}{match["after"]}'
return f"{match['before']}{code}{match['after']}"

src = MD_RE.sub(_md_match, src)
src = MD_PYCON_RE.sub(_md_pycon_match, src)
Expand Down
13 changes: 10 additions & 3 deletions src/codex/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,17 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()

# Don't set the retry count header if it was already set or removed by the caller. We check
# Don't set these headers if they were already set or removed by the caller. We check
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
if "x-stainless-retry-count" not in (header.lower() for header in custom_headers):
lower_custom_headers = [header.lower() for header in custom_headers]
if "x-stainless-retry-count" not in lower_custom_headers:
headers["x-stainless-retry-count"] = str(retries_taken)
if "x-stainless-read-timeout" not in lower_custom_headers:
timeout = self.timeout if isinstance(options.timeout, NotGiven) else options.timeout
if isinstance(timeout, Timeout):
timeout = timeout.read
if timeout is not None:
headers["x-stainless-read-timeout"] = str(timeout)

return headers

Expand Down Expand Up @@ -511,7 +518,7 @@ def _build_request(
# so that passing a `TypedDict` doesn't cause an error.
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
json=json_data,
json=json_data if is_given(json_data) else None,
files=files,
**kwargs,
)
Expand Down
2 changes: 1 addition & 1 deletion src/codex/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"

# default timeout is 1 minute
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60.0, connect=5.0)
DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
DEFAULT_MAX_RETRIES = 2
DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)

Expand Down
10 changes: 8 additions & 2 deletions src/codex/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def to_json(
@override
def __str__(self) -> str:
# mypy complains about an invalid self arg
return f'{self.__repr_name__()}({self.__repr_str__(", ")})' # type: ignore[misc]
return f"{self.__repr_name__()}({self.__repr_str__(', ')})" # type: ignore[misc]

# Override the 'construct' method in a way that supports recursive parsing without validation.
# Based on https://github.com/samuelcolvin/pydantic/issues/1168#issuecomment-817742836.
Expand Down Expand Up @@ -426,10 +426,16 @@ def construct_type(*, value: object, type_: object) -> object:

If the given value does not match the expected type then it is returned as-is.
"""

# store a reference to the original type we were given before we extract any inner
# types so that we can properly resolve forward references in `TypeAliasType` annotations
original_type = None

# we allow `object` as the input type because otherwise, passing things like
# `Literal['value']` will be reported as a type error by type checkers
type_ = cast("type[object]", type_)
if is_type_alias_type(type_):
original_type = type_ # type: ignore[unreachable]
type_ = type_.__value__ # type: ignore[unreachable]

# unwrap `Annotated[T, ...]` -> `T`
Expand All @@ -446,7 +452,7 @@ def construct_type(*, value: object, type_: object) -> object:

if is_union(origin):
try:
return validate_type(type_=cast("type[object]", type_), value=value)
return validate_type(type_=cast("type[object]", original_type or type_), value=value)
except Exception:
pass

Expand Down
19 changes: 17 additions & 2 deletions src/codex/_utils/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
from typing import Any, TypeVar, Callable, Awaitable
from typing_extensions import ParamSpec

import anyio
import sniffio
import anyio.to_thread

T_Retval = TypeVar("T_Retval")
T_ParamSpec = ParamSpec("T_ParamSpec")


if sys.version_info >= (3, 9):
to_thread = asyncio.to_thread
_asyncio_to_thread = asyncio.to_thread
else:
# backport of https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread
# for Python 3.8 support
async def to_thread(
async def _asyncio_to_thread(
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> Any:
"""Asynchronously run function *func* in a separate thread.
Expand All @@ -34,6 +38,17 @@ async def to_thread(
return await loop.run_in_executor(None, func_call)


async def to_thread(
func: Callable[T_ParamSpec, T_Retval], /, *args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> T_Retval:
if sniffio.current_async_library() == "asyncio":
return await _asyncio_to_thread(func, *args, **kwargs)

return await anyio.to_thread.run_sync(
functools.partial(func, *args, **kwargs),
)


# inspired by `asyncer`, https://github.com/tiangolo/asyncer
def asyncify(function: Callable[T_ParamSpec, T_Retval]) -> Callable[T_ParamSpec, Awaitable[T_Retval]]:
"""
Expand Down
12 changes: 11 additions & 1 deletion src/codex/_utils/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
is_annotated_type,
strip_annotated_type,
)
from .._compat import model_dump, is_typeddict
from .._compat import get_origin, model_dump, is_typeddict

_T = TypeVar("_T")

Expand Down Expand Up @@ -164,9 +164,14 @@ def _transform_recursive(
inner_type = annotation

stripped_type = strip_annotated_type(inner_type)
origin = get_origin(stripped_type) or stripped_type
if is_typeddict(stripped_type) and is_mapping(data):
return _transform_typeddict(data, stripped_type)

if origin == dict and is_mapping(data):
items_type = get_args(stripped_type)[1]
return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()}

if (
# List[T]
(is_list_type(stripped_type) and is_list(data))
Expand Down Expand Up @@ -307,9 +312,14 @@ async def _async_transform_recursive(
inner_type = annotation

stripped_type = strip_annotated_type(inner_type)
origin = get_origin(stripped_type) or stripped_type
if is_typeddict(stripped_type) and is_mapping(data):
return await _async_transform_typeddict(data, stripped_type)

if origin == dict and is_mapping(data):
items_type = get_args(stripped_type)[1]
return {key: _transform_recursive(value, annotation=items_type) for key, value in data.items()}

if (
# List[T]
(is_list_type(stripped_type) and is_list(data))
Expand Down
2 changes: 1 addition & 1 deletion src/codex/_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__ = "codex"
__version__ = "0.1.0-alpha.11" # x-release-please-version
__version__ = "0.1.0-alpha.12" # x-release-please-version
20 changes: 16 additions & 4 deletions src/codex/resources/projects/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def create(
"""
Create a knowledge entry for a project.

Raises: HTTPException: If an existing entry is found with the same question.

Args:
extra_headers: Send extra headers

Expand Down Expand Up @@ -138,6 +140,7 @@ def update(
*,
project_id: str,
answer: Optional[str] | NotGiven = NOT_GIVEN,
frequency_count: Optional[int] | NotGiven = NOT_GIVEN,
question: Optional[str] | NotGiven = NOT_GIVEN,
# 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.
Expand Down Expand Up @@ -167,6 +170,7 @@ def update(
body=maybe_transform(
{
"answer": answer,
"frequency_count": frequency_count,
"question": question,
},
entry_update_params.EntryUpdateParams,
Expand Down Expand Up @@ -318,8 +322,10 @@ def query(
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[Entry]:
"""
Query knowledge for a project.
"""Query knowledge for a project.

Also increments the frequency_count for the
matching entry if found.

Returns the matching entry if found and answered, otherwise returns None. This
allows the client to distinguish between: (1) no matching question found
Expand Down Expand Up @@ -383,6 +389,8 @@ async def create(
"""
Create a knowledge entry for a project.

Raises: HTTPException: If an existing entry is found with the same question.

Args:
extra_headers: Send extra headers

Expand Down Expand Up @@ -451,6 +459,7 @@ async def update(
*,
project_id: str,
answer: Optional[str] | NotGiven = NOT_GIVEN,
frequency_count: Optional[int] | NotGiven = NOT_GIVEN,
question: Optional[str] | NotGiven = NOT_GIVEN,
# 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.
Expand Down Expand Up @@ -480,6 +489,7 @@ async def update(
body=await async_maybe_transform(
{
"answer": answer,
"frequency_count": frequency_count,
"question": question,
},
entry_update_params.EntryUpdateParams,
Expand Down Expand Up @@ -631,8 +641,10 @@ async def query(
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[Entry]:
"""
Query knowledge for a project.
"""Query knowledge for a project.

Also increments the frequency_count for the
matching entry if found.

Returns the matching entry if found and answered, otherwise returns None. This
allows the client to distinguish between: (1) no matching question found
Expand Down
2 changes: 2 additions & 0 deletions src/codex/types/projects/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ class Entry(BaseModel):
answer: Optional[str] = None

answered_at: Optional[datetime] = None

frequency_count: Optional[int] = None
2 changes: 2 additions & 0 deletions src/codex/types/projects/entry_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ class EntryUpdateParams(TypedDict, total=False):

answer: Optional[str]

frequency_count: Optional[int]

question: Optional[str]
2 changes: 2 additions & 0 deletions tests/api_resources/projects/test_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_method_update_with_all_params(self, client: Codex) -> None:
entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
answer="answer",
frequency_count=0,
question="question",
)
assert_matches_type(Entry, entry, path=["response"])
Expand Down Expand Up @@ -519,6 +520,7 @@ async def test_method_update_with_all_params(self, async_client: AsyncCodex) ->
entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
answer="answer",
frequency_count=0,
question="question",
)
assert_matches_type(Entry, entry, path=["response"])
Expand Down
Loading