openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a7ebc26085fa0bb5ceeadc8aebb72dd2dfc9d5a6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_assistants.py

254lines · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6
7import pytest
8
9from openai import OpenAI, AsyncOpenAI
10from tests.utils import assert_matches_type
11from openai._client import OpenAI, AsyncOpenAI
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta import Assistant, AssistantDeleted
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestAssistants:
20 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 assistant = client.beta.assistants.create(
27 model="string",
28 )
29 assert_matches_type(Assistant, assistant, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params(self, client: OpenAI) -> None:
33 assistant = client.beta.assistants.create(
34 model="string",
35 description="string",
36 file_ids=["string", "string", "string"],
37 instructions="string",
38 metadata={},
39 name="string",
40 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
41 )
42 assert_matches_type(Assistant, assistant, path=["response"])
43
44 @parametrize
45 def test_raw_response_create(self, client: OpenAI) -> None:
46 response = client.beta.assistants.with_raw_response.create(
47 model="string",
48 )
49 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50 assistant = response.parse()
51 assert_matches_type(Assistant, assistant, path=["response"])
52
53 @parametrize
54 def test_method_retrieve(self, client: OpenAI) -> None:
55 assistant = client.beta.assistants.retrieve(
56 "string",
57 )
58 assert_matches_type(Assistant, assistant, path=["response"])
59
60 @parametrize
61 def test_raw_response_retrieve(self, client: OpenAI) -> None:
62 response = client.beta.assistants.with_raw_response.retrieve(
63 "string",
64 )
65 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
66 assistant = response.parse()
67 assert_matches_type(Assistant, assistant, path=["response"])
68
69 @parametrize
70 def test_method_update(self, client: OpenAI) -> None:
71 assistant = client.beta.assistants.update(
72 "string",
73 )
74 assert_matches_type(Assistant, assistant, path=["response"])
75
76 @parametrize
77 def test_method_update_with_all_params(self, client: OpenAI) -> None:
78 assistant = client.beta.assistants.update(
79 "string",
80 description="string",
81 file_ids=["string", "string", "string"],
82 instructions="string",
83 metadata={},
84 model="string",
85 name="string",
86 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
87 )
88 assert_matches_type(Assistant, assistant, path=["response"])
89
90 @parametrize
91 def test_raw_response_update(self, client: OpenAI) -> None:
92 response = client.beta.assistants.with_raw_response.update(
93 "string",
94 )
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96 assistant = response.parse()
97 assert_matches_type(Assistant, assistant, path=["response"])
98
99 @parametrize
100 def test_method_list(self, client: OpenAI) -> None:
101 assistant = client.beta.assistants.list()
102 assert_matches_type(SyncCursorPage[Assistant], assistant, path=["response"])
103
104 @parametrize
105 def test_method_list_with_all_params(self, client: OpenAI) -> None:
106 assistant = client.beta.assistants.list(
107 after="string",
108 before="string",
109 limit=0,
110 order="asc",
111 )
112 assert_matches_type(SyncCursorPage[Assistant], assistant, path=["response"])
113
114 @parametrize
115 def test_raw_response_list(self, client: OpenAI) -> None:
116 response = client.beta.assistants.with_raw_response.list()
117 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
118 assistant = response.parse()
119 assert_matches_type(SyncCursorPage[Assistant], assistant, path=["response"])
120
121 @parametrize
122 def test_method_delete(self, client: OpenAI) -> None:
123 assistant = client.beta.assistants.delete(
124 "string",
125 )
126 assert_matches_type(AssistantDeleted, assistant, path=["response"])
127
128 @parametrize
129 def test_raw_response_delete(self, client: OpenAI) -> None:
130 response = client.beta.assistants.with_raw_response.delete(
131 "string",
132 )
133 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
134 assistant = response.parse()
135 assert_matches_type(AssistantDeleted, assistant, path=["response"])
136
137
138class TestAsyncAssistants:
139 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
140 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
141 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
142
143 @parametrize
144 async def test_method_create(self, client: AsyncOpenAI) -> None:
145 assistant = await client.beta.assistants.create(
146 model="string",
147 )
148 assert_matches_type(Assistant, assistant, path=["response"])
149
150 @parametrize
151 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
152 assistant = await client.beta.assistants.create(
153 model="string",
154 description="string",
155 file_ids=["string", "string", "string"],
156 instructions="string",
157 metadata={},
158 name="string",
159 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
160 )
161 assert_matches_type(Assistant, assistant, path=["response"])
162
163 @parametrize
164 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
165 response = await client.beta.assistants.with_raw_response.create(
166 model="string",
167 )
168 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
169 assistant = response.parse()
170 assert_matches_type(Assistant, assistant, path=["response"])
171
172 @parametrize
173 async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
174 assistant = await client.beta.assistants.retrieve(
175 "string",
176 )
177 assert_matches_type(Assistant, assistant, path=["response"])
178
179 @parametrize
180 async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
181 response = await client.beta.assistants.with_raw_response.retrieve(
182 "string",
183 )
184 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
185 assistant = response.parse()
186 assert_matches_type(Assistant, assistant, path=["response"])
187
188 @parametrize
189 async def test_method_update(self, client: AsyncOpenAI) -> None:
190 assistant = await client.beta.assistants.update(
191 "string",
192 )
193 assert_matches_type(Assistant, assistant, path=["response"])
194
195 @parametrize
196 async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None:
197 assistant = await client.beta.assistants.update(
198 "string",
199 description="string",
200 file_ids=["string", "string", "string"],
201 instructions="string",
202 metadata={},
203 model="string",
204 name="string",
205 tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
206 )
207 assert_matches_type(Assistant, assistant, path=["response"])
208
209 @parametrize
210 async def test_raw_response_update(self, client: AsyncOpenAI) -> None:
211 response = await client.beta.assistants.with_raw_response.update(
212 "string",
213 )
214 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
215 assistant = response.parse()
216 assert_matches_type(Assistant, assistant, path=["response"])
217
218 @parametrize
219 async def test_method_list(self, client: AsyncOpenAI) -> None:
220 assistant = await client.beta.assistants.list()
221 assert_matches_type(AsyncCursorPage[Assistant], assistant, path=["response"])
222
223 @parametrize
224 async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
225 assistant = await client.beta.assistants.list(
226 after="string",
227 before="string",
228 limit=0,
229 order="asc",
230 )
231 assert_matches_type(AsyncCursorPage[Assistant], assistant, path=["response"])
232
233 @parametrize
234 async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
235 response = await client.beta.assistants.with_raw_response.list()
236 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
237 assistant = response.parse()
238 assert_matches_type(AsyncCursorPage[Assistant], assistant, path=["response"])
239
240 @parametrize
241 async def test_method_delete(self, client: AsyncOpenAI) -> None:
242 assistant = await client.beta.assistants.delete(
243 "string",
244 )
245 assert_matches_type(AssistantDeleted, assistant, path=["response"])
246
247 @parametrize
248 async def test_raw_response_delete(self, client: AsyncOpenAI) -> None:
249 response = await client.beta.assistants.with_raw_response.delete(
250 "string",
251 )
252 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
253 assistant = response.parse()
254 assert_matches_type(AssistantDeleted, assistant, path=["response"])
255