Base LLMs are general-purpose. Fine-tuning adapts a model to your domain — your terminology, tone, data formats, and business logic. This leads to higher accuracy, fewer hallucinations, and more consistent outputs for domain-specific tasks.
| Approach | When to Use | Effort |
|---|---|---|
| Prompt Engineering | Simple tasks, few examples, rapid iteration | Low |
| RAG (Retrieval Augmented) | Dynamic knowledge, large corpora | Medium |
| Fine-tuning | Consistent style/schema, specialized domain, cost reduction | High (dataset prep) |
| Pre-training | New language or knowledge from scratch | Very high |
Fine-tuning data typically follows a chat format. For instruction tuning, use this structure:
[
{
"messages": [
{ "role": "system", "content": "You are a medical coding assistant." },
{ "role": "user", "content": "Diagnosis: Type 2 diabetes, initial encounter" },
{ "role": "assistant", "content": "E11.9" }
]
},
{
"messages": [
{ "role": "system", "content": "You are a medical coding assistant." },
{ "role": "user", "content": "Diagnosis: Essential hypertension" },
{ "role": "assistant", "content": "I10" }
]
}
]
Azure AI Foundry provides a managed fine-tuning service for models like GPT-4o, Phi-3, and Llama families:
# Azure CLI — start a fine-tuning job
az ml job create --file fine-tuning-job.yml
# fine-tuning-job.yml
$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
type: command
code: .
command: >-
python finetune.py
--model gpt-4o
--training-file azureml://datasets/train.jsonl
--validation-file azureml://datasets/val.jsonl
environment: azureml:openai-finetune-env:latest
compute: azureml:gpu-cluster
resources:
instance_count: 1
instance_type: Standard_ND40rs_v2
After fine-tuning, evaluate using:
Once validated, deploy the fine-tuned model as a serverless endpoint or managed compute:
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint="https://your-endpoint.openai.azure.com/",
api_version="2024-08-01-preview",
)
response = client.chat.completions.create(
model="gpt-4o-finetuned", # your fine-tuned deployment name
messages=[{"role": "user", "content": "Classify this support ticket: ..."}]
)
In MAF, you can configure an agent to use any model by specifying the deployment in the model config:
const agent = new Agent({
name: "MedicalCoder",
instructions: "Classify diagnoses into ICD-10 codes.",
model: {
provider: "azure-openai",
deployment: "gpt-4o-finetuned",
endpoint: process.env.AZURE_OPENAI_ENDPOINT
}
});