diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 55d2025..ff261ba 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} USER vscode -RUN curl -sSf https://rye.astral.sh/get | RYE_VERSION="0.35.0" RYE_INSTALL_OPTION="--yes" bash +RUN curl -sSf https://rye.astral.sh/get | RYE_VERSION="0.44.0" RYE_INSTALL_OPTION="--yes" bash ENV PATH=/home/vscode/.rye/shims:$PATH RUN echo "[[ -d .venv ]] && source .venv/bin/activate || export PATH=\$PATH" >> /home/vscode/.bashrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e503784..5ac5f63 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: curl -sSf https://rye.astral.sh/get | bash echo "$HOME/.rye/shims" >> $GITHUB_PATH env: - RYE_VERSION: '0.35.0' + RYE_VERSION: '0.44.0' RYE_INSTALL_OPTION: '--yes' - name: Install dependencies diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 5ed611c..7c078aa 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -21,7 +21,7 @@ jobs: curl -sSf https://rye.astral.sh/get | bash echo "$HOME/.rye/shims" >> $GITHUB_PATH env: - RYE_VERSION: '0.35.0' + RYE_VERSION: '0.44.0' RYE_INSTALL_OPTION: '--yes' - name: Publish to PyPI diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fd0ccba..000572e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.12" + ".": "0.1.0-alpha.13" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 7982133..d2d3f6a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1,3 @@ -configured_endpoints: 37 +configured_endpoints: 36 +openapi_spec_hash: 4e7cb2cd6132c29f60a87a958f617a41 +config_hash: adbedb6317fca6f566f54564cc341846 diff --git a/CHANGELOG.md b/CHANGELOG.md index abb1602..67d337b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Changelog +## 0.1.0-alpha.13 (2025-04-02) + +Full Changelog: [v0.1.0-alpha.12...v0.1.0-alpha.13](https://github.com/cleanlab/codex-python/compare/v0.1.0-alpha.12...v0.1.0-alpha.13) + +### Features + +* **api:** api update ([#83](https://github.com/cleanlab/codex-python/issues/83)) ([b41e3bf](https://github.com/cleanlab/codex-python/commit/b41e3bf21e10b11b6d64e15f320cf3d8aa66bfb8)) +* **api:** api update ([#90](https://github.com/cleanlab/codex-python/issues/90)) ([52933f2](https://github.com/cleanlab/codex-python/commit/52933f2bc708e1f2b5f2e144071a9ee41b27251c)) +* **api:** updates from question grouping ([#93](https://github.com/cleanlab/codex-python/issues/93)) ([14da023](https://github.com/cleanlab/codex-python/commit/14da02311e598a1d5f4e41a100160b81befd4f61)) + + +### Bug Fixes + +* **ci:** ensure pip is always available ([#88](https://github.com/cleanlab/codex-python/issues/88)) ([86a40cc](https://github.com/cleanlab/codex-python/commit/86a40ccd3892d23bb12f78bf5ff13eaa23d8eb2d)) +* **ci:** remove publishing patch ([#89](https://github.com/cleanlab/codex-python/issues/89)) ([674c661](https://github.com/cleanlab/codex-python/commit/674c6613c7709c93cca936f086d5348041252972)) +* **types:** handle more discriminated union shapes ([#87](https://github.com/cleanlab/codex-python/issues/87)) ([ea6a942](https://github.com/cleanlab/codex-python/commit/ea6a9422c2a1ff25f14ade1a790ffd943dadbd81)) + + +### Chores + +* fix typos ([#91](https://github.com/cleanlab/codex-python/issues/91)) ([6b97689](https://github.com/cleanlab/codex-python/commit/6b97689646d7b3611ace81c630fafa1962b5c94d)) +* **internal:** bump rye to 0.44.0 ([#86](https://github.com/cleanlab/codex-python/issues/86)) ([e026b73](https://github.com/cleanlab/codex-python/commit/e026b73fb62aa19689890f14b7dcf355910029a8)) +* **internal:** codegen related update ([#85](https://github.com/cleanlab/codex-python/issues/85)) ([7e1eaca](https://github.com/cleanlab/codex-python/commit/7e1eaca4c5f2c779b264c34883688b52e1a8602e)) +* **internal:** remove extra empty newlines ([#84](https://github.com/cleanlab/codex-python/issues/84)) ([e4b2929](https://github.com/cleanlab/codex-python/commit/e4b2929d58b466199bb02e24b8e0a7c9c63f1b3a)) +* **internal:** version bump ([#81](https://github.com/cleanlab/codex-python/issues/81)) ([7ee4e09](https://github.com/cleanlab/codex-python/commit/7ee4e09545e52eaa3d10522709e833b38221ecad)) + ## 0.1.0-alpha.12 (2025-03-11) 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) diff --git a/api.md b/api.md index 5e25833..b241c15 100644 --- a/api.md +++ b/api.md @@ -10,7 +10,6 @@ Methods: - client.health.check() -> HealthCheckResponse - client.health.db() -> HealthCheckResponse -- client.health.weaviate() -> HealthCheckResponse # Organizations @@ -175,7 +174,7 @@ Methods: Types: ```python -from codex.types.projects import Entry +from codex.types.projects import Entry, EntryQueryResponse ``` Methods: @@ -183,10 +182,21 @@ Methods: - client.projects.entries.create(project_id, \*\*params) -> Entry - client.projects.entries.retrieve(entry_id, \*, project_id) -> Entry - client.projects.entries.update(entry_id, \*, project_id, \*\*params) -> Entry -- client.projects.entries.list(project_id, \*\*params) -> SyncOffsetPageEntries[Entry] - client.projects.entries.delete(entry_id, \*, project_id) -> None -- client.projects.entries.add_question(project_id, \*\*params) -> Entry -- client.projects.entries.query(project_id, \*\*params) -> Optional[Entry] +- client.projects.entries.query(project_id, \*\*params) -> EntryQueryResponse + +## Clusters + +Types: + +```python +from codex.types.projects import ClusterListResponse, ClusterListVariantsResponse +``` + +Methods: + +- client.projects.clusters.list(project_id, \*\*params) -> SyncOffsetPageClusters[ClusterListResponse] +- client.projects.clusters.list_variants(representative_entry_id, \*, project_id) -> ClusterListVariantsResponse # Tlm diff --git a/bin/publish-pypi b/bin/publish-pypi index 05bfccb..826054e 100644 --- a/bin/publish-pypi +++ b/bin/publish-pypi @@ -3,7 +3,4 @@ set -eux mkdir -p dist rye build --clean -# Patching importlib-metadata version until upstream library version is updated -# https://github.com/pypa/twine/issues/977#issuecomment-2189800841 -"$HOME/.rye/self/bin/python3" -m pip install 'importlib-metadata==7.2.1' rye publish --yes --token=$PYPI_TOKEN diff --git a/pyproject.toml b/pyproject.toml index ede4351..70b5b9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "codex-sdk" -version = "0.1.0-alpha.12" +version = "0.1.0-alpha.13" description = "Internal SDK used within cleanlab-codex package. Refer to https://pypi.org/project/cleanlab-codex/ instead." dynamic = ["readme"] license = "MIT" @@ -38,7 +38,6 @@ Homepage = "https://github.com/cleanlab/codex-python" Repository = "https://github.com/cleanlab/codex-python" - [tool.rye] managed = true # version pins are in requirements-dev.lock @@ -87,7 +86,7 @@ typecheck = { chain = [ "typecheck:mypy" = "mypy ." [build-system] -requires = ["hatchling", "hatch-fancy-pypi-readme"] +requires = ["hatchling==1.26.3", "hatch-fancy-pypi-readme"] build-backend = "hatchling.build" [tool.hatch.build] @@ -152,7 +151,6 @@ reportImplicitOverride = true reportImportCycles = false reportPrivateUsage = false - [tool.ruff] line-length = 120 output-format = "grouped" diff --git a/requirements-dev.lock b/requirements-dev.lock index 1961e8d..5b7189d 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -7,6 +7,7 @@ # all-features: true # with-sources: false # generate-hashes: false +# universal: false -e file:. annotated-types==0.6.0 diff --git a/requirements.lock b/requirements.lock index 5d7fff8..1f6c5f7 100644 --- a/requirements.lock +++ b/requirements.lock @@ -7,6 +7,7 @@ # all-features: true # with-sources: false # generate-hashes: false +# universal: false -e file:. annotated-types==0.6.0 diff --git a/src/codex/_models.py b/src/codex/_models.py index c4401ff..3493571 100644 --- a/src/codex/_models.py +++ b/src/codex/_models.py @@ -65,7 +65,7 @@ from ._constants import RAW_RESPONSE_HEADER if TYPE_CHECKING: - from pydantic_core.core_schema import ModelField, LiteralSchema, ModelFieldsSchema + from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema __all__ = ["BaseModel", "GenericModel"] @@ -646,15 +646,18 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any, def _extract_field_schema_pv2(model: type[BaseModel], field_name: str) -> ModelField | None: schema = model.__pydantic_core_schema__ + if schema["type"] == "definitions": + schema = schema["schema"] + if schema["type"] != "model": return None + schema = cast("ModelSchema", schema) fields_schema = schema["schema"] if fields_schema["type"] != "model-fields": return None fields_schema = cast("ModelFieldsSchema", fields_schema) - field = fields_schema["fields"].get(field_name) if not field: return None @@ -678,7 +681,7 @@ def set_pydantic_config(typ: Any, config: pydantic.ConfigDict) -> None: setattr(typ, "__pydantic_config__", config) # noqa: B010 -# our use of subclasssing here causes weirdness for type checkers, +# our use of subclassing here causes weirdness for type checkers, # so we just pretend that we don't subclass if TYPE_CHECKING: GenericModel = BaseModel diff --git a/src/codex/_utils/_transform.py b/src/codex/_utils/_transform.py index 18afd9d..7ac2e17 100644 --- a/src/codex/_utils/_transform.py +++ b/src/codex/_utils/_transform.py @@ -126,7 +126,7 @@ def _get_annotated_type(type_: type) -> type | None: def _maybe_transform_key(key: str, type_: type) -> str: """Transform the given `data` based on the annotations provided in `type_`. - Note: this function only looks at `Annotated` types that contain `PropertInfo` metadata. + Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata. """ annotated_type = _get_annotated_type(type_) if annotated_type is None: diff --git a/src/codex/_version.py b/src/codex/_version.py index fe7cc73..8790f4e 100644 --- a/src/codex/_version.py +++ b/src/codex/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "codex" -__version__ = "0.1.0-alpha.12" # x-release-please-version +__version__ = "0.1.0-alpha.13" # x-release-please-version diff --git a/src/codex/pagination.py b/src/codex/pagination.py index 48ed501..1f590df 100644 --- a/src/codex/pagination.py +++ b/src/codex/pagination.py @@ -12,6 +12,8 @@ __all__ = [ "SyncMyOffsetPageTopLevelArray", "AsyncMyOffsetPageTopLevelArray", + "SyncOffsetPageClusters", + "AsyncOffsetPageClusters", "SyncOffsetPageEntries", "AsyncOffsetPageEntries", ] @@ -83,6 +85,66 @@ def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseM ) +class SyncOffsetPageClusters(BaseSyncPage[_T], BasePage[_T], Generic[_T]): + clusters: List[_T] + total_count: Optional[int] = None + + @override + def _get_page_items(self) -> List[_T]: + clusters = self.clusters + if not clusters: + return [] + return clusters + + @override + def next_page_info(self) -> Optional[PageInfo]: + offset = self._options.params.get("offset") or 0 + if not isinstance(offset, int): + raise ValueError(f'Expected "offset" param to be an integer but got {offset}') + + length = len(self._get_page_items()) + current_count = offset + length + + total_count = self.total_count + if total_count is None: + return None + + if current_count < total_count: + return PageInfo(params={"offset": current_count}) + + return None + + +class AsyncOffsetPageClusters(BaseAsyncPage[_T], BasePage[_T], Generic[_T]): + clusters: List[_T] + total_count: Optional[int] = None + + @override + def _get_page_items(self) -> List[_T]: + clusters = self.clusters + if not clusters: + return [] + return clusters + + @override + def next_page_info(self) -> Optional[PageInfo]: + offset = self._options.params.get("offset") or 0 + if not isinstance(offset, int): + raise ValueError(f'Expected "offset" param to be an integer but got {offset}') + + length = len(self._get_page_items()) + current_count = offset + length + + total_count = self.total_count + if total_count is None: + return None + + if current_count < total_count: + return PageInfo(params={"offset": current_count}) + + return None + + class SyncOffsetPageEntries(BaseSyncPage[_T], BasePage[_T], Generic[_T]): entries: List[_T] total_count: Optional[int] = None diff --git a/src/codex/resources/health.py b/src/codex/resources/health.py index 6a777c6..d74d23a 100644 --- a/src/codex/resources/health.py +++ b/src/codex/resources/health.py @@ -77,25 +77,6 @@ def db( cast_to=HealthCheckResponse, ) - def weaviate( - self, - *, - # 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, - ) -> HealthCheckResponse: - """Check the weaviate connection.""" - return self._get( - "/api/health/weaviate", - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=HealthCheckResponse, - ) - class AsyncHealthResource(AsyncAPIResource): @cached_property @@ -155,25 +136,6 @@ async def db( cast_to=HealthCheckResponse, ) - async def weaviate( - self, - *, - # 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, - ) -> HealthCheckResponse: - """Check the weaviate connection.""" - return await self._get( - "/api/health/weaviate", - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout - ), - cast_to=HealthCheckResponse, - ) - class HealthResourceWithRawResponse: def __init__(self, health: HealthResource) -> None: @@ -185,9 +147,6 @@ def __init__(self, health: HealthResource) -> None: self.db = to_raw_response_wrapper( health.db, ) - self.weaviate = to_raw_response_wrapper( - health.weaviate, - ) class AsyncHealthResourceWithRawResponse: @@ -200,9 +159,6 @@ def __init__(self, health: AsyncHealthResource) -> None: self.db = async_to_raw_response_wrapper( health.db, ) - self.weaviate = async_to_raw_response_wrapper( - health.weaviate, - ) class HealthResourceWithStreamingResponse: @@ -215,9 +171,6 @@ def __init__(self, health: HealthResource) -> None: self.db = to_streamed_response_wrapper( health.db, ) - self.weaviate = to_streamed_response_wrapper( - health.weaviate, - ) class AsyncHealthResourceWithStreamingResponse: @@ -230,6 +183,3 @@ def __init__(self, health: AsyncHealthResource) -> None: self.db = async_to_streamed_response_wrapper( health.db, ) - self.weaviate = async_to_streamed_response_wrapper( - health.weaviate, - ) diff --git a/src/codex/resources/projects/__init__.py b/src/codex/resources/projects/__init__.py index 0159985..2c0595d 100644 --- a/src/codex/resources/projects/__init__.py +++ b/src/codex/resources/projects/__init__.py @@ -8,6 +8,14 @@ EntriesResourceWithStreamingResponse, AsyncEntriesResourceWithStreamingResponse, ) +from .clusters import ( + ClustersResource, + AsyncClustersResource, + ClustersResourceWithRawResponse, + AsyncClustersResourceWithRawResponse, + ClustersResourceWithStreamingResponse, + AsyncClustersResourceWithStreamingResponse, +) from .projects import ( ProjectsResource, AsyncProjectsResource, @@ -38,6 +46,12 @@ "AsyncEntriesResourceWithRawResponse", "EntriesResourceWithStreamingResponse", "AsyncEntriesResourceWithStreamingResponse", + "ClustersResource", + "AsyncClustersResource", + "ClustersResourceWithRawResponse", + "AsyncClustersResourceWithRawResponse", + "ClustersResourceWithStreamingResponse", + "AsyncClustersResourceWithStreamingResponse", "ProjectsResource", "AsyncProjectsResource", "ProjectsResourceWithRawResponse", diff --git a/src/codex/resources/projects/access_keys.py b/src/codex/resources/projects/access_keys.py index d375dbc..6198739 100644 --- a/src/codex/resources/projects/access_keys.py +++ b/src/codex/resources/projects/access_keys.py @@ -10,6 +10,7 @@ from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven from ..._utils import ( maybe_transform, + strip_not_given, async_maybe_transform, ) from ..._compat import cached_property @@ -56,6 +57,10 @@ def create( name: str, description: Optional[str] | NotGiven = NOT_GIVEN, expires_at: Union[str, datetime, None] | NotGiven = NOT_GIVEN, + x_client_library_version: str | NotGiven = NOT_GIVEN, + x_integration_type: str | NotGiven = NOT_GIVEN, + x_source: str | NotGiven = NOT_GIVEN, + x_stainless_package_version: 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. extra_headers: Headers | None = None, @@ -77,6 +82,17 @@ def create( """ if not project_id: raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + extra_headers = { + **strip_not_given( + { + "x-client-library-version": x_client_library_version, + "x-integration-type": x_integration_type, + "x-source": x_source, + "x-stainless-package-version": x_stainless_package_version, + } + ), + **(extra_headers or {}), + } return self._post( f"/api/projects/{project_id}/access_keys/", body=maybe_transform( @@ -330,6 +346,10 @@ async def create( name: str, description: Optional[str] | NotGiven = NOT_GIVEN, expires_at: Union[str, datetime, None] | NotGiven = NOT_GIVEN, + x_client_library_version: str | NotGiven = NOT_GIVEN, + x_integration_type: str | NotGiven = NOT_GIVEN, + x_source: str | NotGiven = NOT_GIVEN, + x_stainless_package_version: 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. extra_headers: Headers | None = None, @@ -351,6 +371,17 @@ async def create( """ if not project_id: raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + extra_headers = { + **strip_not_given( + { + "x-client-library-version": x_client_library_version, + "x-integration-type": x_integration_type, + "x-source": x_source, + "x-stainless-package-version": x_stainless_package_version, + } + ), + **(extra_headers or {}), + } return await self._post( f"/api/projects/{project_id}/access_keys/", body=await async_maybe_transform( diff --git a/src/codex/resources/projects/clusters.py b/src/codex/resources/projects/clusters.py new file mode 100644 index 0000000..54b6c4c --- /dev/null +++ b/src/codex/resources/projects/clusters.py @@ -0,0 +1,296 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import List +from typing_extensions import Literal + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from ..._utils import maybe_transform +from ..._compat import cached_property +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ...pagination import SyncOffsetPageClusters, AsyncOffsetPageClusters +from ..._base_client import AsyncPaginator, make_request_options +from ...types.projects import cluster_list_params +from ...types.projects.cluster_list_response import ClusterListResponse +from ...types.projects.cluster_list_variants_response import ClusterListVariantsResponse + +__all__ = ["ClustersResource", "AsyncClustersResource"] + + +class ClustersResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> ClustersResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cleanlab/codex-python#accessing-raw-response-data-eg-headers + """ + return ClustersResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> ClustersResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cleanlab/codex-python#with_streaming_response + """ + return ClustersResourceWithStreamingResponse(self) + + def list( + self, + project_id: str, + *, + limit: int | NotGiven = NOT_GIVEN, + offset: int | NotGiven = NOT_GIVEN, + order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, + sort: Literal["created_at", "answered_at", "cluster_frequency_count"] | NotGiven = NOT_GIVEN, + states: List[Literal["unanswered", "draft", "published", "published_with_draft"]] | 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. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> SyncOffsetPageClusters[ClusterListResponse]: + """ + List knowledge entries for a project. + + Args: + 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 project_id: + raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + return self._get_api_list( + f"/api/projects/{project_id}/entries/clusters", + page=SyncOffsetPageClusters[ClusterListResponse], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "limit": limit, + "offset": offset, + "order": order, + "sort": sort, + "states": states, + }, + cluster_list_params.ClusterListParams, + ), + ), + model=ClusterListResponse, + ) + + def list_variants( + self, + representative_entry_id: str, + *, + project_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, + ) -> ClusterListVariantsResponse: + """ + Get Cluster Variants Route + + Args: + 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 project_id: + raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + if not representative_entry_id: + raise ValueError( + f"Expected a non-empty value for `representative_entry_id` but received {representative_entry_id!r}" + ) + return self._get( + f"/api/projects/{project_id}/entries/clusters/{representative_entry_id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ClusterListVariantsResponse, + ) + + +class AsyncClustersResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncClustersResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cleanlab/codex-python#accessing-raw-response-data-eg-headers + """ + return AsyncClustersResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncClustersResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cleanlab/codex-python#with_streaming_response + """ + return AsyncClustersResourceWithStreamingResponse(self) + + def list( + self, + project_id: str, + *, + limit: int | NotGiven = NOT_GIVEN, + offset: int | NotGiven = NOT_GIVEN, + order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, + sort: Literal["created_at", "answered_at", "cluster_frequency_count"] | NotGiven = NOT_GIVEN, + states: List[Literal["unanswered", "draft", "published", "published_with_draft"]] | 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. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> AsyncPaginator[ClusterListResponse, AsyncOffsetPageClusters[ClusterListResponse]]: + """ + List knowledge entries for a project. + + Args: + 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 project_id: + raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + return self._get_api_list( + f"/api/projects/{project_id}/entries/clusters", + page=AsyncOffsetPageClusters[ClusterListResponse], + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform( + { + "limit": limit, + "offset": offset, + "order": order, + "sort": sort, + "states": states, + }, + cluster_list_params.ClusterListParams, + ), + ), + model=ClusterListResponse, + ) + + async def list_variants( + self, + representative_entry_id: str, + *, + project_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, + ) -> ClusterListVariantsResponse: + """ + Get Cluster Variants Route + + Args: + 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 project_id: + raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + if not representative_entry_id: + raise ValueError( + f"Expected a non-empty value for `representative_entry_id` but received {representative_entry_id!r}" + ) + return await self._get( + f"/api/projects/{project_id}/entries/clusters/{representative_entry_id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=ClusterListVariantsResponse, + ) + + +class ClustersResourceWithRawResponse: + def __init__(self, clusters: ClustersResource) -> None: + self._clusters = clusters + + self.list = to_raw_response_wrapper( + clusters.list, + ) + self.list_variants = to_raw_response_wrapper( + clusters.list_variants, + ) + + +class AsyncClustersResourceWithRawResponse: + def __init__(self, clusters: AsyncClustersResource) -> None: + self._clusters = clusters + + self.list = async_to_raw_response_wrapper( + clusters.list, + ) + self.list_variants = async_to_raw_response_wrapper( + clusters.list_variants, + ) + + +class ClustersResourceWithStreamingResponse: + def __init__(self, clusters: ClustersResource) -> None: + self._clusters = clusters + + self.list = to_streamed_response_wrapper( + clusters.list, + ) + self.list_variants = to_streamed_response_wrapper( + clusters.list_variants, + ) + + +class AsyncClustersResourceWithStreamingResponse: + def __init__(self, clusters: AsyncClustersResource) -> None: + self._clusters = clusters + + self.list = async_to_streamed_response_wrapper( + clusters.list, + ) + self.list_variants = async_to_streamed_response_wrapper( + clusters.list_variants, + ) diff --git a/src/codex/resources/projects/entries.py b/src/codex/resources/projects/entries.py index 2fcc8e0..8be96b0 100644 --- a/src/codex/resources/projects/entries.py +++ b/src/codex/resources/projects/entries.py @@ -3,13 +3,13 @@ from __future__ import annotations from typing import Optional -from typing_extensions import Literal import httpx from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven from ..._utils import ( maybe_transform, + strip_not_given, async_maybe_transform, ) from ..._compat import cached_property @@ -20,16 +20,10 @@ async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) -from ...pagination import SyncOffsetPageEntries, AsyncOffsetPageEntries -from ..._base_client import AsyncPaginator, make_request_options -from ...types.projects import ( - entry_list_params, - entry_query_params, - entry_create_params, - entry_update_params, - entry_add_question_params, -) +from ..._base_client import make_request_options +from ...types.projects import entry_query_params, entry_create_params, entry_update_params from ...types.projects.entry import Entry +from ...types.projects.entry_query_response import EntryQueryResponse __all__ = ["EntriesResource", "AsyncEntriesResource"] @@ -60,6 +54,11 @@ def create( *, question: str, answer: Optional[str] | NotGiven = NOT_GIVEN, + draft_answer: Optional[str] | NotGiven = NOT_GIVEN, + x_client_library_version: str | NotGiven = NOT_GIVEN, + x_integration_type: str | NotGiven = NOT_GIVEN, + x_source: str | NotGiven = NOT_GIVEN, + x_stainless_package_version: 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. extra_headers: Headers | None = None, @@ -68,9 +67,7 @@ def create( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> Entry: """ - Create a knowledge entry for a project. - - Raises: HTTPException: If an existing entry is found with the same question. + Create a new knowledge entry for a project. Args: extra_headers: Send extra headers @@ -83,12 +80,24 @@ def create( """ if not project_id: raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + extra_headers = { + **strip_not_given( + { + "x-client-library-version": x_client_library_version, + "x-integration-type": x_integration_type, + "x-source": x_source, + "x-stainless-package-version": x_stainless_package_version, + } + ), + **(extra_headers or {}), + } return self._post( f"/api/projects/{project_id}/entries/", body=maybe_transform( { "question": question, "answer": answer, + "draft_answer": draft_answer, }, entry_create_params.EntryCreateParams, ), @@ -140,7 +149,7 @@ def update( *, project_id: str, answer: Optional[str] | NotGiven = NOT_GIVEN, - frequency_count: Optional[int] | NotGiven = NOT_GIVEN, + draft_answer: Optional[str] | 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. @@ -170,7 +179,7 @@ def update( body=maybe_transform( { "answer": answer, - "frequency_count": frequency_count, + "draft_answer": draft_answer, "question": question, }, entry_update_params.EntryUpdateParams, @@ -181,60 +190,6 @@ def update( cast_to=Entry, ) - def list( - self, - project_id: str, - *, - answered_only: bool | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - offset: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, - sort: Literal["created_at", "answered_at"] | NotGiven = NOT_GIVEN, - unanswered_only: bool | 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. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> SyncOffsetPageEntries[Entry]: - """ - List knowledge entries for a project. - - Args: - 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 project_id: - raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") - return self._get_api_list( - f"/api/projects/{project_id}/entries/", - page=SyncOffsetPageEntries[Entry], - options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - query=maybe_transform( - { - "answered_only": answered_only, - "limit": limit, - "offset": offset, - "order": order, - "sort": sort, - "unanswered_only": unanswered_only, - }, - entry_list_params.EntryListParams, - ), - ), - model=Entry, - ) - def delete( self, entry_id: str, @@ -272,23 +227,24 @@ def delete( cast_to=NoneType, ) - def add_question( + def query( self, project_id: str, *, question: str, + x_client_library_version: str | NotGiven = NOT_GIVEN, + x_integration_type: str | NotGiven = NOT_GIVEN, + x_source: str | NotGiven = NOT_GIVEN, + x_stainless_package_version: 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. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Entry: + ) -> EntryQueryResponse: """ - Add a question to a project. - - Returns: 201 Created if a new question was added 200 OK if the question already - existed + Query Entries Route Args: extra_headers: Send extra headers @@ -301,55 +257,24 @@ def add_question( """ if not project_id: raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") - return self._post( - f"/api/projects/{project_id}/entries/add_question", - body=maybe_transform({"question": question}, entry_add_question_params.EntryAddQuestionParams), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers = { + **strip_not_given( + { + "x-client-library-version": x_client_library_version, + "x-integration-type": x_integration_type, + "x-source": x_source, + "x-stainless-package-version": x_stainless_package_version, + } ), - cast_to=Entry, - ) - - def query( - self, - project_id: str, - *, - question: 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, - ) -> Optional[Entry]: - """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 - (returns None), and (2) matching question found but not yet answered (returns - Entry with answer=None). - - Args: - 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 project_id: - raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + **(extra_headers or {}), + } return self._post( f"/api/projects/{project_id}/entries/query", body=maybe_transform({"question": question}, entry_query_params.EntryQueryParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=Entry, + cast_to=EntryQueryResponse, ) @@ -379,6 +304,11 @@ async def create( *, question: str, answer: Optional[str] | NotGiven = NOT_GIVEN, + draft_answer: Optional[str] | NotGiven = NOT_GIVEN, + x_client_library_version: str | NotGiven = NOT_GIVEN, + x_integration_type: str | NotGiven = NOT_GIVEN, + x_source: str | NotGiven = NOT_GIVEN, + x_stainless_package_version: 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. extra_headers: Headers | None = None, @@ -387,9 +317,7 @@ async def create( timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> Entry: """ - Create a knowledge entry for a project. - - Raises: HTTPException: If an existing entry is found with the same question. + Create a new knowledge entry for a project. Args: extra_headers: Send extra headers @@ -402,12 +330,24 @@ async def create( """ if not project_id: raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + extra_headers = { + **strip_not_given( + { + "x-client-library-version": x_client_library_version, + "x-integration-type": x_integration_type, + "x-source": x_source, + "x-stainless-package-version": x_stainless_package_version, + } + ), + **(extra_headers or {}), + } return await self._post( f"/api/projects/{project_id}/entries/", body=await async_maybe_transform( { "question": question, "answer": answer, + "draft_answer": draft_answer, }, entry_create_params.EntryCreateParams, ), @@ -459,7 +399,7 @@ async def update( *, project_id: str, answer: Optional[str] | NotGiven = NOT_GIVEN, - frequency_count: Optional[int] | NotGiven = NOT_GIVEN, + draft_answer: Optional[str] | 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. @@ -489,7 +429,7 @@ async def update( body=await async_maybe_transform( { "answer": answer, - "frequency_count": frequency_count, + "draft_answer": draft_answer, "question": question, }, entry_update_params.EntryUpdateParams, @@ -500,60 +440,6 @@ async def update( cast_to=Entry, ) - def list( - self, - project_id: str, - *, - answered_only: bool | NotGiven = NOT_GIVEN, - limit: int | NotGiven = NOT_GIVEN, - offset: int | NotGiven = NOT_GIVEN, - order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN, - sort: Literal["created_at", "answered_at"] | NotGiven = NOT_GIVEN, - unanswered_only: bool | 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. - extra_headers: Headers | None = None, - extra_query: Query | None = None, - extra_body: Body | None = None, - timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> AsyncPaginator[Entry, AsyncOffsetPageEntries[Entry]]: - """ - List knowledge entries for a project. - - Args: - 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 project_id: - raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") - return self._get_api_list( - f"/api/projects/{project_id}/entries/", - page=AsyncOffsetPageEntries[Entry], - options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - query=maybe_transform( - { - "answered_only": answered_only, - "limit": limit, - "offset": offset, - "order": order, - "sort": sort, - "unanswered_only": unanswered_only, - }, - entry_list_params.EntryListParams, - ), - ), - model=Entry, - ) - async def delete( self, entry_id: str, @@ -591,23 +477,24 @@ async def delete( cast_to=NoneType, ) - async def add_question( + async def query( self, project_id: str, *, question: str, + x_client_library_version: str | NotGiven = NOT_GIVEN, + x_integration_type: str | NotGiven = NOT_GIVEN, + x_source: str | NotGiven = NOT_GIVEN, + x_stainless_package_version: 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. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Entry: + ) -> EntryQueryResponse: """ - Add a question to a project. - - Returns: 201 Created if a new question was added 200 OK if the question already - existed + Query Entries Route Args: extra_headers: Send extra headers @@ -620,55 +507,24 @@ async def add_question( """ if not project_id: raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") - return await self._post( - f"/api/projects/{project_id}/entries/add_question", - body=await async_maybe_transform({"question": question}, entry_add_question_params.EntryAddQuestionParams), - options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers = { + **strip_not_given( + { + "x-client-library-version": x_client_library_version, + "x-integration-type": x_integration_type, + "x-source": x_source, + "x-stainless-package-version": x_stainless_package_version, + } ), - cast_to=Entry, - ) - - async def query( - self, - project_id: str, - *, - question: 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, - ) -> Optional[Entry]: - """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 - (returns None), and (2) matching question found but not yet answered (returns - Entry with answer=None). - - Args: - 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 project_id: - raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}") + **(extra_headers or {}), + } return await self._post( f"/api/projects/{project_id}/entries/query", body=await async_maybe_transform({"question": question}, entry_query_params.EntryQueryParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=Entry, + cast_to=EntryQueryResponse, ) @@ -685,15 +541,9 @@ def __init__(self, entries: EntriesResource) -> None: self.update = to_raw_response_wrapper( entries.update, ) - self.list = to_raw_response_wrapper( - entries.list, - ) self.delete = to_raw_response_wrapper( entries.delete, ) - self.add_question = to_raw_response_wrapper( - entries.add_question, - ) self.query = to_raw_response_wrapper( entries.query, ) @@ -712,15 +562,9 @@ def __init__(self, entries: AsyncEntriesResource) -> None: self.update = async_to_raw_response_wrapper( entries.update, ) - self.list = async_to_raw_response_wrapper( - entries.list, - ) self.delete = async_to_raw_response_wrapper( entries.delete, ) - self.add_question = async_to_raw_response_wrapper( - entries.add_question, - ) self.query = async_to_raw_response_wrapper( entries.query, ) @@ -739,15 +583,9 @@ def __init__(self, entries: EntriesResource) -> None: self.update = to_streamed_response_wrapper( entries.update, ) - self.list = to_streamed_response_wrapper( - entries.list, - ) self.delete = to_streamed_response_wrapper( entries.delete, ) - self.add_question = to_streamed_response_wrapper( - entries.add_question, - ) self.query = to_streamed_response_wrapper( entries.query, ) @@ -766,15 +604,9 @@ def __init__(self, entries: AsyncEntriesResource) -> None: self.update = async_to_streamed_response_wrapper( entries.update, ) - self.list = async_to_streamed_response_wrapper( - entries.list, - ) self.delete = async_to_streamed_response_wrapper( entries.delete, ) - self.add_question = async_to_streamed_response_wrapper( - entries.add_question, - ) self.query = async_to_streamed_response_wrapper( entries.query, ) diff --git a/src/codex/resources/projects/projects.py b/src/codex/resources/projects/projects.py index 38d7b03..8a7ff1b 100644 --- a/src/codex/resources/projects/projects.py +++ b/src/codex/resources/projects/projects.py @@ -21,6 +21,14 @@ maybe_transform, async_maybe_transform, ) +from .clusters import ( + ClustersResource, + AsyncClustersResource, + ClustersResourceWithRawResponse, + AsyncClustersResourceWithRawResponse, + ClustersResourceWithStreamingResponse, + AsyncClustersResourceWithStreamingResponse, +) from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( @@ -53,6 +61,10 @@ def access_keys(self) -> AccessKeysResource: def entries(self) -> EntriesResource: return EntriesResource(self._client) + @cached_property + def clusters(self) -> ClustersResource: + return ClustersResource(self._client) + @cached_property def with_raw_response(self) -> ProjectsResourceWithRawResponse: """ @@ -321,6 +333,10 @@ def access_keys(self) -> AsyncAccessKeysResource: def entries(self) -> AsyncEntriesResource: return AsyncEntriesResource(self._client) + @cached_property + def clusters(self) -> AsyncClustersResource: + return AsyncClustersResource(self._client) + @cached_property def with_raw_response(self) -> AsyncProjectsResourceWithRawResponse: """ @@ -611,6 +627,10 @@ def access_keys(self) -> AccessKeysResourceWithRawResponse: def entries(self) -> EntriesResourceWithRawResponse: return EntriesResourceWithRawResponse(self._projects.entries) + @cached_property + def clusters(self) -> ClustersResourceWithRawResponse: + return ClustersResourceWithRawResponse(self._projects.clusters) + class AsyncProjectsResourceWithRawResponse: def __init__(self, projects: AsyncProjectsResource) -> None: @@ -643,6 +663,10 @@ def access_keys(self) -> AsyncAccessKeysResourceWithRawResponse: def entries(self) -> AsyncEntriesResourceWithRawResponse: return AsyncEntriesResourceWithRawResponse(self._projects.entries) + @cached_property + def clusters(self) -> AsyncClustersResourceWithRawResponse: + return AsyncClustersResourceWithRawResponse(self._projects.clusters) + class ProjectsResourceWithStreamingResponse: def __init__(self, projects: ProjectsResource) -> None: @@ -675,6 +699,10 @@ def access_keys(self) -> AccessKeysResourceWithStreamingResponse: def entries(self) -> EntriesResourceWithStreamingResponse: return EntriesResourceWithStreamingResponse(self._projects.entries) + @cached_property + def clusters(self) -> ClustersResourceWithStreamingResponse: + return ClustersResourceWithStreamingResponse(self._projects.clusters) + class AsyncProjectsResourceWithStreamingResponse: def __init__(self, projects: AsyncProjectsResource) -> None: @@ -706,3 +734,7 @@ def access_keys(self) -> AsyncAccessKeysResourceWithStreamingResponse: @cached_property def entries(self) -> AsyncEntriesResourceWithStreamingResponse: return AsyncEntriesResourceWithStreamingResponse(self._projects.entries) + + @cached_property + def clusters(self) -> AsyncClustersResourceWithStreamingResponse: + return AsyncClustersResourceWithStreamingResponse(self._projects.clusters) diff --git a/src/codex/types/projects/__init__.py b/src/codex/types/projects/__init__.py index 44c304f..2733406 100644 --- a/src/codex/types/projects/__init__.py +++ b/src/codex/types/projects/__init__.py @@ -4,14 +4,16 @@ from .entry import Entry as Entry from .access_key_schema import AccessKeySchema as AccessKeySchema -from .entry_list_params import EntryListParams as EntryListParams from .entry_query_params import EntryQueryParams as EntryQueryParams +from .cluster_list_params import ClusterListParams as ClusterListParams from .entry_create_params import EntryCreateParams as EntryCreateParams from .entry_update_params import EntryUpdateParams as EntryUpdateParams +from .entry_query_response import EntryQueryResponse as EntryQueryResponse +from .cluster_list_response import ClusterListResponse as ClusterListResponse from .access_key_create_params import AccessKeyCreateParams as AccessKeyCreateParams from .access_key_list_response import AccessKeyListResponse as AccessKeyListResponse from .access_key_update_params import AccessKeyUpdateParams as AccessKeyUpdateParams -from .entry_add_question_params import EntryAddQuestionParams as EntryAddQuestionParams +from .cluster_list_variants_response import ClusterListVariantsResponse as ClusterListVariantsResponse from .access_key_retrieve_project_id_response import ( AccessKeyRetrieveProjectIDResponse as AccessKeyRetrieveProjectIDResponse, ) diff --git a/src/codex/types/projects/access_key_create_params.py b/src/codex/types/projects/access_key_create_params.py index 1cbc202..cf5f00f 100644 --- a/src/codex/types/projects/access_key_create_params.py +++ b/src/codex/types/projects/access_key_create_params.py @@ -17,3 +17,11 @@ class AccessKeyCreateParams(TypedDict, total=False): description: Optional[str] expires_at: Annotated[Union[str, datetime, None], PropertyInfo(format="iso8601")] + + x_client_library_version: Annotated[str, PropertyInfo(alias="x-client-library-version")] + + x_integration_type: Annotated[str, PropertyInfo(alias="x-integration-type")] + + x_source: Annotated[str, PropertyInfo(alias="x-source")] + + x_stainless_package_version: Annotated[str, PropertyInfo(alias="x-stainless-package-version")] diff --git a/src/codex/types/projects/cluster_list_params.py b/src/codex/types/projects/cluster_list_params.py new file mode 100644 index 0000000..438b481 --- /dev/null +++ b/src/codex/types/projects/cluster_list_params.py @@ -0,0 +1,20 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import List +from typing_extensions import Literal, TypedDict + +__all__ = ["ClusterListParams"] + + +class ClusterListParams(TypedDict, total=False): + limit: int + + offset: int + + order: Literal["asc", "desc"] + + sort: Literal["created_at", "answered_at", "cluster_frequency_count"] + + states: List[Literal["unanswered", "draft", "published", "published_with_draft"]] diff --git a/src/codex/types/projects/cluster_list_response.py b/src/codex/types/projects/cluster_list_response.py new file mode 100644 index 0000000..7b4ef3a --- /dev/null +++ b/src/codex/types/projects/cluster_list_response.py @@ -0,0 +1,36 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from datetime import datetime +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["ClusterListResponse"] + + +class ClusterListResponse(BaseModel): + id: str + + cluster_frequency_count: int + + created_at: datetime + + project_id: str + + question: str + + state: Literal["unanswered", "draft", "published", "published_with_draft"] + + answer: Optional[str] = None + + answered_at: Optional[datetime] = None + + draft_answer: Optional[str] = None + + draft_answer_last_edited: Optional[datetime] = None + + frequency_count: Optional[int] = None + """number of times the entry matched for a /query request""" + + representative_entry_id: Optional[str] = None diff --git a/src/codex/types/projects/cluster_list_variants_response.py b/src/codex/types/projects/cluster_list_variants_response.py new file mode 100644 index 0000000..aa35905 --- /dev/null +++ b/src/codex/types/projects/cluster_list_variants_response.py @@ -0,0 +1,14 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List + +from .entry import Entry +from ..._models import BaseModel + +__all__ = ["ClusterListVariantsResponse"] + + +class ClusterListVariantsResponse(BaseModel): + entries: List[Entry] + + total_count: int diff --git a/src/codex/types/projects/entry.py b/src/codex/types/projects/entry.py index 4621cc4..442eddd 100644 --- a/src/codex/types/projects/entry.py +++ b/src/codex/types/projects/entry.py @@ -2,6 +2,7 @@ from typing import Optional from datetime import datetime +from typing_extensions import Literal from ..._models import BaseModel @@ -9,14 +10,20 @@ class Entry(BaseModel): + id: str + created_at: datetime + project_id: str + question: str - id: Optional[str] = None + state: Literal["unanswered", "draft", "published", "published_with_draft"] answer: Optional[str] = None answered_at: Optional[datetime] = None - frequency_count: Optional[int] = None + draft_answer: Optional[str] = None + + draft_answer_last_edited: Optional[datetime] = None diff --git a/src/codex/types/projects/entry_add_question_params.py b/src/codex/types/projects/entry_add_question_params.py deleted file mode 100644 index e2d009b..0000000 --- a/src/codex/types/projects/entry_add_question_params.py +++ /dev/null @@ -1,11 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from __future__ import annotations - -from typing_extensions import Required, TypedDict - -__all__ = ["EntryAddQuestionParams"] - - -class EntryAddQuestionParams(TypedDict, total=False): - question: Required[str] diff --git a/src/codex/types/projects/entry_create_params.py b/src/codex/types/projects/entry_create_params.py index 1ac23dd..0022942 100644 --- a/src/codex/types/projects/entry_create_params.py +++ b/src/codex/types/projects/entry_create_params.py @@ -3,7 +3,9 @@ from __future__ import annotations from typing import Optional -from typing_extensions import Required, TypedDict +from typing_extensions import Required, Annotated, TypedDict + +from ..._utils import PropertyInfo __all__ = ["EntryCreateParams"] @@ -12,3 +14,13 @@ class EntryCreateParams(TypedDict, total=False): question: Required[str] answer: Optional[str] + + draft_answer: Optional[str] + + x_client_library_version: Annotated[str, PropertyInfo(alias="x-client-library-version")] + + x_integration_type: Annotated[str, PropertyInfo(alias="x-integration-type")] + + x_source: Annotated[str, PropertyInfo(alias="x-source")] + + x_stainless_package_version: Annotated[str, PropertyInfo(alias="x-stainless-package-version")] diff --git a/src/codex/types/projects/entry_list_params.py b/src/codex/types/projects/entry_list_params.py deleted file mode 100644 index b50181f..0000000 --- a/src/codex/types/projects/entry_list_params.py +++ /dev/null @@ -1,21 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -from __future__ import annotations - -from typing_extensions import Literal, TypedDict - -__all__ = ["EntryListParams"] - - -class EntryListParams(TypedDict, total=False): - answered_only: bool - - limit: int - - offset: int - - order: Literal["asc", "desc"] - - sort: Literal["created_at", "answered_at"] - - unanswered_only: bool diff --git a/src/codex/types/projects/entry_query_params.py b/src/codex/types/projects/entry_query_params.py index b6fbc43..bc0e317 100644 --- a/src/codex/types/projects/entry_query_params.py +++ b/src/codex/types/projects/entry_query_params.py @@ -2,10 +2,20 @@ from __future__ import annotations -from typing_extensions import Required, TypedDict +from typing_extensions import Required, Annotated, TypedDict + +from ..._utils import PropertyInfo __all__ = ["EntryQueryParams"] class EntryQueryParams(TypedDict, total=False): question: Required[str] + + x_client_library_version: Annotated[str, PropertyInfo(alias="x-client-library-version")] + + x_integration_type: Annotated[str, PropertyInfo(alias="x-integration-type")] + + x_source: Annotated[str, PropertyInfo(alias="x-source")] + + x_stainless_package_version: Annotated[str, PropertyInfo(alias="x-stainless-package-version")] diff --git a/src/codex/types/projects/entry_query_response.py b/src/codex/types/projects/entry_query_response.py new file mode 100644 index 0000000..ad106d7 --- /dev/null +++ b/src/codex/types/projects/entry_query_response.py @@ -0,0 +1,23 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from ..._models import BaseModel + +__all__ = ["EntryQueryResponse", "Entry"] + + +class Entry(BaseModel): + id: str + + question: str + + answer: Optional[str] = None + + draft_answer: Optional[str] = None + + +class EntryQueryResponse(BaseModel): + entry: Entry + + answer: Optional[str] = None diff --git a/src/codex/types/projects/entry_update_params.py b/src/codex/types/projects/entry_update_params.py index ba10549..aac256f 100644 --- a/src/codex/types/projects/entry_update_params.py +++ b/src/codex/types/projects/entry_update_params.py @@ -13,6 +13,6 @@ class EntryUpdateParams(TypedDict, total=False): answer: Optional[str] - frequency_count: Optional[int] + draft_answer: Optional[str] question: Optional[str] diff --git a/tests/api_resources/projects/test_access_keys.py b/tests/api_resources/projects/test_access_keys.py index 240c31e..ad4ee5e 100644 --- a/tests/api_resources/projects/test_access_keys.py +++ b/tests/api_resources/projects/test_access_keys.py @@ -39,6 +39,10 @@ def test_method_create_with_all_params(self, client: Codex) -> None: name="name", description="description", expires_at=parse_datetime("2019-12-27T18:11:19.117Z"), + x_client_library_version="x-client-library-version", + x_integration_type="x-integration-type", + x_source="x-source", + x_stainless_package_version="x-stainless-package-version", ) assert_matches_type(AccessKeySchema, access_key, path=["response"]) @@ -395,6 +399,10 @@ async def test_method_create_with_all_params(self, async_client: AsyncCodex) -> name="name", description="description", expires_at=parse_datetime("2019-12-27T18:11:19.117Z"), + x_client_library_version="x-client-library-version", + x_integration_type="x-integration-type", + x_source="x-source", + x_stainless_package_version="x-stainless-package-version", ) assert_matches_type(AccessKeySchema, access_key, path=["response"]) diff --git a/tests/api_resources/projects/test_clusters.py b/tests/api_resources/projects/test_clusters.py new file mode 100644 index 0000000..5a46497 --- /dev/null +++ b/tests/api_resources/projects/test_clusters.py @@ -0,0 +1,241 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from codex import Codex, AsyncCodex +from tests.utils import assert_matches_type +from codex.pagination import SyncOffsetPageClusters, AsyncOffsetPageClusters +from codex.types.projects import ClusterListResponse, ClusterListVariantsResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestClusters: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + def test_method_list(self, client: Codex) -> None: + cluster = client.projects.clusters.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + assert_matches_type(SyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_method_list_with_all_params(self, client: Codex) -> None: + cluster = client.projects.clusters.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + limit=1, + offset=0, + order="asc", + sort="created_at", + states=["unanswered"], + ) + assert_matches_type(SyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_list(self, client: Codex) -> None: + response = client.projects.clusters.with_raw_response.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + cluster = response.parse() + assert_matches_type(SyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_list(self, client: Codex) -> None: + with client.projects.clusters.with_streaming_response.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + cluster = response.parse() + assert_matches_type(SyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_list(self, client: Codex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): + client.projects.clusters.with_raw_response.list( + project_id="", + ) + + @pytest.mark.skip() + @parametrize + def test_method_list_variants(self, client: Codex) -> None: + cluster = client.projects.clusters.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + assert_matches_type(ClusterListVariantsResponse, cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_raw_response_list_variants(self, client: Codex) -> None: + response = client.projects.clusters.with_raw_response.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + cluster = response.parse() + assert_matches_type(ClusterListVariantsResponse, cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + def test_streaming_response_list_variants(self, client: Codex) -> None: + with client.projects.clusters.with_streaming_response.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + cluster = response.parse() + assert_matches_type(ClusterListVariantsResponse, cluster, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + def test_path_params_list_variants(self, client: Codex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): + client.projects.clusters.with_raw_response.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="", + ) + + with pytest.raises( + ValueError, match=r"Expected a non-empty value for `representative_entry_id` but received ''" + ): + client.projects.clusters.with_raw_response.list_variants( + representative_entry_id="", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + +class TestAsyncClusters: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @pytest.mark.skip() + @parametrize + async def test_method_list(self, async_client: AsyncCodex) -> None: + cluster = await async_client.projects.clusters.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + assert_matches_type(AsyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_method_list_with_all_params(self, async_client: AsyncCodex) -> None: + cluster = await async_client.projects.clusters.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + limit=1, + offset=0, + order="asc", + sort="created_at", + states=["unanswered"], + ) + assert_matches_type(AsyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_list(self, async_client: AsyncCodex) -> None: + response = await async_client.projects.clusters.with_raw_response.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + cluster = await response.parse() + assert_matches_type(AsyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_list(self, async_client: AsyncCodex) -> None: + async with async_client.projects.clusters.with_streaming_response.list( + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + cluster = await response.parse() + assert_matches_type(AsyncOffsetPageClusters[ClusterListResponse], cluster, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_list(self, async_client: AsyncCodex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): + await async_client.projects.clusters.with_raw_response.list( + project_id="", + ) + + @pytest.mark.skip() + @parametrize + async def test_method_list_variants(self, async_client: AsyncCodex) -> None: + cluster = await async_client.projects.clusters.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + assert_matches_type(ClusterListVariantsResponse, cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_raw_response_list_variants(self, async_client: AsyncCodex) -> None: + response = await async_client.projects.clusters.with_raw_response.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + cluster = await response.parse() + assert_matches_type(ClusterListVariantsResponse, cluster, path=["response"]) + + @pytest.mark.skip() + @parametrize + async def test_streaming_response_list_variants(self, async_client: AsyncCodex) -> None: + async with async_client.projects.clusters.with_streaming_response.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + cluster = await response.parse() + assert_matches_type(ClusterListVariantsResponse, cluster, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @pytest.mark.skip() + @parametrize + async def test_path_params_list_variants(self, async_client: AsyncCodex) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): + await async_client.projects.clusters.with_raw_response.list_variants( + representative_entry_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + project_id="", + ) + + with pytest.raises( + ValueError, match=r"Expected a non-empty value for `representative_entry_id` but received ''" + ): + await async_client.projects.clusters.with_raw_response.list_variants( + representative_entry_id="", + project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) diff --git a/tests/api_resources/projects/test_entries.py b/tests/api_resources/projects/test_entries.py index 026add4..e8965e4 100644 --- a/tests/api_resources/projects/test_entries.py +++ b/tests/api_resources/projects/test_entries.py @@ -3,16 +3,13 @@ from __future__ import annotations import os -from typing import Any, Optional, cast +from typing import Any, cast import pytest from codex import Codex, AsyncCodex from tests.utils import assert_matches_type -from codex.pagination import SyncOffsetPageEntries, AsyncOffsetPageEntries -from codex.types.projects import ( - Entry, -) +from codex.types.projects import Entry, EntryQueryResponse base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -36,6 +33,11 @@ def test_method_create_with_all_params(self, client: Codex) -> None: project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", question="question", answer="answer", + draft_answer="draft_answer", + x_client_library_version="x-client-library-version", + x_integration_type="x-integration-type", + x_source="x-source", + x_stainless_package_version="x-stainless-package-version", ) assert_matches_type(Entry, entry, path=["response"]) @@ -144,7 +146,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, + draft_answer="draft_answer", question="question", ) assert_matches_type(Entry, entry, path=["response"]) @@ -192,62 +194,6 @@ def test_path_params_update(self, client: Codex) -> None: project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - @pytest.mark.skip() - @parametrize - def test_method_list(self, client: Codex) -> None: - entry = client.projects.entries.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) - assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_method_list_with_all_params(self, client: Codex) -> None: - entry = client.projects.entries.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - answered_only=True, - limit=1, - offset=0, - order="asc", - sort="created_at", - unanswered_only=True, - ) - assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_list(self, client: Codex) -> None: - response = client.projects.entries.with_raw_response.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - entry = response.parse() - assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_streaming_response_list(self, client: Codex) -> None: - with client.projects.entries.with_streaming_response.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - entry = response.parse() - assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - def test_path_params_list(self, client: Codex) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): - client.projects.entries.with_raw_response.list( - project_id="", - ) - @pytest.mark.skip() @parametrize def test_method_delete(self, client: Codex) -> None: @@ -302,58 +248,25 @@ def test_path_params_delete(self, client: Codex) -> None: @pytest.mark.skip() @parametrize - def test_method_add_question(self, client: Codex) -> None: - entry = client.projects.entries.add_question( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - question="question", - ) - assert_matches_type(Entry, entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_add_question(self, client: Codex) -> None: - response = client.projects.entries.with_raw_response.add_question( + def test_method_query(self, client: Codex) -> None: + entry = client.projects.entries.query( project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", question="question", ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - entry = response.parse() - assert_matches_type(Entry, entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) @pytest.mark.skip() @parametrize - def test_streaming_response_add_question(self, client: Codex) -> None: - with client.projects.entries.with_streaming_response.add_question( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - question="question", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - entry = response.parse() - assert_matches_type(Entry, entry, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - def test_path_params_add_question(self, client: Codex) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): - client.projects.entries.with_raw_response.add_question( - project_id="", - question="question", - ) - - @pytest.mark.skip() - @parametrize - def test_method_query(self, client: Codex) -> None: + def test_method_query_with_all_params(self, client: Codex) -> None: entry = client.projects.entries.query( project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", question="question", + x_client_library_version="x-client-library-version", + x_integration_type="x-integration-type", + x_source="x-source", + x_stainless_package_version="x-stainless-package-version", ) - assert_matches_type(Optional[Entry], entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) @pytest.mark.skip() @parametrize @@ -366,7 +279,7 @@ def test_raw_response_query(self, client: Codex) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" entry = response.parse() - assert_matches_type(Optional[Entry], entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) @pytest.mark.skip() @parametrize @@ -379,7 +292,7 @@ def test_streaming_response_query(self, client: Codex) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" entry = response.parse() - assert_matches_type(Optional[Entry], entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) assert cast(Any, response.is_closed) is True @@ -412,6 +325,11 @@ async def test_method_create_with_all_params(self, async_client: AsyncCodex) -> project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", question="question", answer="answer", + draft_answer="draft_answer", + x_client_library_version="x-client-library-version", + x_integration_type="x-integration-type", + x_source="x-source", + x_stainless_package_version="x-stainless-package-version", ) assert_matches_type(Entry, entry, path=["response"]) @@ -520,7 +438,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, + draft_answer="draft_answer", question="question", ) assert_matches_type(Entry, entry, path=["response"]) @@ -568,62 +486,6 @@ async def test_path_params_update(self, async_client: AsyncCodex) -> None: project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - @pytest.mark.skip() - @parametrize - async def test_method_list(self, async_client: AsyncCodex) -> None: - entry = await async_client.projects.entries.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) - assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_method_list_with_all_params(self, async_client: AsyncCodex) -> None: - entry = await async_client.projects.entries.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - answered_only=True, - limit=1, - offset=0, - order="asc", - sort="created_at", - unanswered_only=True, - ) - assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_list(self, async_client: AsyncCodex) -> None: - response = await async_client.projects.entries.with_raw_response.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - entry = await response.parse() - assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_streaming_response_list(self, async_client: AsyncCodex) -> None: - async with async_client.projects.entries.with_streaming_response.list( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - entry = await response.parse() - assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - async def test_path_params_list(self, async_client: AsyncCodex) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): - await async_client.projects.entries.with_raw_response.list( - project_id="", - ) - @pytest.mark.skip() @parametrize async def test_method_delete(self, async_client: AsyncCodex) -> None: @@ -678,58 +540,25 @@ async def test_path_params_delete(self, async_client: AsyncCodex) -> None: @pytest.mark.skip() @parametrize - async def test_method_add_question(self, async_client: AsyncCodex) -> None: - entry = await async_client.projects.entries.add_question( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - question="question", - ) - assert_matches_type(Entry, entry, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_add_question(self, async_client: AsyncCodex) -> None: - response = await async_client.projects.entries.with_raw_response.add_question( + async def test_method_query(self, async_client: AsyncCodex) -> None: + entry = await async_client.projects.entries.query( project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", question="question", ) - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - entry = await response.parse() - assert_matches_type(Entry, entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) @pytest.mark.skip() @parametrize - async def test_streaming_response_add_question(self, async_client: AsyncCodex) -> None: - async with async_client.projects.entries.with_streaming_response.add_question( - project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - question="question", - ) as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - entry = await response.parse() - assert_matches_type(Entry, entry, path=["response"]) - - assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - async def test_path_params_add_question(self, async_client: AsyncCodex) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): - await async_client.projects.entries.with_raw_response.add_question( - project_id="", - question="question", - ) - - @pytest.mark.skip() - @parametrize - async def test_method_query(self, async_client: AsyncCodex) -> None: + async def test_method_query_with_all_params(self, async_client: AsyncCodex) -> None: entry = await async_client.projects.entries.query( project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", question="question", + x_client_library_version="x-client-library-version", + x_integration_type="x-integration-type", + x_source="x-source", + x_stainless_package_version="x-stainless-package-version", ) - assert_matches_type(Optional[Entry], entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) @pytest.mark.skip() @parametrize @@ -742,7 +571,7 @@ async def test_raw_response_query(self, async_client: AsyncCodex) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" entry = await response.parse() - assert_matches_type(Optional[Entry], entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) @pytest.mark.skip() @parametrize @@ -755,7 +584,7 @@ async def test_streaming_response_query(self, async_client: AsyncCodex) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" entry = await response.parse() - assert_matches_type(Optional[Entry], entry, path=["response"]) + assert_matches_type(EntryQueryResponse, entry, path=["response"]) assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/test_health.py b/tests/api_resources/test_health.py index 0970012..ed942cd 100644 --- a/tests/api_resources/test_health.py +++ b/tests/api_resources/test_health.py @@ -73,34 +73,6 @@ def test_streaming_response_db(self, client: Codex) -> None: assert cast(Any, response.is_closed) is True - @pytest.mark.skip() - @parametrize - def test_method_weaviate(self, client: Codex) -> None: - health = client.health.weaviate() - assert_matches_type(HealthCheckResponse, health, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_raw_response_weaviate(self, client: Codex) -> None: - response = client.health.with_raw_response.weaviate() - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - health = response.parse() - assert_matches_type(HealthCheckResponse, health, path=["response"]) - - @pytest.mark.skip() - @parametrize - def test_streaming_response_weaviate(self, client: Codex) -> None: - with client.health.with_streaming_response.weaviate() as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - health = response.parse() - assert_matches_type(HealthCheckResponse, health, path=["response"]) - - assert cast(Any, response.is_closed) is True - class TestAsyncHealth: parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) @@ -160,31 +132,3 @@ async def test_streaming_response_db(self, async_client: AsyncCodex) -> None: assert_matches_type(HealthCheckResponse, health, path=["response"]) assert cast(Any, response.is_closed) is True - - @pytest.mark.skip() - @parametrize - async def test_method_weaviate(self, async_client: AsyncCodex) -> None: - health = await async_client.health.weaviate() - assert_matches_type(HealthCheckResponse, health, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_raw_response_weaviate(self, async_client: AsyncCodex) -> None: - response = await async_client.health.with_raw_response.weaviate() - - assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - health = await response.parse() - assert_matches_type(HealthCheckResponse, health, path=["response"]) - - @pytest.mark.skip() - @parametrize - async def test_streaming_response_weaviate(self, async_client: AsyncCodex) -> None: - async with async_client.health.with_streaming_response.weaviate() as response: - assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" - - health = await response.parse() - assert_matches_type(HealthCheckResponse, health, path=["response"]) - - assert cast(Any, response.is_closed) is True diff --git a/tests/test_models.py b/tests/test_models.py index 26df341..73e6d67 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -854,3 +854,35 @@ class Model(BaseModel): m = construct_type(value={"cls": "foo"}, type_=Model) assert isinstance(m, Model) assert isinstance(m.cls, str) + + +def test_discriminated_union_case() -> None: + class A(BaseModel): + type: Literal["a"] + + data: bool + + class B(BaseModel): + type: Literal["b"] + + data: List[Union[A, object]] + + class ModelA(BaseModel): + type: Literal["modelA"] + + data: int + + class ModelB(BaseModel): + type: Literal["modelB"] + + required: str + + data: Union[A, B] + + # when constructing ModelA | ModelB, value data doesn't match ModelB exactly - missing `required` + m = construct_type( + value={"type": "modelB", "data": {"type": "a", "data": True}}, + type_=cast(Any, Annotated[Union[ModelA, ModelB], PropertyInfo(discriminator="type")]), + ) + + assert isinstance(m, ModelB)