openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/test_fine_tunes.py

274lines · 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.types import FineTune, FineTuneEventsListResponse
12from openai._client import OpenAI, AsyncOpenAI
13from openai.pagination import SyncPage, AsyncPage
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestFineTunes:
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 fine_tune = client.fine_tunes.create(
27 training_file="file-abc123",
28 )
29 assert_matches_type(FineTune, fine_tune, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params(self, client: OpenAI) -> None:
33 fine_tune = client.fine_tunes.create(
34 training_file="file-abc123",
35 batch_size=0,
36 classification_betas=[0.6, 1, 1.5, 2],
37 classification_n_classes=0,
38 classification_positive_class="string",
39 compute_classification_metrics=True,
40 hyperparameters={"n_epochs": "auto"},
41 learning_rate_multiplier=0,
42 model="curie",
43 prompt_loss_weight=0,
44 suffix="x",
45 validation_file="file-abc123",
46 )
47 assert_matches_type(FineTune, fine_tune, path=["response"])
48
49 @parametrize
50 def test_raw_response_create(self, client: OpenAI) -> None:
51 response = client.fine_tunes.with_raw_response.create(
52 training_file="file-abc123",
53 )
54 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55 fine_tune = response.parse()
56 assert_matches_type(FineTune, fine_tune, path=["response"])
57
58 @parametrize
59 def test_method_retrieve(self, client: OpenAI) -> None:
60 fine_tune = client.fine_tunes.retrieve(
61 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
62 )
63 assert_matches_type(FineTune, fine_tune, path=["response"])
64
65 @parametrize
66 def test_raw_response_retrieve(self, client: OpenAI) -> None:
67 response = client.fine_tunes.with_raw_response.retrieve(
68 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
69 )
70 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
71 fine_tune = response.parse()
72 assert_matches_type(FineTune, fine_tune, path=["response"])
73
74 @parametrize
75 def test_method_list(self, client: OpenAI) -> None:
76 fine_tune = client.fine_tunes.list()
77 assert_matches_type(SyncPage[FineTune], fine_tune, path=["response"])
78
79 @parametrize
80 def test_raw_response_list(self, client: OpenAI) -> None:
81 response = client.fine_tunes.with_raw_response.list()
82 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
83 fine_tune = response.parse()
84 assert_matches_type(SyncPage[FineTune], fine_tune, path=["response"])
85
86 @parametrize
87 def test_method_cancel(self, client: OpenAI) -> None:
88 fine_tune = client.fine_tunes.cancel(
89 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
90 )
91 assert_matches_type(FineTune, fine_tune, path=["response"])
92
93 @parametrize
94 def test_raw_response_cancel(self, client: OpenAI) -> None:
95 response = client.fine_tunes.with_raw_response.cancel(
96 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
97 )
98 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99 fine_tune = response.parse()
100 assert_matches_type(FineTune, fine_tune, path=["response"])
101
102 @pytest.mark.skip(reason="Prism chokes on this")
103 @parametrize
104 def test_method_list_events_overload_1(self, client: OpenAI) -> None:
105 fine_tune = client.fine_tunes.list_events(
106 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
107 )
108 assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
109
110 @pytest.mark.skip(reason="Prism chokes on this")
111 @parametrize
112 def test_method_list_events_with_all_params_overload_1(self, client: OpenAI) -> None:
113 fine_tune = client.fine_tunes.list_events(
114 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
115 stream=False,
116 )
117 assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
118
119 @pytest.mark.skip(reason="Prism chokes on this")
120 @parametrize
121 def test_raw_response_list_events_overload_1(self, client: OpenAI) -> None:
122 response = client.fine_tunes.with_raw_response.list_events(
123 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
124 )
125 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
126 fine_tune = response.parse()
127 assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
128
129 @pytest.mark.skip(reason="Prism chokes on this")
130 @parametrize
131 def test_method_list_events_overload_2(self, client: OpenAI) -> None:
132 client.fine_tunes.list_events(
133 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
134 stream=True,
135 )
136
137 @pytest.mark.skip(reason="Prism chokes on this")
138 @parametrize
139 def test_raw_response_list_events_overload_2(self, client: OpenAI) -> None:
140 response = client.fine_tunes.with_raw_response.list_events(
141 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
142 stream=True,
143 )
144 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
145 response.parse()
146
147
148class TestAsyncFineTunes:
149 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
150 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
151 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
152
153 @parametrize
154 async def test_method_create(self, client: AsyncOpenAI) -> None:
155 fine_tune = await client.fine_tunes.create(
156 training_file="file-abc123",
157 )
158 assert_matches_type(FineTune, fine_tune, path=["response"])
159
160 @parametrize
161 async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
162 fine_tune = await client.fine_tunes.create(
163 training_file="file-abc123",
164 batch_size=0,
165 classification_betas=[0.6, 1, 1.5, 2],
166 classification_n_classes=0,
167 classification_positive_class="string",
168 compute_classification_metrics=True,
169 hyperparameters={"n_epochs": "auto"},
170 learning_rate_multiplier=0,
171 model="curie",
172 prompt_loss_weight=0,
173 suffix="x",
174 validation_file="file-abc123",
175 )
176 assert_matches_type(FineTune, fine_tune, path=["response"])
177
178 @parametrize
179 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
180 response = await client.fine_tunes.with_raw_response.create(
181 training_file="file-abc123",
182 )
183 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
184 fine_tune = response.parse()
185 assert_matches_type(FineTune, fine_tune, path=["response"])
186
187 @parametrize
188 async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
189 fine_tune = await client.fine_tunes.retrieve(
190 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
191 )
192 assert_matches_type(FineTune, fine_tune, path=["response"])
193
194 @parametrize
195 async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
196 response = await client.fine_tunes.with_raw_response.retrieve(
197 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
198 )
199 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
200 fine_tune = response.parse()
201 assert_matches_type(FineTune, fine_tune, path=["response"])
202
203 @parametrize
204 async def test_method_list(self, client: AsyncOpenAI) -> None:
205 fine_tune = await client.fine_tunes.list()
206 assert_matches_type(AsyncPage[FineTune], fine_tune, path=["response"])
207
208 @parametrize
209 async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
210 response = await client.fine_tunes.with_raw_response.list()
211 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
212 fine_tune = response.parse()
213 assert_matches_type(AsyncPage[FineTune], fine_tune, path=["response"])
214
215 @parametrize
216 async def test_method_cancel(self, client: AsyncOpenAI) -> None:
217 fine_tune = await client.fine_tunes.cancel(
218 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
219 )
220 assert_matches_type(FineTune, fine_tune, path=["response"])
221
222 @parametrize
223 async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None:
224 response = await client.fine_tunes.with_raw_response.cancel(
225 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
226 )
227 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
228 fine_tune = response.parse()
229 assert_matches_type(FineTune, fine_tune, path=["response"])
230
231 @pytest.mark.skip(reason="Prism chokes on this")
232 @parametrize
233 async def test_method_list_events_overload_1(self, client: AsyncOpenAI) -> None:
234 fine_tune = await client.fine_tunes.list_events(
235 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
236 )
237 assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
238
239 @pytest.mark.skip(reason="Prism chokes on this")
240 @parametrize
241 async def test_method_list_events_with_all_params_overload_1(self, client: AsyncOpenAI) -> None:
242 fine_tune = await client.fine_tunes.list_events(
243 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
244 stream=False,
245 )
246 assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
247
248 @pytest.mark.skip(reason="Prism chokes on this")
249 @parametrize
250 async def test_raw_response_list_events_overload_1(self, client: AsyncOpenAI) -> None:
251 response = await client.fine_tunes.with_raw_response.list_events(
252 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
253 )
254 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
255 fine_tune = response.parse()
256 assert_matches_type(FineTuneEventsListResponse, fine_tune, path=["response"])
257
258 @pytest.mark.skip(reason="Prism chokes on this")
259 @parametrize
260 async def test_method_list_events_overload_2(self, client: AsyncOpenAI) -> None:
261 await client.fine_tunes.list_events(
262 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
263 stream=True,
264 )
265
266 @pytest.mark.skip(reason="Prism chokes on this")
267 @parametrize
268 async def test_raw_response_list_events_overload_2(self, client: AsyncOpenAI) -> None:
269 response = await client.fine_tunes.with_raw_response.list_events(
270 "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
271 stream=True,
272 )
273 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
274 response.parse()
275