openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.7.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/test_assistants.py

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