Skip to content

fix: update pagination scheme #11

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

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ Methods:
Types:

```python
from codex.types.projects import Entry, EntryListResponse
from codex.types.projects import Entry
```

Methods:

- <code title="post /api/projects/{project_id}/entries/">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">create</a>(project_id, \*\*<a href="src/codex/types/projects/entry_create_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
- <code title="get /api/projects/{project_id}/entries/{entry_id}">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">retrieve</a>(entry_id, \*, project_id) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
- <code title="put /api/projects/{project_id}/entries/{entry_id}">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">update</a>(entry_id, \*, project_id, \*\*<a href="src/codex/types/projects/entry_update_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
- <code title="get /api/projects/{project_id}/entries/">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">list</a>(project_id, \*\*<a href="src/codex/types/projects/entry_list_params.py">params</a>) -> <a href="./src/codex/types/projects/entry_list_response.py">EntryListResponse</a></code>
- <code title="get /api/projects/{project_id}/entries/">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">list</a>(project_id, \*\*<a href="src/codex/types/projects/entry_list_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">SyncOffsetPageEntries[Entry]</a></code>
- <code title="delete /api/projects/{project_id}/entries/{entry_id}">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">delete</a>(entry_id, \*, project_id) -> None</code>
- <code title="post /api/projects/{project_id}/entries/add_question">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">add_question</a>(project_id, \*\*<a href="src/codex/types/projects/entry_add_question_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
- <code title="post /api/projects/{project_id}/entries/query">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">query</a>(project_id, \*\*<a href="src/codex/types/projects/entry_query_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Optional[Entry]</a></code>
18 changes: 0 additions & 18 deletions src/codex/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ def next_page_info(self) -> Optional[PageInfo]:

return None

@classmethod
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
return cls.construct(
None,
**{
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"entries": data}),
},
)


class AsyncOffsetPageEntries(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
entries: List[_T]
Expand Down Expand Up @@ -150,12 +141,3 @@ def next_page_info(self) -> Optional[PageInfo]:
return PageInfo(params={"offset": current_count})

return None

@classmethod
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
return cls.construct(
None,
**{
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"entries": data}),
},
)
22 changes: 12 additions & 10 deletions src/codex/resources/projects/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
async_to_raw_response_wrapper,
async_to_streamed_response_wrapper,
)
from ..._base_client import make_request_options
from ...pagination import SyncOffsetPageEntries, AsyncOffsetPageEntries
from ..._base_client import AsyncPaginator, make_request_options
from ...types.projects import (
entry_list_params,
entry_query_params,
Expand All @@ -29,7 +30,6 @@
entry_add_question_params,
)
from ...types.projects.entry import Entry
from ...types.projects.entry_list_response import EntryListResponse

__all__ = ["EntriesResource", "AsyncEntriesResource"]

Expand Down Expand Up @@ -187,7 +187,7 @@ def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> EntryListResponse:
) -> SyncOffsetPageEntries[Entry]:
"""
List knowledge entries for a project.

Expand All @@ -200,8 +200,9 @@ def list(

timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
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,
Expand All @@ -219,7 +220,7 @@ def list(
entry_list_params.EntryListParams,
),
),
cast_to=EntryListResponse,
model=Entry,
)

def delete(
Expand Down Expand Up @@ -469,7 +470,7 @@ async def update(
cast_to=Entry,
)

async def list(
def list(
self,
project_id: int,
*,
Expand All @@ -485,7 +486,7 @@ async def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> EntryListResponse:
) -> AsyncPaginator[Entry, AsyncOffsetPageEntries[Entry]]:
"""
List knowledge entries for a project.

Expand All @@ -498,14 +499,15 @@ async def list(

timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._get(
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=await async_maybe_transform(
query=maybe_transform(
{
"answered_only": answered_only,
"limit": limit,
Expand All @@ -517,7 +519,7 @@ async def list(
entry_list_params.EntryListParams,
),
),
cast_to=EntryListResponse,
model=Entry,
)

async def delete(
Expand Down
1 change: 0 additions & 1 deletion src/codex/types/projects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .entry_list_params import EntryListParams as EntryListParams
from .entry_query_params import EntryQueryParams as EntryQueryParams
from .entry_create_params import EntryCreateParams as EntryCreateParams
from .entry_list_response import EntryListResponse as EntryListResponse
from .entry_update_params import EntryUpdateParams as EntryUpdateParams
from .access_key_create_params import AccessKeyCreateParams as AccessKeyCreateParams
from .access_key_list_response import AccessKeyListResponse as AccessKeyListResponse
Expand Down
14 changes: 0 additions & 14 deletions src/codex/types/projects/entry_list_response.py

This file was deleted.

18 changes: 9 additions & 9 deletions tests/api_resources/projects/test_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from codex import Codex, AsyncCodex
from tests.utils import assert_matches_type
from codex.pagination import SyncOffsetPageEntries, AsyncOffsetPageEntries
from codex.types.projects import (
Entry,
EntryListResponse,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_method_list(self, client: Codex) -> None:
entry = client.projects.entries.list(
project_id=0,
)
assert_matches_type(EntryListResponse, entry, path=["response"])
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])

@pytest.mark.skip()
@parametrize
Expand All @@ -190,7 +190,7 @@ def test_method_list_with_all_params(self, client: Codex) -> None:
sort="created_at",
unanswered_only=True,
)
assert_matches_type(EntryListResponse, entry, path=["response"])
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])

@pytest.mark.skip()
@parametrize
Expand All @@ -202,7 +202,7 @@ def test_raw_response_list(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(EntryListResponse, entry, path=["response"])
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])

@pytest.mark.skip()
@parametrize
Expand All @@ -214,7 +214,7 @@ def test_streaming_response_list(self, client: Codex) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

entry = response.parse()
assert_matches_type(EntryListResponse, entry, path=["response"])
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down Expand Up @@ -498,7 +498,7 @@ async def test_method_list(self, async_client: AsyncCodex) -> None:
entry = await async_client.projects.entries.list(
project_id=0,
)
assert_matches_type(EntryListResponse, entry, path=["response"])
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])

@pytest.mark.skip()
@parametrize
Expand All @@ -512,7 +512,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncCodex) -> No
sort="created_at",
unanswered_only=True,
)
assert_matches_type(EntryListResponse, entry, path=["response"])
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])

@pytest.mark.skip()
@parametrize
Expand All @@ -524,7 +524,7 @@ async def test_raw_response_list(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(EntryListResponse, entry, path=["response"])
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])

@pytest.mark.skip()
@parametrize
Expand All @@ -536,7 +536,7 @@ async def test_streaming_response_list(self, async_client: AsyncCodex) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

entry = await response.parse()
assert_matches_type(EntryListResponse, entry, path=["response"])
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down