Skip to content

Commit 1353df1

Browse files
feat: Ai-assistants: support pattern in canary deploy
1 parent 19eb8f1 commit 1353df1

10 files changed

Lines changed: 300 additions & 159 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 1035
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/telnyx/telnyx-055a1979f5ac02203769967c4a310711c597b14ac7ffcb8be8e0e869ebd9ca55.yml
3-
openapi_spec_hash: 60bfd254a4c29087c75e7c58022db884
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/telnyx/telnyx-570b7881c5b3801b01f22d8af31055ee48aad4b73f535dd62e6d68979e6d9fdb.yml
3+
openapi_spec_hash: 19ff50775de609b633c05d3b834cd765
44
config_hash: cfdc548410473bb526a8fc846ec89e39

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ Methods:
698698
Types:
699699

700700
```python
701-
from telnyx.types.ai.assistants import CanaryDeploy, CanaryDeployResponse, VersionConfig
701+
from telnyx.types.ai.assistants import CanaryDeploy, CanaryDeployResponse
702702
```
703703

704704
Methods:

src/telnyx/resources/ai/assistants/canary_deploys.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import httpx
88

9-
from ...._types import Body, Query, Headers, NoneType, NotGiven, not_given
9+
from ...._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
1010
from ...._utils import path_template, maybe_transform, async_maybe_transform
1111
from ...._compat import cached_property
1212
from ...._resource import SyncAPIResource, AsyncAPIResource
@@ -18,7 +18,6 @@
1818
)
1919
from ...._base_client import make_request_options
2020
from ....types.ai.assistants import canary_deploy_create_params, canary_deploy_update_params
21-
from ....types.ai.assistants.version_config_param import VersionConfigParam
2221
from ....types.ai.assistants.canary_deploy_response import CanaryDeployResponse
2322

