Skip to content

Commit fc9c38f

Browse files
committed
update
1 parent d0c3d70 commit fc9c38f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

articles/ai-services/openai/includes/fine-tuning-python.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ az cognitiveservices account deployment create
374374

375375
After your custom model deploys, you can use it like any other deployed model. You can use the **Playgrounds** in [Azure OpenAI Studio](https://oai.azure.com) to experiment with your new deployment. You can continue to use the same parameters with your custom model, such as `temperature` and `max_tokens`, as you can with other deployed models. For fine-tuned `babbage-002` and `davinci-002` models you will use the Completions playground and the Completions API. For fine-tuned `gpt-35-turbo-0613` models you will use the Chat playground and the Chat completion API.
376376

377+
# [OpenAI Python 0.28.1](#tab/python)
378+
377379
```python
378380
#Note: The openai-python library support for Azure OpenAI is in preview.
379381
import os
@@ -397,12 +399,41 @@ print(response)
397399
print(response['choices'][0]['message']['content'])
398400
```
399401

402+
# [OpenAI Python 1.x](#tab/python-new)
403+
404+
```python
405+
import os
406+
from openai import AzureOpenAI
407+
408+
client = AzureOpenAI(
409+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
410+
api_key=os.getenv("AZURE_OPENAI_KEY"),
411+
api_version="2023-05-15"
412+
)
413+
414+
response = client.chat.completions.create(
415+
model="gpt-35-turbo-ft", # model = "Custom deployment name you chose for your fine-tuning model"
416+
messages=[
417+
{"role": "system", "content": "You are a helpful assistant."},
418+
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
419+
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
420+
{"role": "user", "content": "Do other Azure AI services support this too?"}
421+
]
422+
)
423+
424+
print(response.choices[0].message.content)
425+
```
426+
427+
---
428+
400429
## Analyze your customized model
401430

402431
Azure OpenAI attaches a result file named _results.csv_ to each fine-tune job after it completes. You can use the result file to analyze the training and validation performance of your customized model. The file ID for the result file is listed for each customized model, and you can use the Python SDK to retrieve the file ID and download the result file for analysis.
403432

404433
The following Python example retrieves the file ID of the first result file attached to the fine-tune job for your customized model, and then uses the Python SDK to download the file to your working directory for analysis.
405434

435+
# [OpenAI Python 0.28.1](#tab/python)
436+
406437
```python
407438
# Retrieve the file ID of the first result file from the fine-tune job
408439
# for the customized model.
@@ -420,6 +451,27 @@ with open(result_file_name, "wb") as file:
420451
file.write(result)
421452
```
422453

454+
# [OpenAI Python 1.x](#tab/python-new)
455+
456+
```python
457+
# Retrieve the file ID of the first result file from the fine-tune job
458+
# for the customized model.
459+
response = client.fine_tuning.jobs.retrieve(job_id)
460+
if response.status == 'succeeded':
461+
result_file_id = response.result_files[0]
462+
463+
retrieve = client.files.retrieve(result_file_id)
464+
465+
# Download the result file.
466+
print(f'Downloading result file: {result_file_id}')
467+
468+
with open(retrieve.filename, "wb") as file:
469+
result = client.files.content(result_file_id).read()
470+
file.write(result)
471+
```
472+
473+
---
474+
423475
The result file is a CSV file that contains a header row and a row for each training step performed by the fine-tune job. The result file contains the following columns:
424476

425477
| Column name | Description |

0 commit comments

Comments
 (0)