Skip to content

Commit 654e066

Browse files
committed
Minor format adjustments
1 parent 2dd3f18 commit 654e066

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

articles/ai-services/openai/includes/get-key-endpoint.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ To successfully make a call against Azure OpenAI, you need an **endpoint** and a
2020
| `ENDPOINT` | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the value in the **Azure OpenAI Studio** > **Playground** > **Code View**. An example endpoint is: `https://docs-test-001.openai.azure.com/`.|
2121
| `API-KEY` | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.|
2222

23-
Go to your resource in the Azure portal. The **Endpoint and Keys** can be found in the **Resource Management** section. Copy your endpoint and access key as you'll need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
23+
Go to your resource in the Azure portal. The **Keys & Endpoint** section can be found in the **Resource Management** section. Copy your endpoint and access key as you'll need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.
2424

2525
:::image type="content" source="../media/quickstarts/endpoint.png" alt-text="Screenshot of the overview UI for an Azure OpenAI resource in the Azure portal with the endpoint and access keys location circled in red." lightbox="../media/quickstarts/endpoint.png":::

articles/ai-services/openai/tutorials/fine-tune.md

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ In this tutorial you learn how to:
2929
3030
## Prerequisites
3131

32-
* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true).
32+
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true).
3333
- Access granted to Azure OpenAI in the desired Azure subscription Currently, access to this service is granted only by application. You can apply for access to Azure OpenAI by completing the form at https://aka.ms/oai/access.
3434
- Python 3.8 or later version
3535
- The following Python libraries: `json`, `requests`, `os`, `tiktoken`, `time`, `openai`, `numpy`.
@@ -159,6 +159,8 @@ Create the files in the same directory that you're running the Jupyter Notebook,
159159
Now you need to run some preliminary checks on our training and validation files.
160160

161161
```python
162+
# Run preliminary checks
163+
162164
import json
163165

164166
# Load the training set
@@ -203,6 +205,8 @@ In this case we only have 10 training and 10 validation examples so while this w
203205
Now you can then run some additional code from OpenAI using the tiktoken library to validate the token counts. Individual examples need to remain under the `gpt-35-turbo-0613` model's input token limit of 4096 tokens.
204206

205207
```python
208+
# Validate token counts
209+
206210
import json
207211
import tiktoken
208212
import numpy as np
@@ -295,8 +299,8 @@ from openai import AzureOpenAI
295299

296300
client = AzureOpenAI(
297301
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
298-
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
299-
api_version="2024-02-01" # This API version or later is required to access fine-tuning for turbo/babbage-002/davinci-002
302+
api_key = os.getenv("AZURE_OPENAI_API_KEY"),
303+
api_version = "2024-02-01" # This API version or later is required to access fine-tuning for turbo/babbage-002/davinci-002
300304
)
301305

302306
training_file_name = 'training_set.jsonl'
@@ -305,12 +309,12 @@ validation_file_name = 'validation_set.jsonl'
305309
# Upload the training and validation dataset files to Azure OpenAI with the SDK.
306310

307311
training_response = client.files.create(
308-
file=open(training_file_name, "rb"), purpose="fine-tune"
312+
file = open(training_file_name, "rb"), purpose="fine-tune"
309313
)
310314
training_file_id = training_response.id
311315

312316
validation_response = client.files.create(
313-
file=open(validation_file_name, "rb"), purpose="fine-tune"
317+
file = open(validation_file_name, "rb"), purpose="fine-tune"
314318
)
315319
validation_file_id = validation_response.id
316320

@@ -322,6 +326,7 @@ print("Validation file ID:", validation_file_id)
322326

323327
```Python
324328
# Upload fine-tuning files
329+
325330
import openai
326331
import os
327332

@@ -336,12 +341,12 @@ validation_file_name = 'validation_set.jsonl'
336341
# Upload the training and validation dataset files to Azure OpenAI with the SDK.
337342

338343
training_response = openai.File.create(
339-
file=open(training_file_name, "rb"), purpose="fine-tune", user_provided_filename="training_set.jsonl"
344+
file = open(training_file_name, "rb"), purpose="fine-tune", user_provided_filename="training_set.jsonl"
340345
)
341346
training_file_id = training_response["id"]
342347

343348
validation_response = openai.File.create(
344-
file=open(validation_file_name, "rb"), purpose="fine-tune", user_provided_filename="validation_set.jsonl"
349+
file = open(validation_file_name, "rb"), purpose="fine-tune", user_provided_filename="validation_set.jsonl"
345350
)
346351
validation_file_id = validation_response["id"]
347352

@@ -365,10 +370,12 @@ Now that the fine-tuning files have been successfully uploaded you can submit yo
365370
# [OpenAI Python 1.x](#tab/python-new)
366371

367372
```python
373+
# Submit fine-tuning training job
374+
368375
response = client.fine_tuning.jobs.create(
369-
training_file=training_file_id,
370-
validation_file=validation_file_id,
371-
model="gpt-35-turbo-0613", # Enter base model name. Note that in Azure OpenAI the model name contains dashes and cannot contain dot/period characters.
376+
training_file = training_file_id,
377+
validation_file = validation_file_id,
378+
model = "gpt-35-turbo-0613", # Enter base model name. Note that in Azure OpenAI the model name contains dashes and cannot contain dot/period characters.
372379
)
373380

