22
33from __future__ import annotations
44
5+ from typing import Optional
6+
57import httpx
68
79from ...._types import NOT_GIVEN , Body , Query , Headers , NotGiven
8- from ...._utils import maybe_transform , async_maybe_transform
10+ from ...._utils import maybe_transform , strip_not_given , async_maybe_transform
911from ...._compat import cached_property
1012from ...._resource import SyncAPIResource , AsyncAPIResource
1113from ...._response import (
1517 async_to_streamed_response_wrapper ,
1618)
1719from ...._base_client import make_request_options
18- from ....types .async_ .chat import completion_list_params , completion_create_params
20+ from ....types .async_ .chat import completion_get_params , completion_create_params
1921from ....types .async_ .chat .completion_get_response import CompletionGetResponse
2022from ....types .async_ .chat .completion_list_response import CompletionListResponse
2123from ....types .async_ .chat .completion_create_response import CompletionCreateResponse
@@ -47,6 +49,7 @@ def create(
4749 self ,
4850 * ,
4951 request : completion_create_params .Request ,
52+ idempotency_key : Optional [str ] | NotGiven = NOT_GIVEN ,
5053 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5154 # The extra values given here take precedence over values defined on the client or passed to this method.
5255 extra_headers : Headers | None = None ,
@@ -55,7 +58,10 @@ def create(
5558 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
5659 ) -> CompletionCreateResponse :
5760 """
58- Creates an asynchronous chat completion job
61+ FastAPI wrapper around async chat completions
62+
63+ This endpoint creates an asynchronous chat completion job and returns a job ID
64+ that can be used to poll for results.
5965
6066 Args:
6167 extra_headers: Send extra headers
@@ -68,7 +74,13 @@ def create(
6874 """
6975 return self ._post (
7076 "/async/chat/completions" ,
71- body = maybe_transform ({"request" : request }, completion_create_params .CompletionCreateParams ),
77+ body = maybe_transform (
78+ {
79+ "request" : request ,
80+ "idempotency_key" : idempotency_key ,
81+ },
82+ completion_create_params .CompletionCreateParams ,
83+ ),
7284 options = make_request_options (
7385 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
7486 ),
@@ -78,53 +90,32 @@ def create(
7890 def list (
7991 self ,
8092 * ,
81- limit : int | NotGiven = NOT_GIVEN ,
82- next_token : str | NotGiven = NOT_GIVEN ,
8393 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
8494 # The extra values given here take precedence over values defined on the client or passed to this method.
8595 extra_headers : Headers | None = None ,
8696 extra_query : Query | None = None ,
8797 extra_body : Body | None = None ,
8898 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
8999 ) -> CompletionListResponse :
90- """
91- Lists all asynchronous chat completion requests for the authenticated user
92-
93- Args:
94- limit: Maximum number of requests to return
95-
96- next_token: Token for fetching the next page of results
97-
98- extra_headers: Send extra headers
99-
100- extra_query: Add additional query parameters to the request
101-
102- extra_body: Add additional JSON properties to the request
103-
104- timeout: Override the client-level default timeout for this request, in seconds
105- """
100+ """list all async chat completion requests for a given user."""
106101 return self ._get (
107102 "/async/chat/completions" ,
108103 options = make_request_options (
109- extra_headers = extra_headers ,
110- extra_query = extra_query ,
111- extra_body = extra_body ,
112- timeout = timeout ,
113- query = maybe_transform (
114- {
115- "limit" : limit ,
116- "next_token" : next_token ,
117- },
118- completion_list_params .CompletionListParams ,
119- ),
104+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
120105 ),
121106 cast_to = CompletionListResponse ,
122107 )
123108
124109 def get (
125110 self ,
126- request_id : str ,
111+ api_request : str ,
127112 * ,
113+ local_mode : bool | NotGiven = NOT_GIVEN ,
114+ x_client_env : str | NotGiven = NOT_GIVEN ,
115+ x_client_name : str | NotGiven = NOT_GIVEN ,
116+ x_request_time : str | NotGiven = NOT_GIVEN ,
117+ x_usage_tier : str | NotGiven = NOT_GIVEN ,
118+ x_user_id : str | NotGiven = NOT_GIVEN ,
128119 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
129120 # The extra values given here take precedence over values defined on the client or passed to this method.
130121 extra_headers : Headers | None = None ,
@@ -133,7 +124,7 @@ def get(
133124 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
134125 ) -> CompletionGetResponse :
135126 """
136- Retrieves the status and result of a specific asynchronous chat completion job
127+ get the response for a given async chat completion request.
137128
138129 Args:
139130 extra_headers: Send extra headers
@@ -144,12 +135,28 @@ def get(
144135
145136 timeout: Override the client-level default timeout for this request, in seconds
146137 """
147- if not request_id :
148- raise ValueError (f"Expected a non-empty value for `request_id` but received { request_id !r} " )
138+ if not api_request :
139+ raise ValueError (f"Expected a non-empty value for `api_request` but received { api_request !r} " )
140+ extra_headers = {
141+ ** strip_not_given (
142+ {
143+ "x-client-env" : x_client_env ,
144+ "x-client-name" : x_client_name ,
145+ "x-request-time" : x_request_time ,
146+ "x-usage-tier" : x_usage_tier ,
147+ "x-user-id" : x_user_id ,
148+ }
149+ ),
150+ ** (extra_headers or {}),
151+ }
149152 return self ._get (
150- f"/async/chat/completions/{ request_id } " ,
153+ f"/async/chat/completions/{ api_request } " ,
151154 options = make_request_options (
152- extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
155+ extra_headers = extra_headers ,
156+ extra_query = extra_query ,
157+ extra_body = extra_body ,
158+ timeout = timeout ,
159+ query = maybe_transform ({"local_mode" : local_mode }, completion_get_params .CompletionGetParams ),
153160 ),
154161 cast_to = CompletionGetResponse ,
155162 )
@@ -179,6 +186,7 @@ async def create(
179186 self ,
180187 * ,
181188 request : completion_create_params .Request ,
189+ idempotency_key : Optional [str ] | NotGiven = NOT_GIVEN ,
182190 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
183191 # The extra values given here take precedence over values defined on the client or passed to this method.
184192 extra_headers : Headers | None = None ,
@@ -187,7 +195,10 @@ async def create(
187195 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
188196 ) -> CompletionCreateResponse :
189197 """
190- Creates an asynchronous chat completion job
198+ FastAPI wrapper around async chat completions
199+
200+ This endpoint creates an asynchronous chat completion job and returns a job ID
201+ that can be used to poll for results.
191202
192203 Args:
193204 extra_headers: Send extra headers
@@ -200,7 +211,13 @@ async def create(
200211 """
201212 return await self ._post (
202213 "/async/chat/completions" ,
203- body = await async_maybe_transform ({"request" : request }, completion_create_params .CompletionCreateParams ),
214+ body = await async_maybe_transform (
215+ {
216+ "request" : request ,
217+ "idempotency_key" : idempotency_key ,
218+ },
219+ completion_create_params .CompletionCreateParams ,
220+ ),
204221 options = make_request_options (
205222 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
206223 ),
@@ -210,53 +227,32 @@ async def create(
210227 async def list (
211228 self ,
212229 * ,
213- limit : int | NotGiven = NOT_GIVEN ,
214- next_token : str | NotGiven = NOT_GIVEN ,
215230 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
216231 # The extra values given here take precedence over values defined on the client or passed to this method.
217232 extra_headers : Headers | None = None ,
218233 extra_query : Query | None = None ,
219234 extra_body : Body | None = None ,
220235 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
221236 ) -> CompletionListResponse :
222- """
223- Lists all asynchronous chat completion requests for the authenticated user
224-
225- Args:
226- limit: Maximum number of requests to return
227-
228- next_token: Token for fetching the next page of results
229-
230- extra_headers: Send extra headers
231-
232- extra_query: Add additional query parameters to the request
233-
234- extra_body: Add additional JSON properties to the request
235-
236- timeout: Override the client-level default timeout for this request, in seconds
237- """
237+ """list all async chat completion requests for a given user."""
238238 return await self ._get (
239239 "/async/chat/completions" ,
240240 options = make_request_options (
241- extra_headers = extra_headers ,
242- extra_query = extra_query ,
243- extra_body = extra_body ,
244- timeout = timeout ,
245- query = await async_maybe_transform (
246- {
247- "limit" : limit ,
248- "next_token" : next_token ,
249- },
250- completion_list_params .CompletionListParams ,
251- ),
241+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
252242 ),
253243 cast_to = CompletionListResponse ,
254244 )
255245
256246 async def get (
257247 self ,
258- request_id : str ,
248+ api_request : str ,
259249 * ,
250+ local_mode : bool | NotGiven = NOT_GIVEN ,
251+ x_client_env : str | NotGiven = NOT_GIVEN ,
252+ x_client_name : str | NotGiven = NOT_GIVEN ,
253+ x_request_time : str | NotGiven = NOT_GIVEN ,
254+ x_usage_tier : str | NotGiven = NOT_GIVEN ,
255+ x_user_id : str | NotGiven = NOT_GIVEN ,
260256 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
261257 # The extra values given here take precedence over values defined on the client or passed to this method.
262258 extra_headers : Headers | None = None ,
@@ -265,7 +261,7 @@ async def get(
265261 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
266262 ) -> CompletionGetResponse :
267263 """
268- Retrieves the status and result of a specific asynchronous chat completion job
264+ get the response for a given async chat completion request.
269265
270266 Args:
271267 extra_headers: Send extra headers
@@ -276,12 +272,30 @@ async def get(
276272
277273 timeout: Override the client-level default timeout for this request, in seconds
278274 """
279- if not request_id :
280- raise ValueError (f"Expected a non-empty value for `request_id` but received { request_id !r} " )
275+ if not api_request :
276+ raise ValueError (f"Expected a non-empty value for `api_request` but received { api_request !r} " )
277+ extra_headers = {
278+ ** strip_not_given (
279+ {
280+ "x-client-env" : x_client_env ,
281+ "x-client-name" : x_client_name ,
282+ "x-request-time" : x_request_time ,
283+ "x-usage-tier" : x_usage_tier ,
284+ "x-user-id" : x_user_id ,
285+ }
286+ ),
287+ ** (extra_headers or {}),
288+ }
281289 return await self ._get (
282- f"/async/chat/completions/{ request_id } " ,
290+ f"/async/chat/completions/{ api_request } " ,
283291 options = make_request_options (
284- extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
292+ extra_headers = extra_headers ,
293+ extra_query = extra_query ,
294+ extra_body = extra_body ,
295+ timeout = timeout ,
296+ query = await async_maybe_transform (
297+ {"local_mode" : local_mode }, completion_get_params .CompletionGetParams
298+ ),
285299 ),
286300 cast_to = CompletionGetResponse ,
287301 )
0 commit comments