Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
name: sdkinternal-py-env-setup-venv
description: Set up Python virtual environment for azure-ai-contentunderstanding package development. Use this skill when setting up the development environment, creating venv, installing dependencies, or configuring environment variables.
---

# Python Virtual Environment Setup for azure-ai-contentunderstanding

Set up a complete Python development environment for the azure-ai-contentunderstanding package, including virtual environment creation, dependency installation, and environment configuration.

## Package Directory

```
sdk/contentunderstanding/azure-ai-contentunderstanding
```

## Workflow

### 1. Navigate to Package Directory

```bash
cd sdk/contentunderstanding/azure-ai-contentunderstanding
```

### 2. Check and Create Virtual Environment

Check if the virtual environment already exists:

```bash
if [ -d ".venv" ]; then
echo "Virtual environment already exists at .venv"
else
echo "Creating virtual environment..."
python -m venv .venv
echo "Virtual environment created at .venv"
fi
```

### 3. Activate Virtual Environment

**On Linux/macOS:**
```bash
source .venv/bin/activate
```

**On Windows (PowerShell):**
```powershell
.venv\Scripts\Activate.ps1
```

**On Windows (Command Prompt):**
```cmd
.venv\Scripts\activate.bat
```

Verify activation by checking Python location:
```bash
which python # Linux/macOS
# where python # Windows
```

### 4. Install Dependencies

Install the SDK and all development dependencies:

```bash
pip install -e .
pip install -r dev_requirements.txt
```

This installs:
- `aiohttp` - Required for async operations
- `python-dotenv` - For loading `.env` files
- `azure-identity` - For `DefaultAzureCredential` authentication
- `pytest-xdist` - For parallel test execution

### 5. Configure Environment Variables

Check if `.env` file exists in the package root directory:

```bash
if [ -f ".env" ]; then
echo ".env file already exists"
else
echo "Copying env.sample to .env..."
cp env.sample .env
echo "Created .env - Please configure the required variables"
fi
```

### 6. Required Environment Variables

After copying, edit `.env` and configure these **required** variables:

| Variable | Description | Required For |
|----------|-------------|--------------|
| `CONTENTUNDERSTANDING_ENDPOINT` | Microsoft Foundry resource endpoint URL (e.g., `https://<your-resource>.services.ai.azure.com/`) | All samples |
| `CONTENTUNDERSTANDING_KEY` | API key (optional if using DefaultAzureCredential) | API key authentication |
| `GPT_4_1_DEPLOYMENT` | GPT-4.1 deployment name in Microsoft Foundry | sample_update_defaults.py |
| `GPT_4_1_MINI_DEPLOYMENT` | GPT-4.1-mini deployment name | sample_update_defaults.py |
| `TEXT_EMBEDDING_3_LARGE_DEPLOYMENT` | text-embedding-3-large deployment name | sample_update_defaults.py |

**Example `.env` configuration:**
```bash
CONTENTUNDERSTANDING_ENDPOINT=https://<your-resource-name>.services.ai.azure.com/
CONTENTUNDERSTANDING_KEY=<your-api-key> # Optional if using DefaultAzureCredential
GPT_4_1_DEPLOYMENT=gpt-4.1
GPT_4_1_MINI_DEPLOYMENT=gpt-4.1-mini
TEXT_EMBEDDING_3_LARGE_DEPLOYMENT=text-embedding-3-large
```

### 7. Verify Setup

Test the environment by running a sample:

```bash
cd samples
python sample_update_defaults.py
```

## Complete Setup Script (Linux/macOS)

Run the automated setup script:

```bash
# From the package directory
.github/skills/sdkinternal-py-env-setup-venv/scripts/setup_venv.sh
```

Or run all steps manually:

```bash
cd sdk/contentunderstanding/azure-ai-contentunderstanding

# Create venv if not exists
[ ! -d ".venv" ] && python -m venv .venv

# Activate
source .venv/bin/activate

# Install dependencies
pip install -e .
pip install -r dev_requirements.txt

# Copy env.sample if .env doesn't exist
[ ! -f ".env" ] && cp env.sample .env && echo "Created .env - configure required variables"

echo "Setup complete! Edit .env with your configuration."
```

## Troubleshooting

**Error: "python: command not found"**
- Ensure Python 3.9+ is installed
- Try using `python3` instead of `python`

**Error: "pip: command not found" after activation**
- The venv may not have pip. Run: `python -m ensurepip --upgrade`

**Error: "ModuleNotFoundError" when running samples**
- Ensure venv is activated: `source .venv/bin/activate`
- Reinstall dependencies: `pip install -r dev_requirements.txt`

