Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/ai/azure-ai-projects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This package no longer depends on the `azure-ai-agents` package. See `samples\ag
### Sample updates

* Added `files` samples for operations create, delete, list, retrieve and content.
* Added `finetuning` samples for operations create, retrieve, list, list_events, list_checkpoints, cancel, pause and resume. Also, these samples includes various finetuning techniques like Supervised (SFT), Reinforcement (RFT) and Direct performance optimization (DPO).

## 1.1.0b4 (2025-09-12)

Expand Down
94 changes: 94 additions & 0 deletions sdk/ai/azure-ai-projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,100 @@ print(f"Successfully deleted file: {deleted_file.id}")

<!-- END SNIPPET -->

### Fine-tuning operations

The code below shows Fine-tuning operations using the OpenAI client, which allow you to create, retrieve, list, cancel, pause, resume, and manage fine-tuning jobs. These operations support various fine-tuning techniques like Supervised Fine-Tuning (SFT), Reinforcement Fine-Tuning (RFT), and Direct Performance Optimization (DPO). Full samples can be found under the "finetuning" folder in the [package samples][samples].

<!-- SNIPPET:sample_finetuning_supervised_job.finetuning_supervised_job_sample-->

```python
print("Uploading training file...")
with open(training_file_path, "rb") as f:
train_file = openai_client.files.create(file=f, purpose="fine-tune")
print(f"Uploaded training file with ID: {train_file.id}")

print("Uploading validation file...")
with open(validation_file_path, "rb") as f:
validation_file = openai_client.files.create(file=f, purpose="fine-tune")
print(f"Uploaded validation file with ID: {validation_file.id}")

print("Creating supervised fine-tuning job")
fine_tuning_job = openai_client.fine_tuning.jobs.create(
training_file=train_file.id,
validation_file=validation_file.id,
model=model_name,
method={
"type": "supervised",
"supervised": {
"hyperparameters": {"n_epochs": 3, "batch_size": 1, "learning_rate_multiplier": 1.0}
},
},
)
print(fine_tuning_job)

print(f"Getting fine-tuning job with ID: {fine_tuning_job.id}")
retrieved_job = openai_client.fine_tuning.jobs.retrieve(fine_tuning_job.id)
print(retrieved_job)

print("Listing all fine-tuning jobs:")
for job in openai_client.fine_tuning.jobs.list():
print(job)

print(f"Pausing fine-tuning job with ID: {fine_tuning_job.id}")
paused_job = openai_client.fine_tuning.jobs.pause(fine_tuning_job.id)
print(paused_job)

print(f"Resuming fine-tuning job with ID: {fine_tuning_job.id}")
resumed_job = openai_client.fine_tuning.jobs.resume(fine_tuning_job.id)
print(resumed_job)

print(f"Listing events of fine-tuning job: {fine_tuning_job.id}")
for event in openai_client.fine_tuning.jobs.list_events(fine_tuning_job.id):
print(event)

# Note that to retrieve the checkpoints, job needs to be in terminal state.
print(f"Listing checkpoints of fine-tuning job: {fine_tuning_job.id}")
for checkpoint in openai_client.fine_tuning.jobs.checkpoints.list(fine_tuning_job.id):
print(checkpoint)

print(f"Cancelling fine-tuning job with ID: {fine_tuning_job.id}")
cancelled_job = openai_client.fine_tuning.jobs.cancel(fine_tuning_job.id)
print(f"Successfully cancelled fine-tuning job: {cancelled_job.id}, Status: {cancelled_job.status}")

# Deploy model (using Azure Management SDK - azure-mgmt-cognitiveservices)
print(f"Getting fine-tuning job with ID: {fine_tuning_job.id}")
model_name = openai_client.fine_tuning.jobs.retrieve(fine_tuning_job.id).fine_tuned_model
deployment_name = "gpt-4-1-fine-tuned"

with CognitiveServicesManagementClient(
credential=credential, subscription_id=subscription_id
) as cogsvc_client:

deployment = cogsvc_client.deployments.begin_create_or_update(
resource_group_name=resource_group,
account_name=account_name,
deployment_name=deployment_name,
deployment={
"properties": {
"model": {"format": "OpenAI", "name": model_name, "version": "1"},
},
"sku": {"capacity": 250, "name": "standard"},
},
)

while deployment.status() not in ["succeeded", "failed"]:
time.sleep(30)
print(f"Status: {deployment.status()}")

