Skip to content

Commit ae478df

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

5 files changed

Lines changed: 19 additions & 14 deletions

File tree

‎src/maisa/_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/maisa/resources/kpu.py‎

Lines changed: 4 additions & 4 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, Mapping, Optional, cast
5+
from typing import Mapping, Optional, cast
66
from typing_extensions import Literal
77

88
import httpx
99

1010
from ..types import kpu_run_params
11-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
11+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes, SequenceNotStr
1212
from .._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
1313
from .._compat import cached_property
1414
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -49,7 +49,7 @@ def run(
4949
query: str,
5050
explain_steps: bool | NotGiven = NOT_GIVEN,
5151
retries: int | NotGiven = NOT_GIVEN,
52-
file: List[FileTypes] | NotGiven = NOT_GIVEN,
52+
file: SequenceNotStr[FileTypes] | NotGiven = NOT_GIVEN,
5353
reasoner_model: Optional[
5454
Literal[
5555
"gpt-4-turbo",
@@ -156,7 +156,7 @@ async def run(
156156
query: str,
157157
explain_steps: bool | NotGiven = NOT_GIVEN,
158158
retries: int | NotGiven = NOT_GIVEN,
159-
file: List[FileTypes] | NotGiven = NOT_GIVEN,
159+
file: SequenceNotStr[FileTypes] | NotGiven = NOT_GIVEN,
160160
reasoner_model: Optional[
161161
Literal[
162162
"gpt-4-turbo",

‎src/maisa/resources/models/embeddings.py‎

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

33
from __future__ import annotations
44

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

9-
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven
7+
from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
108
from ..._utils import maybe_transform, async_maybe_transform
119
from ..._compat import cached_property
1210
from ..._resource import SyncAPIResource, AsyncAPIResource
@@ -46,7 +44,7 @@ def with_streaming_response(self) -> EmbeddingsResourceWithStreamingResponse:
4644
def create(
4745
self,
4846
*,
49-
texts: List[str],
47+
texts: SequenceNotStr[str],
5048
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5149
# The extra values given here take precedence over values defined on the client or passed to this method.
5250
extra_headers: Headers | None = None,
@@ -101,7 +99,7 @@ def with_streaming_response(self) -> AsyncEmbeddingsResourceWithStreamingRespons
10199
async def create(
102100
self,
103101
*,
104-
texts: List[str],
102+
texts: SequenceNotStr[str],
105103
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
106104
# The extra values given here take precedence over values defined on the client or passed to this method.
107105
extra_headers: Headers | None = None,

‎src/maisa/types/kpu_run_params.py‎

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

33
from __future__ import annotations
44

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

8-
from .._types import FileTypes
8+
from .._types import FileTypes, SequenceNotStr
99

1010
__all__ = ["KpuRunParams"]
1111

@@ -28,7 +28,7 @@ class KpuRunParams(TypedDict, total=False):
2828
intent. This feature is experimental.
2929
"""
3030

31-
file: List[FileTypes]
31+
file: SequenceNotStr[FileTypes]
3232
"""Files to be used in the KPU execution. Files can be of any type."""
3333

3434
reasoner_model: Optional[

‎src/maisa/types/models/embedding_create_params.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
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__ = ["EmbeddingCreateParams"]
910

1011

1112
class EmbeddingCreateParams(TypedDict, total=False):
12-
texts: Required[List[str]]
13+
texts: Required[SequenceNotStr[str]]
1314
"""A list of texts from which we will generate the embeddings."""

0 commit comments

Comments
 (0)