@@ -140,6 +140,8 @@ For large data files, we recommend that you import from an Azure Blob store. La
140
140
141
141
The following Python example uploads local training and validation files by using the Python SDK, and retrieves the returned file IDs.
142
142
143
+ # [ OpenAI Python 0.28.1] ( #tab/python )
144
+
143
145
``` python
144
146
# Upload fine-tuning files
145
147
@@ -170,12 +172,50 @@ print("Training file ID:", training_file_id)
170
172
print (" Validation file ID:" , validation_file_id)
171
173
```
172
174
175
+ # [ OpenAI Python 1.x] ( #tab/python-new )
176
+
177
+ ``` python
178
+ # Upload fine-tuning files
179
+
180
+ import os
181
+ from openai import AzureOpenAI
182
+
183
+ client = AzureOpenAI(
184
+ azure_endpoint = os.getenv(" AZURE_OPENAI_ENDPOINT" ),
185
+ api_key = os.getenv(" AZURE_OPENAI_KEY" ),
186
+ api_version = " 2023-10-01-preview" # This API version or later is required to access fine-tuning for turbo/babbage-002/davinci-002
187
+ )
188
+
189
+ training_file_name = ' training_set.jsonl'
190
+ validation_file_name = ' validation_set.jsonl'
191
+
192
+ # Upload the training and validation dataset files to Azure OpenAI with the SDK.
193
+
194
+ training_response = client.files.create(
195
+ file = open (training_file_name, " rb" ), purpose = " fine-tune"
196
+ )
197
+ training_file_id = training_response.id
198
+
199
+ validation_response = client.files.create(
200
+ file = open (validation_file_name, " rb" ), purpose = " fine-tune"
201
+ )
202
+ validation_file_id = validation_response.id
203
+
204
+ print (" Training file ID:" , training_file_id)
205
+ print (" Validation file ID:" , validation_file_id)
206
+
207
+ ```
208
+
209
+ ---
210
+
173
211
## Create a customized model
174
212
175
213
After you upload your training and validation files, you're ready to start the fine-tuning job.
176
214
177
215
The following Python code shows an example of how to create a new fine-tune job with the Python SDK:
178
216
217
+ # [ OpenAI Python 0.28.1] ( #tab/python )
218
+
179
219
``` python
180
220
181
221
response = openai.FineTuningJob.create(
@@ -195,8 +235,31 @@ print(response)
195
235
196
236
```
197
237
238
+ # [ OpenAI Python 1.x] ( #tab/python-new )
239
+
240
+ ``` python
241
+ response = client.fine_tuning.jobs.create(
242
+ training_file = training_file_id,
243
+ validation_file = validation_file_id,
244
+ model = " gpt-35-turbo" , # Enter base model name. Note that in Azure OpenAI the model name contains dashes and cannot contain dot/period characters.
245
+ )
246
+
247
+ job_id = response.id
248
+
249
+ # You can use the job ID to monitor the status of the fine-tuning job.
250
+ # The fine-tuning job will take some time to start and complete.
251
+
252
+ print (" Job ID:" , response.id)
253
+ print (" Status:" , response.id)
254
+ print (response.model_dump_json(indent = 2 ))
255
+ ```
256
+
257
+ ---
258
+
198
259
## Check fine-tuning job status
199
260
261
+ # [ OpenAI Python 0.28.1] ( #tab/python )
262
+
200
263
``` python
201
264
# Retrieve training job ID
202
265
@@ -207,6 +270,18 @@ print("Status:", response["status"])
207
270
print (response)
208
271
```
209
272
273
+ # [ OpenAI Python 1.x] ( #tab/python-new )
274
+
275
+ ``` python
276
+ response = client.fine_tuning.jobs.retrieve(job_id)
277
+
278
+ print (" Job ID:" , response.id)
279
+ print (" Status:" , response.status)
280
+ print (response.model_dump_json(indent = 2 ))
281
+ ```
282
+
283
+ ---
284
+
210
285
## Deploy a customized model
211
286
212
287
When the fine-tune job succeeds, the value of the ` fine_tuned_model ` variable in the response body is set to the name of your customized model. Your model is now also available for discovery from the [ list Models API] ( /rest/api/azureopenai/models/list ) . However, you can't issue completion calls to your customized model until your customized model is deployed. You must deploy your customized model to make it available for use with completion calls.
0 commit comments