print(f"Testing fine-tuned model via deployment: {deployment_name}")
response = openai_client.chat.completions.create(
model=deployment_name, messages=[{"role": "user", "content": "Who invented the telephone?"}]
)
print(f"Model response: {response.choices[0].message.content}")
```

<!-- END SNIPPET -->

### Indexes operations

The code below shows some Indexes operations. Full samples can be found under the "indexes"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What's the capital of France?"}]},"preferred_output":[{"role":"assistant","content":"The capital of France is Paris."}],"non_preferred_output":[{"role":"assistant","content":"I think it's London."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is 2+2?"}]},"preferred_output":[{"role":"assistant","content":"2+2 equals 4."}],"non_preferred_output":[{"role":"assistant","content":"2+2 equals 5."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What color is the sky?"}]},"preferred_output":[{"role":"assistant","content":"The sky is typically blue during the day."}],"non_preferred_output":[{"role":"assistant","content":"The sky is always green."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Who wrote Romeo and Juliet?"}]},"preferred_output":[{"role":"assistant","content":"William Shakespeare wrote Romeo and Juliet."}],"non_preferred_output":[{"role":"assistant","content":"Charles Dickens wrote Romeo and Juliet."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the largest planet in our solar system?"}]},"preferred_output":[{"role":"assistant","content":"Jupiter is the largest planet in our solar system."}],"non_preferred_output":[{"role":"assistant","content":"Earth is the largest planet in our solar system."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the speed of light?"}]},"preferred_output":[{"role":"assistant","content":"The speed of light is approximately 299,792,458 meters per second in a vacuum."}],"non_preferred_output":[{"role":"assistant","content":"The speed of light is about 100 mph."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Who painted the Mona Lisa?"}]},"preferred_output":[{"role":"assistant","content":"Leonardo da Vinci painted the Mona Lisa."}],"non_preferred_output":[{"role":"assistant","content":"Pablo Picasso painted the Mona Lisa."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is H2O?"}]},"preferred_output":[{"role":"assistant","content":"H2O is the chemical formula for water."}],"non_preferred_output":[{"role":"assistant","content":"H2O is oxygen gas."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"How many continents are there?"}]},"preferred_output":[{"role":"assistant","content":"There are 7 continents: Africa, Antarctica, Asia, Europe, North America, Australia (Oceania), and South America."}],"non_preferred_output":[{"role":"assistant","content":"There are 5 continents in the world."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the boiling point of water?"}]},"preferred_output":[{"role":"assistant","content":"The boiling point of water is 100 degrees Celsius (212 degrees Fahrenheit) at sea level."}],"non_preferred_output":[{"role":"assistant","content":"Water boils at 50 degrees Celsius."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Who invented the telephone?"}]},"preferred_output":[{"role":"assistant","content":"Alexander Graham Bell is credited with inventing the telephone."}],"non_preferred_output":[{"role":"assistant","content":"Thomas Edison invented the telephone."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the smallest country in the world?"}]},"preferred_output":[{"role":"assistant","content":"Vatican City is the smallest country in the world by both area and population."}],"non_preferred_output":[{"role":"assistant","content":"Russia is the smallest country in the world."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the tallest mountain on Earth?"}]},"preferred_output":[{"role":"assistant","content":"Mount Everest is the tallest mountain on Earth at 8,849 meters (29,032 feet) above sea level."}],"non_preferred_output":[{"role":"assistant","content":"Mount Kilimanjaro is the tallest mountain on Earth."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the largest ocean?"}]},"preferred_output":[{"role":"assistant","content":"The Pacific Ocean is the largest ocean, covering about 46% of Earth's water surface."}],"non_preferred_output":[{"role":"assistant","content":"The Atlantic Ocean is the largest ocean."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"How many days are in a leap year?"}]},"preferred_output":[{"role":"assistant","content":"A leap year has 366 days."}],"non_preferred_output":[{"role":"assistant","content":"A leap year has 365 days."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the chemical symbol for gold?"}]},"preferred_output":[{"role":"assistant","content":"The chemical symbol for gold is Au, from the Latin word 'aurum'."}],"non_preferred_output":[{"role":"assistant","content":"The chemical symbol for gold is Go."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Who was the first person to walk on the moon?"}]},"preferred_output":[{"role":"assistant","content":"Neil Armstrong was the first person to walk on the moon on July 20, 1969."}],"non_preferred_output":[{"role":"assistant","content":"Buzz Aldrin was the first person to walk on the moon."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the freezing point of water?"}]},"preferred_output":[{"role":"assistant","content":"The freezing point of water is 0 degrees Celsius (32 degrees Fahrenheit) at standard pressure."}],"non_preferred_output":[{"role":"assistant","content":"Water freezes at -10 degrees Celsius."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"How many planets are in our solar system?"}]},"preferred_output":[{"role":"assistant","content":"There are 8 planets in our solar system: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune."}],"non_preferred_output":[{"role":"assistant","content":"There are 9 planets in our solar system including Pluto."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the largest desert in the world?"}]},"preferred_output":[{"role":"assistant","content":"The Antarctic Desert is the largest desert in the world. If considering only hot deserts, the Sahara Desert is the largest."}],"non_preferred_output":[{"role":"assistant","content":"The Gobi Desert is the largest desert in the world."}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the speed of light?"}]},"preferred_output":[{"role":"assistant","content":"The speed of light is approximately 299,792,458 meters per second."}],"non_preferred_output":[{"role":"assistant","content":"The speed of light is about 100 mph."}]}
{"input":{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is H2O?"}]},"preferred_output":[{"role":"assistant","content":"H2O is the chemical formula for water."}],"non_preferred_output":[{"role":"assistant","content":"H2O is oxygen gas."}]}
Loading
Loading