Skip to content

Commit 7f685a7

Browse files
rushitatcursoragent
andcommitted
Add Responses API resource and client.responses (with tests)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c37ecf4 commit 7f685a7

File tree

5 files changed

+412
-39
lines changed

5 files changed

+412
-39
lines changed

src/gradient/_client.py

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
retrieve,
4343
databases,
4444
inference,
45+
responses,
4546
gpu_droplets,
4647
knowledge_bases,
4748
)
@@ -58,6 +59,10 @@
5859
from .resources.models.models import ModelsResource, AsyncModelsResource
5960
from .resources.databases.databases import DatabasesResource, AsyncDatabasesResource
6061
from .resources.inference.inference import InferenceResource, AsyncInferenceResource
62+
from .resources.responses.responses import (
63+
ResponsesResource,
64+
AsyncResponsesResource,
65+
)
6166
from .resources.knowledge_bases.knowledge_bases import (
6267
KnowledgeBasesResource,
6368
AsyncKnowledgeBasesResource,
@@ -195,6 +200,12 @@ def chat(self) -> ChatResource:
195200

196201
return ChatResource(self)
197202

203+
@cached_property
204+
def responses(self) -> ResponsesResource:
205+
from .resources.responses import ResponsesResource
206+
207+
return ResponsesResource(self)
208+
198209
@cached_property
199210
def images(self) -> ImagesResource:
200211
from .resources.images import ImagesResource
@@ -353,14 +364,10 @@ def copy(
353364
Create a new client instance re-using the same options given to the current client with optional overriding.
354365
"""
355366
if default_headers is not None and set_default_headers is not None:
356-
raise ValueError(
357-
"The `default_headers` and `set_default_headers` arguments are mutually exclusive"
358-
)
367+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
359368

360369
if default_query is not None and set_default_query is not None:
361-
raise ValueError(
362-
"The `default_query` and `set_default_query` arguments are mutually exclusive"
363-
)
370+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
364371

365372
headers = self._custom_headers
366373
if default_headers is not None:
@@ -411,14 +418,10 @@ def _make_status_error(
411418
return _exceptions.BadRequestError(err_msg, response=response, body=body)
412419

413420
if response.status_code == 401:
414-
return _exceptions.AuthenticationError(
415-
err_msg, response=response, body=body
416-
)
421+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
417422

418423
if response.status_code == 403:
419-
return _exceptions.PermissionDeniedError(
420-
err_msg, response=response, body=body
421-
)
424+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
422425

423426
if response.status_code == 404:
424427
return _exceptions.NotFoundError(err_msg, response=response, body=body)
@@ -427,17 +430,13 @@ def _make_status_error(
427430
return _exceptions.ConflictError(err_msg, response=response, body=body)
428431

429432
if response.status_code == 422:
430-
return _exceptions.UnprocessableEntityError(
431-
err_msg, response=response, body=body
432-
)
433+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
433434

434435
if response.status_code == 429:
435436
return _exceptions.RateLimitError(err_msg, response=response, body=body)
436437

437438
if response.status_code >= 500:
438-
return _exceptions.InternalServerError(
439-
err_msg, response=response, body=body
440-
)
439+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
441440
return APIStatusError(err_msg, response=response, body=body)
442441

443442

@@ -561,6 +560,12 @@ def chat(self) -> AsyncChatResource:
561560

562561
return AsyncChatResource(self)
563562

563+
@cached_property
564+
def responses(self) -> AsyncResponsesResource:
565+
from .resources.responses import AsyncResponsesResource
566+
567+
return AsyncResponsesResource(self)
568+
564569
@cached_property
565570
def images(self) -> AsyncImagesResource:
566571
from .resources.images import AsyncImagesResource
@@ -719,14 +724,10 @@ def copy(
719724
Create a new client instance re-using the same options given to the current client with optional overriding.
720725
"""
721726
if default_headers is not None and set_default_headers is not None:
722-
raise ValueError(
723-
"The `default_headers` and `set_default_headers` arguments are mutually exclusive"
724-
)
727+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
725728

726729
if default_query is not None and set_default_query is not None:
727-
raise ValueError(
728-
"The `default_query` and `set_default_query` arguments are mutually exclusive"
729-
)
730+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
730731

731732
headers = self._custom_headers
732733
if default_headers is not None:
@@ -777,14 +778,10 @@ def _make_status_error(
777778
return _exceptions.BadRequestError(err_msg, response=response, body=body)
778779

779780
if response.status_code == 401:
780-
return _exceptions.AuthenticationError(
781-
err_msg, response=response, body=body
782-
)
781+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
783782

784783
if response.status_code == 403:
785-
return _exceptions.PermissionDeniedError(
786-
err_msg, response=response, body=body
787-
)
784+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
788785

789786
if response.status_code == 404:
790787
return _exceptions.NotFoundError(err_msg, response=response, body=body)
@@ -793,17 +790,13 @@ def _make_status_error(
793790
return _exceptions.ConflictError(err_msg, response=response, body=body)
794791

795792
if response.status_code == 422:
796-
return _exceptions.UnprocessableEntityError(
797-
err_msg, response=response, body=body
798-
)
793+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
799794

800795
if response.status_code == 429:
801796
return _exceptions.RateLimitError(err_msg, response=response, body=body)
802797

803798
if response.status_code >= 500:
804-
return _exceptions.InternalServerError(
805-
err_msg, response=response, body=body
806-
)
799+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
807800
return APIStatusError(err_msg, response=response, body=body)
808801

809802

@@ -825,6 +818,12 @@ def chat(self) -> chat.ChatResourceWithRawResponse:
825818

826819
return ChatResourceWithRawResponse(self._client.chat)
827820

821+
@cached_property
822+
def responses(self) -> responses.ResponsesResourceWithRawResponse:
823+
from .resources.responses import ResponsesResourceWithRawResponse
824+
825+
return ResponsesResourceWithRawResponse(self._client.responses)
826+
828827
@cached_property
829828
def images(self) -> images.ImagesResourceWithRawResponse:
830829
from .resources.images import ImagesResourceWithRawResponse
@@ -898,6 +897,12 @@ def chat(self) -> chat.AsyncChatResourceWithRawResponse:
898897

899898
return AsyncChatResourceWithRawResponse(self._client.chat)
900899

900+
@cached_property
901+
def responses(self) -> responses.AsyncResponsesResourceWithRawResponse:
902+
from .resources.responses import AsyncResponsesResourceWithRawResponse
903+
904+
return AsyncResponsesResourceWithRawResponse(self._client.responses)
905+
901906
@cached_property
902907
def images(self) -> images.AsyncImagesResourceWithRawResponse:
903908
from .resources.images import AsyncImagesResourceWithRawResponse
@@ -975,6 +980,12 @@ def chat(self) -> chat.ChatResourceWithStreamingResponse:
975980

976981
return ChatResourceWithStreamingResponse(self._client.chat)
977982

983+
@cached_property
984+
def responses(self) -> responses.ResponsesResourceWithStreamingResponse:
985+
from .resources.responses import ResponsesResourceWithStreamingResponse
986+
987+
return ResponsesResourceWithStreamingResponse(self._client.responses)
988+
978989
@cached_property
979990
def images(self) -> images.ImagesResourceWithStreamingResponse:
980991
from .resources.images import ImagesResourceWithStreamingResponse
@@ -1052,6 +1063,12 @@ def chat(self) -> chat.AsyncChatResourceWithStreamingResponse:
10521063

10531064
return AsyncChatResourceWithStreamingResponse(self._client.chat)
10541065

1066+
@cached_property
1067+
def responses(self) -> responses.AsyncResponsesResourceWithStreamingResponse:
1068+
from .resources.responses import AsyncResponsesResourceWithStreamingResponse
1069+
1070+
return AsyncResponsesResourceWithStreamingResponse(self._client.responses)
1071+
10551072
@cached_property
10561073
def images(self) -> images.AsyncImagesResourceWithStreamingResponse:
10571074
from .resources.images import AsyncImagesResourceWithStreamingResponse
@@ -1082,9 +1099,7 @@ def knowledge_bases(
10821099
AsyncKnowledgeBasesResourceWithStreamingResponse,
10831100
)
10841101

1085-
return AsyncKnowledgeBasesResourceWithStreamingResponse(
1086-
self._client.knowledge_bases
1087-
)
1102+
return AsyncKnowledgeBasesResourceWithStreamingResponse(self._client.knowledge_bases)
10881103

10891104
@cached_property
10901105
def models(self) -> models.AsyncModelsResourceWithStreamingResponse:

src/gradient/resources/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
InferenceResourceWithStreamingResponse,
7373
AsyncInferenceResourceWithStreamingResponse,
7474
)
75+
from .responses import (
76+
ResponsesResource,
77+
AsyncResponsesResource,
78+
ResponsesResourceWithRawResponse,
79+
AsyncResponsesResourceWithRawResponse,
80+
ResponsesResourceWithStreamingResponse,
81+
AsyncResponsesResourceWithStreamingResponse,
82+
)
7583
from .gpu_droplets import (
7684
GPUDropletsResource,
7785
AsyncGPUDropletsResource,
@@ -150,6 +158,12 @@
150158
"AsyncNfsResourceWithRawResponse",
151159
"NfsResourceWithStreamingResponse",
152160
"AsyncNfsResourceWithStreamingResponse",
161+
"ResponsesResource",
162+
"AsyncResponsesResource",
163+
"ResponsesResourceWithRawResponse",
164+
"AsyncResponsesResourceWithRawResponse",
165+
"ResponsesResourceWithStreamingResponse",
166+
"AsyncResponsesResourceWithStreamingResponse",
153167
"RetrieveResource",
154168
"AsyncRetrieveResource",
155169
"RetrieveResourceWithRawResponse",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Responses API. See docs/RESPONSES_API_PR_BREAKDOWN.md.
2+
3+
from __future__ import annotations
4+
5+
from .responses import (
6+
ResponsesResource,
7+
AsyncResponsesResource,
8+
ResponsesResourceWithRawResponse,
9+
AsyncResponsesResourceWithRawResponse,
10+
ResponsesResourceWithStreamingResponse,
11+
AsyncResponsesResourceWithStreamingResponse,
12+
)
13+
14+
__all__ = [
15+
"AsyncResponsesResource",
16+
"AsyncResponsesResourceWithRawResponse",
17+
"AsyncResponsesResourceWithStreamingResponse",
18+
"ResponsesResource",
19+
"ResponsesResourceWithRawResponse",
20+
"ResponsesResourceWithStreamingResponse",
21+
]

0 commit comments

Comments
 (0)