**Error: "Access denied" or authentication failures**
- Check `CONTENTUNDERSTANDING_ENDPOINT` is correct
- If using API key, verify `CONTENTUNDERSTANDING_KEY` is set
- If using DefaultAzureCredential, run `az login` first
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
# Setup script for azure-ai-contentunderstanding Python development environment
# This script sets up venv, installs dependencies, and configures environment variables

set -e

# Determine script directory and package root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PACKAGE_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"

echo "=== Azure AI Content Understanding - Python Environment Setup ==="
echo "Package root: $PACKAGE_ROOT"
echo ""

cd "$PACKAGE_ROOT"

# Step 1: Check and create virtual environment
echo "Step 1: Checking virtual environment..."
if [ -d ".venv" ]; then
echo " ✓ Virtual environment already exists at .venv"
else
echo " Creating virtual environment..."
python3 -m venv .venv || python -m venv .venv
echo " ✓ Virtual environment created at .venv"
fi
echo ""

# Step 2: Activate virtual environment
echo "Step 2: Activating virtual environment..."
source .venv/bin/activate
echo " ✓ Virtual environment activated"
echo " Python: $(which python)"
echo ""

# Step 3: Install dependencies
echo "Step 3: Installing dependencies..."
echo " Installing package in editable mode..."
pip install -e . --quiet
echo " Installing dev requirements..."
pip install -r dev_requirements.txt --quiet
echo " ✓ Dependencies installed"
echo ""

# Step 4: Configure environment variables
echo "Step 4: Configuring environment variables..."
if [ -f ".env" ]; then
echo " ✓ .env file already exists"
else
if [ -f "env.sample" ]; then
cp env.sample .env
echo " ✓ Created .env from env.sample"
echo ""
echo " ⚠ Please configure the required variables in .env:"
echo ""
echo " Required variables:"
echo " CONTENTUNDERSTANDING_ENDPOINT - Your Microsoft Foundry endpoint URL"
echo " CONTENTUNDERSTANDING_KEY - API key (optional if using DefaultAzureCredential)"
echo ""
echo " For running sample_update_defaults.py:"
echo " GPT_4_1_DEPLOYMENT - Your GPT-4.1 deployment name"
echo " GPT_4_1_MINI_DEPLOYMENT - Your GPT-4.1-mini deployment name"
echo " TEXT_EMBEDDING_3_LARGE_DEPLOYMENT - Your text-embedding-3-large deployment name"
echo ""

# Ask user if they want to configure now
read -p " Would you like to configure required variables now? (y/N): " configure_now
if [[ "$configure_now" =~ ^[Yy]$ ]]; then
echo ""
read -p " Enter CONTENTUNDERSTANDING_ENDPOINT: " endpoint
if [ -n "$endpoint" ]; then
sed -i "s|CONTENTUNDERSTANDING_ENDPOINT=.*|CONTENTUNDERSTANDING_ENDPOINT=$endpoint|" .env
fi

read -p " Enter CONTENTUNDERSTANDING_KEY (press Enter to skip for DefaultAzureCredential): " api_key
if [ -n "$api_key" ]; then
sed -i "s|CONTENTUNDERSTANDING_KEY=.*|CONTENTUNDERSTANDING_KEY=$api_key|" .env
fi

read -p " Enter GPT_4_1_DEPLOYMENT (default: gpt-4.1): " gpt41
gpt41="${gpt41:-gpt-4.1}"
sed -i "s|GPT_4_1_DEPLOYMENT=.*|GPT_4_1_DEPLOYMENT=$gpt41|" .env

read -p " Enter GPT_4_1_MINI_DEPLOYMENT (default: gpt-4.1-mini): " gpt41mini
gpt41mini="${gpt41mini:-gpt-4.1-mini}"
sed -i "s|GPT_4_1_MINI_DEPLOYMENT=.*|GPT_4_1_MINI_DEPLOYMENT=$gpt41mini|" .env

read -p " Enter TEXT_EMBEDDING_3_LARGE_DEPLOYMENT (default: text-embedding-3-large): " embedding
embedding="${embedding:-text-embedding-3-large}"
sed -i "s|TEXT_EMBEDDING_3_LARGE_DEPLOYMENT=.*|TEXT_EMBEDDING_3_LARGE_DEPLOYMENT=$embedding|" .env

echo ""
echo " ✓ Environment variables configured"
fi
else
echo " ⚠ env.sample not found, skipping .env creation"
fi
fi
echo ""

# Summary
echo "=== Setup Complete ==="
echo ""
echo "To activate the virtual environment in a new terminal:"
echo " cd $PACKAGE_ROOT"
echo " source .venv/bin/activate"
echo ""
echo "To run samples:"
echo " cd samples"
echo " python sample_update_defaults.py"
echo ""
Loading