Azure-AI_Foundry

Lesson 1: Playground Deep Dive

Overview

The Azure AI Foundry Playground is an interactive environment for testing prompts, tuning parameters, and prototyping AI features — all without writing code. This lesson covers each playground type, configuration options, and how to export your work to production code.


Chat Playground

The Chat Playground is the most commonly used interface for working with GPT models.

Layout

Panel Purpose
System message Define the model’s persona, rules, and context (left panel)
Chat session Interactive conversation history (center panel)
Configuration Model selection, parameters, deployment settings (right panel)
Add your data Connect Azure AI Search or upload files for grounded responses

System Message Best Practices

You are [role]. Your job is to [primary task].

Rules:
- [Constraint 1]
- [Constraint 2]
- [Output format requirement]

Context:
- [Domain-specific knowledge]
- [Tone and style guidelines]

Example:

You are a senior financial analyst assistant. Your job is to analyze quarterly
earnings reports and provide concise summaries.

Rules:
- Only use data provided in the conversation. Do not fabricate numbers.
- Present financial figures in USD with appropriate formatting ($X.XM, $X.XB).
- Flag any year-over-year changes greater than 15% as "significant."
- Respond in 3-5 bullet points unless asked for more detail.

Tone: Professional, data-driven, neutral.

Chat Parameters

Parameter Range Default Effect
Temperature 0.0 – 2.0 0.7 Controls randomness. Lower = more deterministic.
Top P 0.0 – 1.0 0.95 Nucleus sampling. Lower = fewer token choices.
Max tokens 1 – model max varies Maximum response length.
Frequency penalty -2.0 – 2.0 0 Penalizes token repetition based on frequency.
Presence penalty -2.0 – 2.0 0 Penalizes tokens that have appeared at all.
Stop sequences up to 4 none Strings that terminate generation.

Parameter Tuning Guide

Need factual, consistent answers (classification, extraction):
→ temperature: 0.0–0.3, top_p: 0.9

Need creative, varied responses (brainstorming, writing):
→ temperature: 0.7–1.2, top_p: 0.95

Need strict format (JSON output, structured data):
→ temperature: 0.0, top_p: 1.0

Need diverse but coherent options (multiple suggestions):
→ temperature: 0.8, top_p: 0.9, presence_penalty: 0.3

Completions Playground

The Completions Playground is for single-turn text generation (no conversation history).

💡 Tip: For most use cases, the Chat Playground with the chat completions API is preferred over the Completions Playground, even for single-turn tasks.


Images Playground

Generate images with DALL-E 3 directly in the portal.

Configuration Options

Setting Options
Model dall-e-3
Size 1024×1024, 1024×1792 (portrait), 1792×1024 (landscape)
Quality standard, hd
Style natural, vivid

Image Generation Tips

Poor prompt:  "A dog"
Good prompt:  "A golden retriever puppy sitting in a field of sunflowers,
               golden hour lighting, shallow depth of field, photorealistic style"

Image Generation with Python

from openai import AzureOpenAI

client = AzureOpenAI(
    azure_endpoint="https://your-resource.openai.azure.com/",
    api_key="your-api-key",
    api_version="2024-12-01-preview"
)

result = client.images.generate(
    model="dall-e-3",
    prompt="A modern office workspace with a standing desk, dual monitors, "
           "and indoor plants. Clean, minimalist style. Soft natural lighting.",
    size="1792x1024",
    quality="hd",
    style="natural",
    n=1
)

image_url = result.data[0].url
revised_prompt = result.data[0].revised_prompt
print(f"Image URL: {image_url}")
print(f"Revised prompt: {revised_prompt}")

Audio Playground

Speech-to-Text (Whisper)

from openai import AzureOpenAI

client = AzureOpenAI(
    azure_endpoint="https://your-resource.openai.azure.com/",
    api_key="your-api-key",
    api_version="2024-12-01-preview"
)

with open("meeting_recording.mp3", "rb") as audio_file:
    transcript = client.audio.transcriptions.create(
        model="whisper",
        file=audio_file,
        response_format="verbose_json",
        timestamp_granularities=["segment"]
    )

print(transcript.text)
for segment in transcript.segments:
    print(f"[{segment.start:.1f}s - {segment.end:.1f}s] {segment.text}")

Text-to-Speech (TTS)

from openai import AzureOpenAI
from pathlib import Path

client = AzureOpenAI(
    azure_endpoint="https://your-resource.openai.azure.com/",
    api_key="your-api-key",
    api_version="2024-12-01-preview"
)

speech_file = Path("output_speech.mp3")

response = client.audio.speech.create(
    model="tts",
    voice="nova",
    input="Welcome to Azure AI Foundry. Today we'll explore prompt engineering."
)

response.stream_to_file(speech_file)
print(f"Audio saved to {speech_file}")

Exporting Playground Configurations to Code

How to Export

  1. Configure your system prompt, messages, and parameters in the Playground
  2. Click the “View Code” button (</> icon)
  3. Select your language: Python, C#, JavaScript, or curl
  4. Copy the generated code into your application

Exported Python Code Example

# Auto-generated from Azure AI Foundry Playground
import os
from openai import AzureOpenAI

client = AzureOpenAI(
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
    api_version="2024-12-01-preview"
)

response = client.chat.completions.create(
    model="gpt-4o-prod",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant that summarizes articles in 3 bullet points."
        },
        {
            "role": "user",
            "content": "Summarize the following article:\n\n{article_text}"
        }
    ],
    temperature=0.3,
    max_tokens=200,
    top_p=0.95,
    frequency_penalty=0,
    presence_penalty=0
)

print(response.choices[0].message.content)

💡 Tip: After exporting, replace hardcoded API keys with environment variables or Azure Key Vault references. Never commit API keys to source control.


Saving and Sharing Configurations

Save a Playground Session

Version Control Your Prompts

project/
├── prompts/
│   ├── customer-support-v1.md      # System prompt text
│   ├── customer-support-v2.md      # Updated version
│   ├── summarization.md
│   └── code-review.md
├── configs/
│   ├── playground-customer-support.json  # Exported config
│   └── playground-summarization.json
└── src/
    └── app.py

Playground Workflow Best Practices

  1. Start with a clear objective — know what you want the model to produce
  2. Write the system prompt first — define persona, rules, and constraints
  3. Test with 5-10 diverse inputs — include edge cases and adversarial inputs
  4. Tune parameters — adjust temperature, max_tokens based on output quality
  5. Export to code — use the View Code button as your starting point
  6. Iterate in code — once basic behavior is validated, refine in your application

💡 Tip: Keep a “prompt journal” of what worked and what didn’t. Prompt engineering is empirical — documenting experiments saves time.

💡 Tip: Use the “Add your data” feature to test RAG (Retrieval-Augmented Generation) scenarios directly in the Playground without building a full pipeline.

💡 Tip: Test your prompts with intentionally bad or adversarial inputs. If a user types “ignore your instructions,” your system prompt should be robust enough to handle it.


Summary


Next: Lesson 2 — Prompt Techniques