Skip to content

Commit ee66bc5

Browse files
feat(types): replace List[str] with SequenceNotStr in params
1 parent f00b892 commit ee66bc5

12 files changed

+60
-47
lines changed

src/contextual/_utils/_transform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
lru_cache,
1717
is_mapping,
1818
is_iterable,
19+
is_sequence,
1920
)
2021
from .._files import is_base64_file_input
2122
from ._typing import (
@@ -24,6 +25,7 @@
2425
extract_type_arg,
2526
is_iterable_type,
2627
is_required_type,
28+
is_sequence_type,
2729
is_annotated_type,
2830
strip_annotated_type,
2931
)
@@ -184,6 +186,8 @@ def _transform_recursive(
184186
(is_list_type(stripped_type) and is_list(data))
185187
# Iterable[T]
186188
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
189+
# Sequence[T]
190+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
187191
):
188192
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
189193
# intended as an iterable, so we don't transform it.
@@ -346,6 +350,8 @@ async def _async_transform_recursive(
346350
(is_list_type(stripped_type) and is_list(data))
347351
# Iterable[T]
348352
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
353+
# Sequence[T]
354+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
349355
):
350356
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
351357
# intended as an iterable, so we don't transform it.

src/contextual/resources/agents/agents.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Any, List, cast
5+
from typing import Any, cast
66

77
import httpx
88

