Dietary Planning with Azure AI¶
This guide demonstrates how to implement dietary planning scenarios using Azure AI Foundry's latest SDKs.
SDK Updates
This guide uses the latest Azure AI SDKs:
Quick Start Example¶
Here's a simple example of getting dietary advice:
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.inference import ChatCompletionsClient
# Initialize clients
credential = DefaultAzureCredential()
project_client = AIProjectClient(
subscription_id=os.getenv("AZURE_SUBSCRIPTION_ID"),
resource_group=os.getenv("AZURE_RESOURCE_GROUP"),
credential=credential
)
chat_client = project_client.inference.get_chat_completions_client()
response = chat_client.complete(
model=os.getenv("MODEL_DEPLOYMENT_NAME"),
messages=[{"role": "user", "content": "How to be healthy in one sentence?"}]
)
print(response.choices[0].message.content)
Dietary Planning Scenarios¶
BMI Calculation
bmi_calculator = {
"type": "function",
"function": {
"name": "calculate_bmi",
"description": "Calculate BMI given height and weight",
"parameters": {
"type": "object",
"properties": {
"height_inches": {"type": "number"},
"weight_pounds": {"type": "number"}
}
}
}
}
response = chat_client.complete(
model=model_name,
messages=[
{"role": "user", "content": "Calculate BMI for 5'9\" and 160 pounds"}
],
tools=[bmi_calculator]
)
Meal Planning
Dietary Restrictions
Content Safety¶
Medical Advice
Always include content safety checks when providing health-related advice:
Response Evaluation¶
Use the TextEvaluator to assess dietary advice quality:
from azure.ai.evaluation import TextEvaluator
evaluator = TextEvaluator(credential=credential)
evaluation = await evaluator.evaluate_text(
text=response.choices[0].message.content,
criteria={
"medical_accuracy": "Advice should be accurate and evidence-based",
"safety": "Advice should include appropriate disclaimers",
"clarity": "Explanations should be clear and easy to understand"
}
)
Best Practices¶
- Always include health disclaimers
- Validate nutritional information
- Consider dietary restrictions
- Monitor response quality
- Implement safety checks
Monitoring
Use Azure Monitor OpenTelemetry for tracking:
For more examples and detailed documentation, see the Azure AI Foundry documentation.