374381
job_id = response.id
@@ -385,10 +392,12 @@ print(response.model_dump_json(indent=2))
385392
# [OpenAI Python 0.28.1](#tab/python)
386393

387394
```python
395+
# Submit fine-tuning training job
396+
388397
response = openai.FineTuningJob.create(
389-
training_file=training_file_id,
390-
validation_file=validation_file_id,
391-
model="gpt-35-turbo-0613",
398+
training_file = training_file_id,
399+
validation_file = validation_file_id,
400+
model = "gpt-35-turbo-0613",
392401
)
393402

394403
job_id = response["id"]
@@ -531,7 +540,7 @@ To get the full results, run the following:
531540
# [OpenAI Python 1.x](#tab/python-new)
532541

533542
```python
534-
#Retrieve fine_tuned_model name
543+
# Retrieve fine_tuned_model name
535544

536545
response = client.fine_tuning.jobs.retrieve(job_id)
537546

@@ -542,7 +551,7 @@ fine_tuned_model = response.fine_tuned_model
542551
# [OpenAI Python 0.28.1](#tab/python)
543552

544553
```python
545-
#Retrieve fine_tuned_model name
554+
# Retrieve fine_tuned_model name
546555

547556
response = openai.FineTuningJob.retrieve(job_id)
548557

@@ -571,14 +580,16 @@ Alternatively, you can deploy your fine-tuned model using any of the other commo
571580
[!INCLUDE [Fine-tuning deletion](../includes/fine-tune.md)]
572581

573582
```python
583+
# Deploy fine-tuned model
584+
574585
import json
575586
import requests
576587

577-
token= os.getenv("TEMP_AUTH_TOKEN")
588+
token = os.getenv("TEMP_AUTH_TOKEN")
578589
subscription = "<YOUR_SUBSCRIPTION_ID>"
579590
resource_group = "<YOUR_RESOURCE_GROUP_NAME>"
580591
resource_name = "<YOUR_AZURE_OPENAI_RESOURCE_NAME>"
581-
model_deployment_name ="YOUR_CUSTOM_MODEL_DEPLOYMENT_NAME"
592+
model_deployment_name = "YOUR_CUSTOM_MODEL_DEPLOYMENT_NAME"
582593

583594
deploy_params = {'api-version': "2023-05-01"}
584595
deploy_headers = {'Authorization': 'Bearer {}'.format(token), 'Content-Type': 'application/json'}
@@ -619,18 +630,20 @@ After your fine-tuned model is deployed, you can use it like any other deployed
619630
# [OpenAI Python 1.x](#tab/python-new)
620631

621632
```python
633+
# Use the deployed customized model
634+
622635
import os
623636
from openai import AzureOpenAI
624637

625638
client = AzureOpenAI(
626639
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
627-
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
628-
api_version="2024-02-01"
640+
api_key = os.getenv("AZURE_OPENAI_API_KEY"),
641+
api_version = "2024-02-01"
629642
)
630643

631644
response = client.chat.completions.create(
632-
model="gpt-35-turbo-ft", # model = "Custom deployment name you chose for your fine-tuning model"
633-
messages=[
645+
model = "gpt-35-turbo-ft", # model = "Custom deployment name you chose for your fine-tuning model"
646+
messages = [
634647
{"role": "system", "content": "You are a helpful assistant."},
635648
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
636649
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
@@ -644,16 +657,19 @@ print(response.choices[0].message.content)
644657
# [OpenAI Python 0.28.1](#tab/python)
645658

646659
```python
660+
# Use the deployed customized model
661+
647662
import os
648663
import openai
664+
649665
openai.api_type = "azure"
650666
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
651667
openai.api_version = "2024-02-01"
652668
openai.api_key = os.getenv("AZURE_OPENAI_API_KEY")
653669

654670
response = openai.ChatCompletion.create(
655-
engine="gpt-35-turbo-ft", # engine = "Custom deployment name you chose for your fine-tuning model"
656-
messages=[
671+
engine = "gpt-35-turbo-ft", # engine = "Custom deployment name you chose for your fine-tuning model"
672+
messages = [
657673
{"role": "system", "content": "You are a helpful assistant."},
658674
{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
659675
{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},

0 commit comments

Comments
 (0)