2423
__all__ = ["CanaryDeploysResource", "AsyncCanaryDeploysResource"]
@@ -50,7 +49,7 @@ def create(
5049
self,
5150
assistant_id: str,
5251
*,
53-
versions: Iterable[VersionConfigParam],
52+
rules: Iterable[canary_deploy_create_params.Rule] | Omit = omit,
5453
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5554
# The extra values given here take precedence over values defined on the client or passed to this method.
5655
extra_headers: Headers | None = None,
@@ -65,8 +64,6 @@ def create(
6564
traffic percentages for A/B testing or gradual rollouts of assistant versions.
6665
6766
Args:
68-
versions: List of version configurations
69-
7067
extra_headers: Send extra headers
7168
7269
extra_query: Add additional query parameters to the request
@@ -79,7 +76,7 @@ def create(
7976
raise ValueError(f"Expected a non-empty value for `assistant_id` but received {assistant_id!r}")
8077
return self._post(
8178
path_template("/ai/assistants/{assistant_id}/canary-deploys", assistant_id=assistant_id),
82-
body=maybe_transform({"versions": versions}, canary_deploy_create_params.CanaryDeployCreateParams),
79+
body=maybe_transform({"rules": rules}, canary_deploy_create_params.CanaryDeployCreateParams),
8380
options=make_request_options(
8481
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
8582
),
@@ -126,7 +123,7 @@ def update(
126123
self,
127124
assistant_id: str,
128125
*,
129-
versions: Iterable[VersionConfigParam],
126+
rules: Iterable[canary_deploy_update_params.Rule] | Omit = omit,
130127
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
131128
# The extra values given here take precedence over values defined on the client or passed to this method.
132129
extra_headers: Headers | None = None,
@@ -142,8 +139,6 @@ def update(
142139
request.
143140
144141
Args:
145-
versions: List of version configurations
146-
147142
extra_headers: Send extra headers
148143
149144
extra_query: Add additional query parameters to the request
@@ -156,7 +151,7 @@ def update(
156151
raise ValueError(f"Expected a non-empty value for `assistant_id` but received {assistant_id!r}")
157152
return self._put(
158153
path_template("/ai/assistants/{assistant_id}/canary-deploys", assistant_id=assistant_id),
159-
body=maybe_transform({"versions": versions}, canary_deploy_update_params.CanaryDeployUpdateParams),
154+
body=maybe_transform({"rules": rules}, canary_deploy_update_params.CanaryDeployUpdateParams),
160155
options=make_request_options(
161156
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
162157
),
@@ -226,7 +221,7 @@ async def create(
226221
self,
227222
assistant_id: str,
228223
*,
229-
versions: Iterable[VersionConfigParam],
224+
rules: Iterable[canary_deploy_create_params.Rule] | Omit = omit,
230225
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
231226
# The extra values given here take precedence over values defined on the client or passed to this method.
232227
extra_headers: Headers | None = None,
@@ -241,8 +236,6 @@ async def create(
241236
traffic percentages for A/B testing or gradual rollouts of assistant versions.
242237
243238
Args:
244-
versions: List of version configurations
245-
246239
extra_headers: Send extra headers
247240
248241
extra_query: Add additional query parameters to the request
@@ -255,9 +248,7 @@ async def create(
255248
raise ValueError(f"Expected a non-empty value for `assistant_id` but received {assistant_id!r}")
256249
return await self._post(
257250
path_template("/ai/assistants/{assistant_id}/canary-deploys", assistant_id=assistant_id),
258-
body=await async_maybe_transform(
259-
{"versions": versions}, canary_deploy_create_params.CanaryDeployCreateParams
260-
),
251+
body=await async_maybe_transform({"rules": rules}, canary_deploy_create_params.CanaryDeployCreateParams),
261252
options=make_request_options(
262253
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
263254
),
@@ -304,7 +295,7 @@ async def update(
304295
self,
305296
assistant_id: str,
306297
*,
307-
versions: Iterable[VersionConfigParam],
298+
rules: Iterable[canary_deploy_update_params.Rule] | Omit = omit,
308299
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
309300
# The extra values given here take precedence over values defined on the client or passed to this method.
310301
extra_headers: Headers | None = None,
@@ -320,8 +311,6 @@ async def update(
320311
request.
321312
322313
Args:
323-
versions: List of version configurations
324-
325314
extra_headers: Send extra headers
326315
327316
extra_query: Add additional query parameters to the request
@@ -334,9 +323,7 @@ async def update(
334323
raise ValueError(f"Expected a non-empty value for `assistant_id` but received {assistant_id!r}")
335324
return await self._put(
336325
path_template("/ai/assistants/{assistant_id}/canary-deploys", assistant_id=assistant_id),
337-
body=await async_maybe_transform(
338-
{"versions": versions}, canary_deploy_update_params.CanaryDeployUpdateParams
339-
),
326+
body=await async_maybe_transform({"rules": rules}, canary_deploy_update_params.CanaryDeployUpdateParams),
340327
options=make_request_options(
341328
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
342329
),

src/telnyx/types/ai/assistants/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .event_status import EventStatus as EventStatus
66
from .assistant_test import AssistantTest as AssistantTest
77
from .tag_add_params import TagAddParams as TagAddParams
8-
from .version_config import VersionConfig as VersionConfig
98
from .tag_add_response import TagAddResponse as TagAddResponse
109
from .test_list_params import TestListParams as TestListParams
1110
from .tool_test_params import ToolTestParams as ToolTestParams
@@ -14,7 +13,6 @@
1413
from .test_update_params import TestUpdateParams as TestUpdateParams
1514
from .tool_test_response import ToolTestResponse as ToolTestResponse
1615
from .tag_remove_response import TagRemoveResponse as TagRemoveResponse
17-
from .version_config_param import VersionConfigParam as VersionConfigParam
1816
from .version_update_params import VersionUpdateParams as VersionUpdateParams
1917
from .canary_deploy_response import CanaryDeployResponse as CanaryDeployResponse
2018
from .version_retrieve_params import VersionRetrieveParams as VersionRetrieveParams

src/telnyx/types/ai/assistants/canary_deploy_create_params.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,69 @@
33
from __future__ import annotations
44

55
from typing import Iterable
6-
from typing_extensions import Required, TypedDict
6+
from typing_extensions import Literal, Required, TypedDict
77

8-
from .version_config_param import VersionConfigParam
8+
from ...._types import SequenceNotStr
99

10-
__all__ = ["CanaryDeployCreateParams"]
10+
__all__ = ["CanaryDeployCreateParams", "Rule", "RuleServe", "RuleServeRollout", "RuleMatch"]
1111

1212

1313
class CanaryDeployCreateParams(TypedDict, total=False):
14-
versions: Required[Iterable[VersionConfigParam]]
15-
"""List of version configurations"""
14+
rules: Iterable[Rule]
15+
16+
17+
class RuleServeRollout(TypedDict, total=False):
18+
"""One slot in a percentage rollout."""
19+
20+
version_id: Required[str]
21+
22+
weight: Required[float]
23+
24+
25+
class RuleServe(TypedDict, total=False):
26+
"""What a rule serves when matched.
27+
28+
Exactly one of:
29+
- ``version_id`` — serve a specific version
30+
- ``rollout`` — weighted random across versions; weights must sum to
31+
less than 100, with the leftover routing to the main version
32+
"""
33+
34+
rollout: Iterable[RuleServeRollout]
35+
36+
version_id: str
37+
38+
39+
class RuleMatch(TypedDict, total=False):
40+
"""A single attribute/operator/values check.
41+
42+
A clause matches when the routing context's value for ``attribute``
43+
satisfies ``operator`` against any of ``values``.
44+
"""
45+
46+
attribute: Required[str]
47+
"""Attribute name from the routing context"""
48+
49+
operator: Required[Literal["in", "not_in", "starts_with"]]
50+
"""Match operator"""
51+
52+
values: Required[SequenceNotStr[str]]
53+
54+
55+
class Rule(TypedDict, total=False):
56+
"""A targeting rule: ``match`` clauses (AND) gate ``serve``.
57+
58+
An empty ``match`` is a catch-all (always fires).
59+
"""
60+
61+
serve: Required[RuleServe]
62+
"""What a rule serves when matched.
63+
64+
Exactly one of:
65+
66+
- `version_id` — serve a specific version
67+
- `rollout` — weighted random across versions; weights must sum to less than
68+
100, with the leftover routing to the main version
69+
"""
70+
71+
match: Iterable[RuleMatch]
Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,81 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import List
3+
from typing import List, Optional
44
from datetime import datetime
5+
from typing_extensions import Literal
56

67
from ...._models import BaseModel
7-
from .version_config import VersionConfig
88

9-
__all__ = ["CanaryDeployResponse"]
9+
__all__ = ["CanaryDeployResponse", "Rule", "RuleServe", "RuleServeRollout", "RuleMatch"]
10+
11+
12+
class RuleServeRollout(BaseModel):
13+
"""One slot in a percentage rollout."""
14+
15+
version_id: str
16+
17+
weight: float
18+
19+
20+
class RuleServe(BaseModel):
21+
"""What a rule serves when matched.
22+
23+
Exactly one of:
24+
- ``version_id`` — serve a specific version
25+
- ``rollout`` — weighted random across versions; weights must sum to
26+
less than 100, with the leftover routing to the main version
27+
"""
28+
29+
rollout: Optional[List[RuleServeRollout]] = None
30+
31+
version_id: Optional[str] = None
32+
33+
34+
class RuleMatch(BaseModel):
35+
"""A single attribute/operator/values check.
36+
37+
A clause matches when the routing context's value for ``attribute``
38+
satisfies ``operator`` against any of ``values``.
39+
"""
40+
41+
attribute: str
42+
"""Attribute name from the routing context"""
43+
44+
operator: Literal["in", "not_in", "starts_with"]
45+
"""Match operator"""
46+
47+
values: List[str]
48+
49+
50+
class Rule(BaseModel):
51+
"""A targeting rule: ``match`` clauses (AND) gate ``serve``.
52+
53+
An empty ``match`` is a catch-all (always fires).
54+
"""
55+
56+
serve: RuleServe
57+
"""What a rule serves when matched.
58+
59+
Exactly one of:
60+
61+
- `version_id` — serve a specific version
62+
- `rollout` — weighted random across versions; weights must sum to less than
63+
100, with the leftover routing to the main version
64+
"""
65+
66+
match: Optional[List[RuleMatch]] = None
1067

1168

1269
class CanaryDeployResponse(BaseModel):
13-
"""Response model for canary deploy operations."""
70+
"""Response shape.
71+
72+
Always carries ``rules`` (canonical).
73+
"""
1474

1575
assistant_id: str
1676

1777
created_at: datetime
1878

19-
updated_at: datetime
79+
rules: List[Rule]
2080

21-
versions: List[VersionConfig]
81+
updated_at: datetime

src/telnyx/types/ai/assistants/canary_deploy_update_params.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,69 @@
33
from __future__ import annotations
44

55
from typing import Iterable
6-
from typing_extensions import Required, TypedDict
6+
from typing_extensions import Literal, Required, TypedDict
77

8-
from .version_config_param import VersionConfigParam
8+
from ...._types import SequenceNotStr
99

10-
__all__ = ["CanaryDeployUpdateParams"]
10+
__all__ = ["CanaryDeployUpdateParams", "Rule", "RuleServe", "RuleServeRollout", "RuleMatch"]
1111

1212

1313
class CanaryDeployUpdateParams(TypedDict, total=False):
14-
versions: Required[Iterable[VersionConfigParam]]
15-
"""List of version configurations"""
14+
rules: Iterable[Rule]
15+
16+
17+
class RuleServeRollout(TypedDict, total=False):
18+
"""One slot in a percentage rollout."""
19+
20+
version_id: Required[str]
21+
22+
weight: Required[float]
23+
24+
25+
class RuleServe(TypedDict, total=False):
26+
"""What a rule serves when matched.
27+
28+
Exactly one of:
29+
- ``version_id`` — serve a specific version
30+
- ``rollout`` — weighted random across versions; weights must sum to
31+
less than 100, with the leftover routing to the main version
32+
"""
33+
34+
rollout: Iterable[RuleServeRollout]
35+
36+
version_id: str
37+
38+
39+
class RuleMatch(TypedDict, total=False):
40+
"""A single attribute/operator/values check.
41+
42+
A clause matches when the routing context's value for ``attribute``
43+
satisfies ``operator`` against any of ``values``.
44+
"""
45+
46+
attribute: Required[str]
47+
"""Attribute name from the routing context"""
48+
49+
operator: Required[Literal["in", "not_in", "starts_with"]]
50+
"""Match operator"""
51+
52+
values: Required[SequenceNotStr[str]]
53+
54+
55+
class Rule(TypedDict, total=False):
56+
"""A targeting rule: ``match`` clauses (AND) gate ``serve``.
57+
58+
An empty ``match`` is a catch-all (always fires).
59+
"""
60+
61+
serve: Required[RuleServe]
62+
"""What a rule serves when matched.
63+
64+
Exactly one of:
65+
66+
- `version_id` — serve a specific version
67+
- `rollout` — weighted random across versions; weights must sum to less than
68+
100, with the leftover routing to the main version
69+
"""
70+
71+
match: Iterable[RuleMatch]

0 commit comments

Comments
 (0)