Skip to content

Commit 07bdde8

Browse files
feat(types): replace List[str] with SequenceNotStr in params
1 parent ead0105 commit 07bdde8

File tree

10 files changed

+64
-50
lines changed

10 files changed

+64
-50
lines changed

src/codex/_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/codex/resources/projects/projects.py

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

33
from __future__ import annotations
44

5-
from typing import Dict, List, Iterable, Optional
5+
from typing import Dict, Iterable, Optional
66
from typing_extensions import Literal
77

88
import httpx
@@ -23,7 +23,7 @@
2323
project_invite_sme_params,
2424
project_retrieve_analytics_params,
2525
)
26-
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven
26+
from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven, SequenceNotStr
2727
from ..._utils import maybe_transform, strip_not_given, async_maybe_transform
2828
from ..._compat import cached_property
2929
from .query_logs import (
@@ -450,7 +450,7 @@ def validate(
450450
query: str,
451451
response: project_validate_params.Response,
452452
use_llm_matching: Optional[bool] | NotGiven = NOT_GIVEN,
453-
constrain_outputs: Optional[List[str]] | NotGiven = NOT_GIVEN,
453+
constrain_outputs: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
454454
custom_eval_thresholds: Optional[Dict[str, float]] | NotGiven = NOT_GIVEN,
455455
custom_metadata: Optional[object] | NotGiven = NOT_GIVEN,
456456
eval_scores: Optional[Dict[str, float]] | NotGiven = NOT_GIVEN,
@@ -1028,7 +1028,7 @@ async def validate(
10281028
query: str,
10291029
response: project_validate_params.Response,
10301030
use_llm_matching: Optional[bool] | NotGiven = NOT_GIVEN,
1031-
constrain_outputs: Optional[List[str]] | NotGiven = NOT_GIVEN,
1031+
constrain_outputs: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
10321032
custom_eval_thresholds: Optional[Dict[str, float]] | NotGiven = NOT_GIVEN,
10331033
custom_metadata: Optional[object] | NotGiven = NOT_GIVEN,
10341034
eval_scores: Optional[Dict[str, float]] | NotGiven = NOT_GIVEN,

src/codex/resources/projects/query_logs.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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
@@ -104,13 +104,13 @@ def list(
104104
created_at_end: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
105105
created_at_start: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
106106
custom_metadata: Optional[str] | NotGiven = NOT_GIVEN,
107-
failed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
107+
failed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
108108
guardrailed: Optional[bool] | NotGiven = NOT_GIVEN,
109109
has_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
110110
limit: int | NotGiven = NOT_GIVEN,
111111
offset: int | NotGiven = NOT_GIVEN,
112112
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
113-
passed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
113+
passed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
114114
primary_eval_issue: Optional[
115115
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
116116
]
@@ -127,7 +127,7 @@ def list(
127127
]
128128
]
129129
| NotGiven = NOT_GIVEN,
130-
tool_call_names: Optional[List[str]] | NotGiven = NOT_GIVEN,
130+
tool_call_names: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
131131
was_cache_hit: Optional[bool] | NotGiven = NOT_GIVEN,
132132
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
133133
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -248,19 +248,19 @@ def list_by_group(
248248
created_at_end: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
249249
created_at_start: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
250250
custom_metadata: Optional[str] | NotGiven = NOT_GIVEN,
251-
failed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
251+
failed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
252252
guardrailed: Optional[bool] | NotGiven = NOT_GIVEN,
253253
has_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
254254
limit: int | NotGiven = NOT_GIVEN,
255255
needs_review: Optional[bool] | NotGiven = NOT_GIVEN,
256256
offset: int | NotGiven = NOT_GIVEN,
257257
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
258-
passed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
258+
passed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
259259
primary_eval_issue: Optional[
260260
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
261261
]
262262
| NotGiven = NOT_GIVEN,
263-
remediation_ids: List[str] | NotGiven = NOT_GIVEN,
263+
remediation_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
264264
sort: Optional[
265265
Literal[
266266
"created_at",
@@ -273,7 +273,7 @@ def list_by_group(
273273
]
274274
]
275275
| NotGiven = NOT_GIVEN,
276-
tool_call_names: Optional[List[str]] | NotGiven = NOT_GIVEN,
276+
tool_call_names: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
277277
was_cache_hit: Optional[bool] | NotGiven = NOT_GIVEN,
278278
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
279279
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -359,21 +359,21 @@ def list_groups(
359359
created_at_end: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
360360
created_at_start: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
361361
custom_metadata: Optional[str] | NotGiven = NOT_GIVEN,
362-
failed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
362+
failed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
363363
guardrailed: Optional[bool] | NotGiven = NOT_GIVEN,
364364
has_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
365365
limit: int | NotGiven = NOT_GIVEN,
366366
needs_review: Optional[bool] | NotGiven = NOT_GIVEN,
367367
offset: int | NotGiven = NOT_GIVEN,
368368
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
369-
passed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
369+
passed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
370370
primary_eval_issue: Optional[
371371
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
372372
]
373373
| NotGiven = NOT_GIVEN,
374374
sort: Optional[Literal["created_at", "primary_eval_issue_score", "total_count", "custom_rank", "impact_score"]]
375375
| NotGiven = NOT_GIVEN,
376-
tool_call_names: Optional[List[str]] | NotGiven = NOT_GIVEN,
376+
tool_call_names: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
377377
was_cache_hit: Optional[bool] | NotGiven = NOT_GIVEN,
378378
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
379379
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -550,13 +550,13 @@ def list(
550550
created_at_end: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
551551
created_at_start: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
552552
custom_metadata: Optional[str] | NotGiven = NOT_GIVEN,
553-
failed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
553+
failed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
554554
guardrailed: Optional[bool] | NotGiven = NOT_GIVEN,
555555
has_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
556556
limit: int | NotGiven = NOT_GIVEN,
557557
offset: int | NotGiven = NOT_GIVEN,
558558
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
559-
passed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
559+
passed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
560560
primary_eval_issue: Optional[
561561
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
562562
]
@@ -573,7 +573,7 @@ def list(
573573
]
574574
]
575575
| NotGiven = NOT_GIVEN,
576-
tool_call_names: Optional[List[str]] | NotGiven = NOT_GIVEN,
576+
tool_call_names: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
577577
was_cache_hit: Optional[bool] | NotGiven = NOT_GIVEN,
578578
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
579579
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -696,19 +696,19 @@ async def list_by_group(
696696
created_at_end: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
697697
created_at_start: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
698698
custom_metadata: Optional[str] | NotGiven = NOT_GIVEN,
699-
failed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
699+
failed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
700700
guardrailed: Optional[bool] | NotGiven = NOT_GIVEN,
701701
has_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
702702
limit: int | NotGiven = NOT_GIVEN,
703703
needs_review: Optional[bool] | NotGiven = NOT_GIVEN,
704704
offset: int | NotGiven = NOT_GIVEN,
705705
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
706-
passed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
706+
passed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
707707
primary_eval_issue: Optional[
708708
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
709709
]
710710
| NotGiven = NOT_GIVEN,
711-
remediation_ids: List[str] | NotGiven = NOT_GIVEN,
711+
remediation_ids: SequenceNotStr[str] | NotGiven = NOT_GIVEN,
712712
sort: Optional[
713713
Literal[
714714
"created_at",
@@ -721,7 +721,7 @@ async def list_by_group(
721721
]
722722
]
723723
| NotGiven = NOT_GIVEN,
724-
tool_call_names: Optional[List[str]] | NotGiven = NOT_GIVEN,
724+
tool_call_names: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
725725
was_cache_hit: Optional[bool] | NotGiven = NOT_GIVEN,
726726
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
727727
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -807,21 +807,21 @@ def list_groups(
807807
created_at_end: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
808808
created_at_start: Union[str, datetime, None] | NotGiven = NOT_GIVEN,
809809
custom_metadata: Optional[str] | NotGiven = NOT_GIVEN,
810-
failed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
810+
failed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
811811
guardrailed: Optional[bool] | NotGiven = NOT_GIVEN,
812812
has_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
813813
limit: int | NotGiven = NOT_GIVEN,
814814
needs_review: Optional[bool] | NotGiven = NOT_GIVEN,
815815
offset: int | NotGiven = NOT_GIVEN,
816816
order: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
817-
passed_evals: Optional[List[str]] | NotGiven = NOT_GIVEN,
817+
passed_evals: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
818818
primary_eval_issue: Optional[
819819
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
820820
]
821821
| NotGiven = NOT_GIVEN,
822822
sort: Optional[Literal["created_at", "primary_eval_issue_score", "total_count", "custom_rank", "impact_score"]]
823823
| NotGiven = NOT_GIVEN,
824-
tool_call_names: Optional[List[str]] | NotGiven = NOT_GIVEN,
824+
tool_call_names: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
825825
was_cache_hit: Optional[bool] | NotGiven = NOT_GIVEN,
826826
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
827827
# The extra values given here take precedence over values defined on the client or passed to this method.

src/codex/resources/tlm.py

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

88
import httpx
99

1010
from ..types import tlm_score_params, tlm_prompt_params
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
@@ -49,7 +49,7 @@ def prompt(
4949
self,
5050
*,
5151
prompt: str,
52-
constrain_outputs: Optional[List[str]] | NotGiven = NOT_GIVEN,
52+
constrain_outputs: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
5353
options: Optional[tlm_prompt_params.Options] | NotGiven = NOT_GIVEN,
5454
quality_preset: Literal["best", "high", "medium", "low", "base"] | NotGiven = NOT_GIVEN,
5555
task: Optional[str] | NotGiven = NOT_GIVEN,
@@ -187,7 +187,7 @@ def score(
187187
*,
188188
prompt: str,
189189
response: str,
190-
constrain_outputs: Optional[List[str]] | NotGiven = NOT_GIVEN,
190+
constrain_outputs: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
191191
options: Optional[tlm_score_params.Options] | NotGiven = NOT_GIVEN,
192192
quality_preset: Literal["best", "high", "medium", "low", "base"] | NotGiven = NOT_GIVEN,
193193
task: Optional[str] | NotGiven = NOT_GIVEN,
@@ -351,7 +351,7 @@ async def prompt(
351351
self,
352352
*,
353353
prompt: str,
354-
constrain_outputs: Optional[List[str]] | NotGiven = NOT_GIVEN,
354+
constrain_outputs: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
355355
options: Optional[tlm_prompt_params.Options] | NotGiven = NOT_GIVEN,
356356
quality_preset: Literal["best", "high", "medium", "low", "base"] | NotGiven = NOT_GIVEN,
357357
task: Optional[str] | NotGiven = NOT_GIVEN,
@@ -489,7 +489,7 @@ async def score(
489489
*,
490490
prompt: str,
491491
response: str,
492-
constrain_outputs: Optional[List[str]] | NotGiven = NOT_GIVEN,
492+
constrain_outputs: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
493493
options: Optional[tlm_score_params.Options] | NotGiven = NOT_GIVEN,
494494
quality_preset: Literal["best", "high", "medium", "low", "base"] | NotGiven = NOT_GIVEN,
495495
task: Optional[str] | NotGiven = NOT_GIVEN,

src/codex/types/project_validate_params.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from __future__ import annotations
44

55
import builtins
6-
from typing import Dict, List, Union, Iterable, Optional
6+
from typing import Dict, Union, Iterable, Optional
77
from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict
88

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

1112
__all__ = [
@@ -68,7 +69,7 @@ class ProjectValidateParams(TypedDict, total=False):
6869

6970
use_llm_matching: Optional[bool]
7071

71-
constrain_outputs: Optional[List[str]]
72+
constrain_outputs: Optional[SequenceNotStr[str]]
7273

7374
custom_eval_thresholds: Optional[Dict[str, float]]
7475
"""Optional custom thresholds for specific evals.
@@ -656,7 +657,7 @@ class Options(TypedDict, total=False):
656657

657658
disable_trustworthiness: bool
658659

659-
log: List[str]
660+
log: SequenceNotStr[str]
660661

661662
max_tokens: int
662663

src/codex/types/projects/query_log_list_by_group_params.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from datetime import datetime
77
from typing_extensions import Literal, Annotated, TypedDict
88

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

1112
__all__ = ["QueryLogListByGroupParams"]
@@ -21,7 +22,7 @@ class QueryLogListByGroupParams(TypedDict, total=False):
2122
custom_metadata: Optional[str]
2223
"""Filter by custom metadata as JSON string: {"key1": "value1", "key2": "value2"}"""
2324

24-
failed_evals: Optional[List[str]]
25+
failed_evals: Optional[SequenceNotStr[str]]
2526
"""Filter by evals that failed"""
2627

2728
guardrailed: Optional[bool]
@@ -39,15 +40,15 @@ class QueryLogListByGroupParams(TypedDict, total=False):
3940

4041
order: Literal["asc", "desc"]
4142

42-
passed_evals: Optional[List[str]]
43+
passed_evals: Optional[SequenceNotStr[str]]
4344
"""Filter by evals that passed"""
4445

4546
primary_eval_issue: Optional[
4647
List[Literal["hallucination", "search_failure", "unhelpful", "difficult_query", "ungrounded"]]
4748
]
4849
"""Filter logs that have ANY of these primary evaluation issues (OR operation)"""
4950

50-
remediation_ids: List[str]
51+
remediation_ids: SequenceNotStr[str]
5152
"""List of groups to list child logs for"""
5253

5354
sort: Optional[
@@ -62,7 +63,7 @@ class QueryLogListByGroupParams(TypedDict, total=False):
6263
]
6364
]
6465

65-
tool_call_names: Optional[List[str]]
66+
tool_call_names: Optional[SequenceNotStr[str]]
6667
"""Filter by names of tools called in the assistant response"""
6768

6869
was_cache_hit: Optional[bool]

0 commit comments

Comments
 (0)