openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/fine_tuning/alpha/test_graders.py

285lines · modeblame

a3b8e772stainless-app[bot]1 years ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.types.fine_tuning.alpha import (
13GraderRunResponse,
14GraderValidateResponse,
15)
16
17base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20class TestGraders:
21parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23@parametrize
24def test_method_run(self, client: OpenAI) -> None:
25grader = client.fine_tuning.alpha.graders.run(
26grader={
27"input": "input",
28"name": "name",
29"operation": "eq",
30"reference": "reference",
31"type": "string_check",
32},
33model_sample="model_sample",
34)
35assert_matches_type(GraderRunResponse, grader, path=["response"])
36
37@parametrize
38def test_method_run_with_all_params(self, client: OpenAI) -> None:
39grader = client.fine_tuning.alpha.graders.run(
40grader={
41"input": "input",
42"name": "name",
43"operation": "eq",
44"reference": "reference",
45"type": "string_check",
46},
47model_sample="model_sample",
cca09707stainless-app[bot]1 years ago48item={},
a3b8e772stainless-app[bot]1 years ago49)
50assert_matches_type(GraderRunResponse, grader, path=["response"])
51
52@parametrize
53def test_raw_response_run(self, client: OpenAI) -> None:
54response = client.fine_tuning.alpha.graders.with_raw_response.run(
55grader={
56"input": "input",
57"name": "name",
58"operation": "eq",
59"reference": "reference",
60"type": "string_check",
61},
62model_sample="model_sample",
63)
64
65assert response.is_closed is True
66assert response.http_request.headers.get("X-Stainless-Lang") == "python"
67grader = response.parse()
68assert_matches_type(GraderRunResponse, grader, path=["response"])
69
70@parametrize
71def test_streaming_response_run(self, client: OpenAI) -> None:
72with client.fine_tuning.alpha.graders.with_streaming_response.run(
73grader={
74"input": "input",
75"name": "name",
76"operation": "eq",
77"reference": "reference",
78"type": "string_check",
79},
80model_sample="model_sample",
81) as response:
82assert not response.is_closed
83assert response.http_request.headers.get("X-Stainless-Lang") == "python"
84
85grader = response.parse()
86assert_matches_type(GraderRunResponse, grader, path=["response"])
87
88assert cast(Any, response.is_closed) is True
89
90@parametrize
91def test_method_validate(self, client: OpenAI) -> None:
92grader = client.fine_tuning.alpha.graders.validate(
93grader={
94"input": "input",
95"name": "name",
96"operation": "eq",
97"reference": "reference",
98"type": "string_check",
99},
100)
101assert_matches_type(GraderValidateResponse, grader, path=["response"])
102
103@parametrize
104def test_method_validate_with_all_params(self, client: OpenAI) -> None:
105grader = client.fine_tuning.alpha.graders.validate(
106grader={
107"input": "input",
108"name": "name",
109"operation": "eq",
110"reference": "reference",
111"type": "string_check",
112},
113)
114assert_matches_type(GraderValidateResponse, grader, path=["response"])
115
116@parametrize
117def test_raw_response_validate(self, client: OpenAI) -> None:
118response = client.fine_tuning.alpha.graders.with_raw_response.validate(
119grader={
120"input": "input",
121"name": "name",
122"operation": "eq",
123"reference": "reference",
124"type": "string_check",
125},
126)
127
128assert response.is_closed is True
129assert response.http_request.headers.get("X-Stainless-Lang") == "python"
130grader = response.parse()
131assert_matches_type(GraderValidateResponse, grader, path=["response"])
132
133@parametrize
134def test_streaming_response_validate(self, client: OpenAI) -> None:
135with client.fine_tuning.alpha.graders.with_streaming_response.validate(
136grader={
137"input": "input",
138"name": "name",
139"operation": "eq",
140"reference": "reference",
141"type": "string_check",
142},
143) as response:
144assert not response.is_closed
145assert response.http_request.headers.get("X-Stainless-Lang") == "python"
146
147grader = response.parse()
148assert_matches_type(GraderValidateResponse, grader, path=["response"])
149
150assert cast(Any, response.is_closed) is True
151
152
153class TestAsyncGraders:
c62e9907stainless-app[bot]1 years ago154parametrize = pytest.mark.parametrize(
155"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
156)
a3b8e772stainless-app[bot]1 years ago157
158@parametrize
159async def test_method_run(self, async_client: AsyncOpenAI) -> None:
160grader = await async_client.fine_tuning.alpha.graders.run(
161grader={
162"input": "input",
163"name": "name",
164"operation": "eq",
165"reference": "reference",
166"type": "string_check",
167},
168model_sample="model_sample",
169)
170assert_matches_type(GraderRunResponse, grader, path=["response"])
171
172@parametrize
173async def test_method_run_with_all_params(self, async_client: AsyncOpenAI) -> None:
174grader = await async_client.fine_tuning.alpha.graders.run(
175grader={
176"input": "input",
177"name": "name",
178"operation": "eq",
179"reference": "reference",
180"type": "string_check",
181},
182model_sample="model_sample",
cca09707stainless-app[bot]1 years ago183item={},
a3b8e772stainless-app[bot]1 years ago184)
185assert_matches_type(GraderRunResponse, grader, path=["response"])
186
187@parametrize
188async def test_raw_response_run(self, async_client: AsyncOpenAI) -> None:
189response = await async_client.fine_tuning.alpha.graders.with_raw_response.run(
190grader={
191"input": "input",
192"name": "name",
193"operation": "eq",
194"reference": "reference",
195"type": "string_check",
196},
197model_sample="model_sample",
198)
199
200assert response.is_closed is True
201assert response.http_request.headers.get("X-Stainless-Lang") == "python"
202grader = response.parse()
203assert_matches_type(GraderRunResponse, grader, path=["response"])
204
205@parametrize
206async def test_streaming_response_run(self, async_client: AsyncOpenAI) -> None:
207async with async_client.fine_tuning.alpha.graders.with_streaming_response.run(
208grader={
209"input": "input",
210"name": "name",
211"operation": "eq",
212"reference": "reference",
213"type": "string_check",
214},
215model_sample="model_sample",
216) as response:
217assert not response.is_closed
218assert response.http_request.headers.get("X-Stainless-Lang") == "python"
219
220grader = await response.parse()
221assert_matches_type(GraderRunResponse, grader, path=["response"])
222
223assert cast(Any, response.is_closed) is True
224
225@parametrize
226async def test_method_validate(self, async_client: AsyncOpenAI) -> None:
227grader = await async_client.fine_tuning.alpha.graders.validate(
228grader={
229"input": "input",
230"name": "name",
231"operation": "eq",
232"reference": "reference",
233"type": "string_check",
234},
235)
236assert_matches_type(GraderValidateResponse, grader, path=["response"])
237
238@parametrize
239async def test_method_validate_with_all_params(self, async_client: AsyncOpenAI) -> None:
240grader = await async_client.fine_tuning.alpha.graders.validate(
241grader={
242"input": "input",
243"name": "name",
244"operation": "eq",
245"reference": "reference",
246"type": "string_check",
247},
248)
249assert_matches_type(GraderValidateResponse, grader, path=["response"])
250
251@parametrize
252async def test_raw_response_validate(self, async_client: AsyncOpenAI) -> None:
253response = await async_client.fine_tuning.alpha.graders.with_raw_response.validate(
254grader={
255"input": "input",
256"name": "name",
257"operation": "eq",
258"reference": "reference",
259"type": "string_check",
260},
261)
262
263assert response.is_closed is True
264assert response.http_request.headers.get("X-Stainless-Lang") == "python"
265grader = response.parse()
266assert_matches_type(GraderValidateResponse, grader, path=["response"])
267
268@parametrize
269async def test_streaming_response_validate(self, async_client: AsyncOpenAI) -> None:
270async with async_client.fine_tuning.alpha.graders.with_streaming_response.validate(
271grader={
272"input": "input",
273"name": "name",
274"operation": "eq",
275"reference": "reference",
276"type": "string_check",
277},
278) as response:
279assert not response.is_closed
280assert response.http_request.headers.get("X-Stainless-Lang") == "python"
281
282grader = await response.parse()
283assert_matches_type(GraderValidateResponse, grader, path=["response"])
284
285assert cast(Any, response.is_closed) is True