@@ -15,7 +15,7 @@
1515
AsyncQueryResourceWithStreamingResponse,
1616
)
1717
from ...types import agent_list_params, agent_create_params, agent_update_params
18-
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
18+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1919
from ..._utils import maybe_transform, async_maybe_transform
2020
from ..._compat import cached_property
2121
from ..._resource import SyncAPIResource, AsyncAPIResource
@@ -64,12 +64,12 @@ def create(
6464
*,
6565
name: str,
6666
agent_configs: AgentConfigsParam | NotGiven = NOT_GIVEN,
67-
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
67+
datastore_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
6868
description: str | NotGiven = NOT_GIVEN,
6969
filter_prompt: str | NotGiven = NOT_GIVEN,
7070
multiturn_system_prompt: str | NotGiven = NOT_GIVEN,
7171
no_retrieval_system_prompt: str | NotGiven = NOT_GIVEN,
72-
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
72+
suggested_queries: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
7373
system_prompt: str | NotGiven = NOT_GIVEN,
7474
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
7575
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -156,12 +156,12 @@ def update(
156156
agent_id: str,
157157
*,
158158
agent_configs: AgentConfigsParam | NotGiven = NOT_GIVEN,
159-
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
159+
datastore_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
160160
filter_prompt: str | NotGiven = NOT_GIVEN,
161161
llm_model_id: str | NotGiven = NOT_GIVEN,
162162
multiturn_system_prompt: str | NotGiven = NOT_GIVEN,
163163
no_retrieval_system_prompt: str | NotGiven = NOT_GIVEN,
164-
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
164+
suggested_queries: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
165165
system_prompt: str | NotGiven = NOT_GIVEN,
166166
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
167167
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -462,12 +462,12 @@ async def create(
462462
*,
463463
name: str,
464464
agent_configs: AgentConfigsParam | NotGiven = NOT_GIVEN,
465-
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
465+
datastore_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
466466
description: str | NotGiven = NOT_GIVEN,
467467
filter_prompt: str | NotGiven = NOT_GIVEN,
468468
multiturn_system_prompt: str | NotGiven = NOT_GIVEN,
469469
no_retrieval_system_prompt: str | NotGiven = NOT_GIVEN,
470-
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
470+
suggested_queries: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
471471
system_prompt: str | NotGiven = NOT_GIVEN,
472472
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
473473
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -554,12 +554,12 @@ async def update(
554554
agent_id: str,
555555
*,
556556
agent_configs: AgentConfigsParam | NotGiven = NOT_GIVEN,
557-
datastore_ids: List[str] | NotGiven = NOT_GIVEN,
557+
datastore_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
558558
filter_prompt: str | NotGiven = NOT_GIVEN,
559559
llm_model_id: str | NotGiven = NOT_GIVEN,
560560
multiturn_system_prompt: str | NotGiven = NOT_GIVEN,
561561
no_retrieval_system_prompt: str | NotGiven = NOT_GIVEN,
562-
suggested_queries: List[str] | NotGiven = NOT_GIVEN,
562+
suggested_queries: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
563563
system_prompt: str | NotGiven = NOT_GIVEN,
564564
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
565565
# The extra values given here take precedence over values defined on the client or passed to this method.

src/contextual/resources/agents/query.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Union, Iterable
5+
from typing import Union, Iterable
66
from datetime import datetime
77
from typing_extensions import Literal
88

99
import httpx
1010

11-
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
11+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1212
from ..._utils import maybe_transform, async_maybe_transform
1313
from ..._compat import cached_property
1414
from ..._resource import SyncAPIResource, AsyncAPIResource
@@ -253,12 +253,12 @@ def metrics(
253253
self,
254254
agent_id: str,
255255
*,
256-
conversation_ids: List[str] | NotGiven = NOT_GIVEN,
256+
conversation_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
257257
created_after: Union[str, datetime] | NotGiven = NOT_GIVEN,
258258
created_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
259259
limit: int | NotGiven = NOT_GIVEN,
260260
offset: int | NotGiven = NOT_GIVEN,
261-
user_emails: List[str] | NotGiven = NOT_GIVEN,
261+
user_emails: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
262262
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
263263
# The extra values given here take precedence over values defined on the client or passed to this method.
264264
extra_headers: Headers | None = None,
@@ -323,7 +323,7 @@ def retrieval_info(
323323
message_id: str,
324324
*,
325325
agent_id: str,
326-
content_ids: List[str],
326+
content_ids: SequenceNotStr[str],
327327
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
328328
# The extra values given here take precedence over values defined on the client or passed to this method.
329329
extra_headers: Headers | None = None,
@@ -590,12 +590,12 @@ async def metrics(
590590
self,
591591
agent_id: str,
592592
*,
593-
conversation_ids: List[str] | NotGiven = NOT_GIVEN,
593+
conversation_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
594594
created_after: Union[str, datetime] | NotGiven = NOT_GIVEN,
595595
created_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
596596
limit: int | NotGiven = NOT_GIVEN,
597597
offset: int | NotGiven = NOT_GIVEN,
598-
user_emails: List[str] | NotGiven = NOT_GIVEN,
598+
user_emails: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
599599
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
600600
# The extra values given here take precedence over values defined on the client or passed to this method.
601601
extra_headers: Headers | None = None,
@@ -660,7 +660,7 @@ async def retrieval_info(
660660
message_id: str,
661661
*,
662662
agent_id: str,
663-
content_ids: List[str],
663+
content_ids: SequenceNotStr[str],
664664
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
665665
# The extra values given here take precedence over values defined on the client or passed to this method.
666666
extra_headers: Headers | None = None,

src/contextual/resources/generate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Iterable
5+
from typing import Iterable
66

77
import httpx
88

99
from ..types import generate_create_params
10-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
10+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1111
from .._utils import maybe_transform, async_maybe_transform
1212
from .._compat import cached_property
1313
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -46,7 +46,7 @@ def with_streaming_response(self) -> GenerateResourceWithStreamingResponse:
4646
def create(
4747
self,
4848
*,
49-
knowledge: List[str],
49+
knowledge: SequenceNotStr[str],
5050
messages: Iterable[generate_create_params.Message],
5151
model: str,
5252
avoid_commentary: bool | NotGiven = NOT_GIVEN,
@@ -154,7 +154,7 @@ def with_streaming_response(self) -> AsyncGenerateResourceWithStreamingResponse:
154154
async def create(
155155
self,
156156
*,
157-
knowledge: List[str],
157+
knowledge: SequenceNotStr[str],
158158
messages: Iterable[generate_create_params.Message],
159159
model: str,
160160
avoid_commentary: bool | NotGiven = NOT_GIVEN,

src/contextual/resources/rerank.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
from __future__ import annotations
44

5-
from typing import List
6-
75
import httpx
86

97
from ..types import rerank_create_params
10-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
8+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
119
from .._utils import maybe_transform, async_maybe_transform
1210
from .._compat import cached_property
1311
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -46,11 +44,11 @@ def with_streaming_response(self) -> RerankResourceWithStreamingResponse:
4644
def create(
4745
self,
4846
*,
49-
documents: List[str],
47+
documents: SequenceNotStr[str],
5048
model: str,
5149
query: str,
5250
instruction: str | NotGiven = NOT_GIVEN,
53-
metadata: List[str] | NotGiven = NOT_GIVEN,
51+
metadata: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
5452
top_n: int | NotGiven = NOT_GIVEN,
5553
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5654
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -152,11 +150,11 @@ def with_streaming_response(self) -> AsyncRerankResourceWithStreamingResponse:
152150
async def create(
153151
self,
154152
*,
155-
documents: List[str],
153+
documents: SequenceNotStr[str],
156154
model: str,
157155
query: str,
158156
instruction: str | NotGiven = NOT_GIVEN,
159-
metadata: List[str] | NotGiven = NOT_GIVEN,
157+
metadata: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
160158
top_n: int | NotGiven = NOT_GIVEN,
161159
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
162160
# The extra values given here take precedence over values defined on the client or passed to this method.

src/contextual/types/agent_create_params.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from __future__ import annotations
44

5-
from typing import List
65
from typing_extensions import Required, TypedDict
76

7+
from .._types import SequenceNotStr
8+
89
__all__ = ["AgentCreateParams"]
910

1011

@@ -15,7 +16,7 @@ class AgentCreateParams(TypedDict, total=False):
1516
agent_configs: "AgentConfigsParam"
1617
"""The following advanced parameters are experimental and subject to change."""
1718

18-
datastore_ids: List[str]
19+
datastore_ids: SequenceNotStr[str]
1920
"""The IDs of the datastore to associate with this agent."""
2021

2122
description: str
@@ -36,7 +37,7 @@ class AgentCreateParams(TypedDict, total=False):
3637
retrievals that can be used to answer a query.
3738
"""
3839

39-
suggested_queries: List[str]
40+
suggested_queries: SequenceNotStr[str]
4041
"""
4142
These queries will show up as suggestions in the Contextual UI when users load
4243
the agent. We recommend including common queries that users will ask, as well as

src/contextual/types/agent_update_params.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
from __future__ import annotations
44

5-
from typing import List
65
from typing_extensions import TypedDict
76

7+
from .._types import SequenceNotStr
8+
89
__all__ = ["AgentUpdateParams"]
910

1011

1112
class AgentUpdateParams(TypedDict, total=False):
1213
agent_configs: "AgentConfigsParam"
1314
"""The following advanced parameters are experimental and subject to change."""
1415

15-
datastore_ids: List[str]
16+
datastore_ids: SequenceNotStr[str]
1617
"""IDs of the datastore to associate with the agent."""
1718

1819
filter_prompt: str
@@ -38,7 +39,7 @@ class AgentUpdateParams(TypedDict, total=False):
3839
retrievals that can be used to answer a query.
3940
"""
4041

41-
suggested_queries: List[str]
42+
suggested_queries: SequenceNotStr[str]
4243
"""
4344
These queries will show up as suggestions in the Contextual UI when users load
4445
the agent. We recommend including common queries that users will ask, as well as

src/contextual/types/agents/query_metrics_params.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Union
5+
from typing import Union
66
from datetime import datetime
77
from typing_extensions import Annotated, TypedDict
88

9+
from ..._types import SequenceNotStr
910
from ..._utils import PropertyInfo
1011

1112
__all__ = ["QueryMetricsParams"]
1213

1314

1415
class QueryMetricsParams(TypedDict, total=False):
15-
conversation_ids: List[str]
16+
conversation_ids: SequenceNotStr[str]
1617
"""Filter messages by conversation ids."""
1718

1819
created_after: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
@@ -27,5 +28,5 @@ class QueryMetricsParams(TypedDict, total=False):
2728
offset: int
2829
"""Offset for pagination."""
2930

30-
user_emails: List[str]
31+
user_emails: SequenceNotStr[str]
3132
"""Filter messages by users."""

src/contextual/types/agents/query_retrieval_info_params.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
from __future__ import annotations
44

5-
from typing import List
65
from typing_extensions import Required, TypedDict
76

7+
from ..._types import SequenceNotStr
8+
89
__all__ = ["QueryRetrievalInfoParams"]
910

1011

1112
class QueryRetrievalInfoParams(TypedDict, total=False):
1213
agent_id: Required[str]
1314
"""ID of the agent which sent the provided message."""
1415

15-
content_ids: Required[List[str]]
16+
content_ids: Required[SequenceNotStr[str]]
1617
"""List of content ids for which to get the metadata."""

src/contextual/types/datastores/base_metadata_filter_param.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Union
5+
from typing import Union
66
from typing_extensions import Literal, Required, TypedDict
77

8+
from ..._types import SequenceNotStr
9+
810
__all__ = ["BaseMetadataFilterParam"]
911

1012

@@ -29,7 +31,7 @@ class BaseMetadataFilterParam(TypedDict, total=False):
2931
]
3032
"""Operator to be used for the filter."""
3133

32-
value: Union[str, float, bool, List[Union[str, float, bool]], None]
34+
value: Union[str, float, bool, SequenceNotStr[Union[str, float, bool]], None]
3335
"""The value to be searched for in the field.
3436
3537
In case of exists operator, it is not needed.

0 commit comments

Comments
 (0)