Skip to content

Commit 207c617

Browse files
committed
WIP: azd ai chat
Get AI configuration from config Adds factory to create agent instances
1 parent e64cfe5 commit 207c617

36 files changed

Lines changed: 2689 additions & 0 deletions
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Azure AI Integration Setup
2+
3+
This AI agent can work with both OpenAI and Azure OpenAI Service. Here's how to configure each:
4+
5+
## Option 1: Azure OpenAI Service (Recommended for Azure users)
6+
7+
Azure OpenAI provides the same models as OpenAI but hosted on Azure infrastructure with enterprise security and compliance.
8+
9+
### Prerequisites
10+
1. Azure subscription
11+
2. Azure OpenAI resource created in Azure portal
12+
3. GPT model deployed (e.g., GPT-3.5-turbo or GPT-4)
13+
14+
### Environment Variables
15+
```bash
16+
# Set these environment variables for Azure OpenAI
17+
export AZURE_OPENAI_ENDPOINT="https://your-resource-name.openai.azure.com"
18+
export AZURE_OPENAI_API_KEY="your-azure-openai-api-key"
19+
export AZURE_OPENAI_DEPLOYMENT_NAME="your-gpt-deployment-name"
20+
```
21+
22+
### PowerShell (Windows)
23+
```powershell
24+
$env:AZURE_OPENAI_ENDPOINT="https://your-resource-name.openai.azure.com"
25+
$env:AZURE_OPENAI_API_KEY="your-azure-openai-api-key"
26+
$env:AZURE_OPENAI_DEPLOYMENT_NAME="your-gpt-deployment-name"
27+
```
28+
29+
## Option 2: OpenAI API (Direct)
30+
31+
### Environment Variables
32+
```bash
33+
export OPENAI_API_KEY="your-openai-api-key"
34+
```
35+
36+
### PowerShell (Windows)
37+
```powershell
38+
$env:OPENAI_API_KEY="your-openai-api-key"
39+
```
40+
41+
## Usage Examples
42+
43+
```bash
44+
# Interactive mode
45+
azd ai.chat
46+
47+
# Direct query
48+
azd ai.chat "How do I deploy a Node.js app to Azure Container Apps?"
49+
50+
# Azure-specific queries
51+
azd ai.chat "What's the best way to set up CI/CD with Azure DevOps for my web app?"
52+
azd ai.chat "How do I configure Azure Key Vault for my application secrets?"
53+
```
54+
55+
## Azure OpenAI Advantages
56+
57+
- **Enterprise Security**: Your data stays within your Azure tenant
58+
- **Compliance**: Meets enterprise compliance requirements
59+
- **Integration**: Better integration with other Azure services
60+
- **Cost Control**: Better cost management and billing integration
61+
- **Regional Deployment**: Deploy closer to your users for lower latency
62+
63+
## Setup Steps for Azure OpenAI
64+
65+
1. **Create Azure OpenAI Resource**:
66+
```bash
67+
az cognitiveservices account create \
68+
--name myopenai \
69+
--resource-group myresourcegroup \
70+
--location eastus \
71+
--kind OpenAI \
72+
--sku s0
73+
```
74+
75+
2. **Deploy a Model**:
76+
- Go to Azure OpenAI Studio
77+
- Navigate to "Deployments"
78+
- Create a new deployment with your chosen model (e.g., gpt-35-turbo)
79+
- Note the deployment name for the environment variable
80+
81+
3. **Get API Key**:
82+
```bash
83+
az cognitiveservices account keys list \
84+
--name myopenai \
85+
--resource-group myresourcegroup
86+
```
87+
88+
4. **Set Environment Variables** as shown above
89+
90+
## Model Compatibility
91+
92+
The agent supports various GPT models available in Azure OpenAI:
93+
- GPT-3.5-turbo
94+
- GPT-4
95+
- GPT-4-turbo
96+
- And newer models as they become available
97+
98+
Just make sure your deployment name matches the model you want to use.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Node.js Express App
2+
3+
This is a simple Node.js application using Express with a basic routing setup.
4+
5+
## Project Structure
6+
7+
```
8+
.
9+
├── app.js
10+
├── package.json
11+
├── README.md
12+
└── routes
13+
└── index.js
14+
```
15+
16+
## Getting Started
17+
18+
1. Install dependencies:
19+
```bash
20+
npm install
21+
```
22+
2. Start the server:
23+
```bash
24+
npm start
25+
```
26+
3. Visit [http://localhost:3000](http://localhost:3000) in your browser.
27+
28+
## Features
29+
- Express server setup
30+
- Modular routing
31+
32+
## License
33+
ISC
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Azure AI Agent - Multi-turn Chat Demo
2+
3+
Your Azure AI Agent now supports two modes:
4+
5+
## 1. Single Query Mode
6+
For one-time questions, pass the query as arguments:
7+
```bash
8+
azd.ai.start.exe "How do I deploy a Node.js app to Azure?"
9+
```
10+
11+
## 2. Interactive Chat Mode
12+
For multi-turn conversations, run without arguments:
13+
```bash
14+
azd.ai.start.exe
15+
```
16+
17+
In interactive mode, you'll see:
18+
- 🤖 Welcome message with instructions
19+
- 💬 You: prompt for your input
20+
- 🤖 AI Agent: responses with context awareness
21+
- Type 'exit' or 'quit' to end the session
22+
- Maintains conversation history for context
23+
24+
### Features:
25+
-**Context Aware**: Remembers previous messages in the conversation
26+
-**Azure Focused**: Specialized for Azure development tasks
27+
-**Easy Exit**: Type 'exit', 'quit', or Ctrl+C to quit
28+
-**Memory Management**: Keeps last 10 exchanges to prevent context overflow
29+
-**Error Handling**: Gracefully handles errors and continues the conversation
30+
31+
### Example Interactive Session:
32+
```
33+
🤖 Azure AI Agent - Interactive Chat Mode
34+
Type 'exit', 'quit', or press Ctrl+C to exit
35+
═══════════════════════════════════════════════
36+
37+
💬 You: What is Azure App Service?
38+
39+
🤖 AI Agent: Azure App Service is a platform-as-a-service (PaaS)...
40+
41+
💬 You: How do I deploy to it?
42+
43+
🤖 AI Agent: Based on our previous discussion about App Service...
44+
45+
💬 You: exit
46+
47+
👋 Goodbye! Thanks for using Azure AI Agent!
48+
```
49+
50+
The agent maintains conversation context, so follow-up questions work naturally!
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Get the directory of the script
2+
$EXTENSION_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
3+
4+
# Change to the script directory
5+
Set-Location -Path $EXTENSION_DIR
6+
7+
# Create a safe version of EXTENSION_ID replacing dots with dashes
8+
$EXTENSION_ID_SAFE = $env:EXTENSION_ID -replace '\.', '-'
9+
10+
# Define output directory
11+
$OUTPUT_DIR = if ($env:OUTPUT_DIR) { $env:OUTPUT_DIR } else { Join-Path $EXTENSION_DIR "bin" }
12+
13+
# Create output directory if it doesn't exist
14+
if (-not (Test-Path -Path $OUTPUT_DIR)) {
15+
New-Item -ItemType Directory -Path $OUTPUT_DIR | Out-Null
16+
}
17+
18+
# Get Git commit hash and build date
19+
$COMMIT = git rev-parse HEAD
20+
$BUILD_DATE = (Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ")
21+
22+
# List of OS and architecture combinations
23+
if ($env:EXTENSION_PLATFORM) {
24+
$PLATFORMS = @($env:EXTENSION_PLATFORM)
25+
}
26+
else {
27+
$PLATFORMS = @(
28+
"windows/amd64",
29+
"windows/arm64",
30+
"darwin/amd64",
31+
"darwin/arm64",
32+
"linux/amd64",
33+
"linux/arm64"
34+
)
35+
}
36+
37+
$APP_PATH = "$env:EXTENSION_ID/internal/cmd"
38+
39+
# Loop through platforms and build
40+
foreach ($PLATFORM in $PLATFORMS) {
41+
$OS, $ARCH = $PLATFORM -split '/'
42+
43+
$OUTPUT_NAME = Join-Path $OUTPUT_DIR "$EXTENSION_ID_SAFE-$OS-$ARCH"
44+
45+
if ($OS -eq "windows") {
46+
$OUTPUT_NAME += ".exe"
47+
}
48+
49+
Write-Host "Building for $OS/$ARCH..."
50+
51+
# Delete the output file if it already exists
52+
if (Test-Path -Path $OUTPUT_NAME) {
53+
Remove-Item -Path $OUTPUT_NAME -Force
54+
}
55+
56+
# Set environment variables for Go build
57+
$env:GOOS = $OS
58+
$env:GOARCH = $ARCH
59+
60+
go build `
61+
-ldflags="-X '$APP_PATH.Version=$env:EXTENSION_VERSION' -X '$APP_PATH.Commit=$COMMIT' -X '$APP_PATH.BuildDate=$BUILD_DATE'" `
62+
-o $OUTPUT_NAME
63+
64+
if ($LASTEXITCODE -ne 0) {
65+
Write-Host "An error occurred while building for $OS/$ARCH"
66+
exit 1
67+
}
68+
}
69+
70+
Write-Host "Build completed successfully!"
71+
Write-Host "Binaries are located in the $OUTPUT_DIR directory."
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
# Get the directory of the script
4+
EXTENSION_DIR="$(cd "$(dirname "$0")" && pwd)"
5+
6+
# Change to the script directory
7+
cd "$EXTENSION_DIR" || exit
8+
9+
# Create a safe version of EXTENSION_ID replacing dots with dashes
10+
EXTENSION_ID_SAFE="${EXTENSION_ID//./-}"
11+
12+
# Define output directory
13+
OUTPUT_DIR="${OUTPUT_DIR:-$EXTENSION_DIR/bin}"
14+
15+
# Create output and target directories if they don't exist
16+
mkdir -p "$OUTPUT_DIR"
17+
18+
# Get Git commit hash and build date
19+
COMMIT=$(git rev-parse HEAD)
20+
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
21+
22+
# List of OS and architecture combinations
23+
if [ -n "$EXTENSION_PLATFORM" ]; then
24+
PLATFORMS=("$EXTENSION_PLATFORM")
25+
else
26+
PLATFORMS=(
27+
"windows/amd64"
28+
"windows/arm64"
29+
"darwin/amd64"
30+
"darwin/arm64"
31+
"linux/amd64"
32+
"linux/arm64"
33+
)
34+
fi
35+
36+
APP_PATH="$EXTENSION_ID/internal/cmd"
37+
38+
# Loop through platforms and build
39+
for PLATFORM in "${PLATFORMS[@]}"; do
40+
OS=$(echo "$PLATFORM" | cut -d'/' -f1)
41+
ARCH=$(echo "$PLATFORM" | cut -d'/' -f2)
42+
43+
OUTPUT_NAME="$OUTPUT_DIR/$EXTENSION_ID_SAFE-$OS-$ARCH"
44+
45+
if [ "$OS" = "windows" ]; then
46+
OUTPUT_NAME+='.exe'
47+
fi
48+
49+
echo "Building for $OS/$ARCH..."
50+
51+
# Delete the output file if it already exists
52+
[ -f "$OUTPUT_NAME" ] && rm -f "$OUTPUT_NAME"
53+
54+
# Set environment variables for Go build
55+
GOOS=$OS GOARCH=$ARCH go build \
56+
-ldflags="-X '$APP_PATH.Version=$EXTENSION_VERSION' -X '$APP_PATH.Commit=$COMMIT' -X '$APP_PATH.BuildDate=$BUILD_DATE'" \
57+
-o "$OUTPUT_NAME"
58+
59+
if [ $? -ne 0 ]; then
60+
echo "An error occurred while building for $OS/$ARCH"
61+
exit 1
62+
fi
63+
done
64+
65+
echo "Build completed successfully!"
66+
echo "Binaries are located in the $OUTPUT_DIR directory."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Release History
2+
3+
## 0.0.1 - Initial Version
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
capabilities:
2+
- custom-commands
3+
description: Enables interactive AI agent through AZD
4+
displayName: AZD AI Agent
5+
id: azd.ai.start
6+
language: go
7+
namespace: ai.chat
8+
usage: azd ai.chat <command> [options]
9+
version: 0.0.1
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module azd.ai.start
2+
3+
go 1.24.1
4+
5+
require (
6+
github.com/fatih/color v1.18.0
7+
github.com/spf13/cobra v1.9.1
8+
github.com/tmc/langchaingo v0.1.13
9+
)
10+
11+
require (
12+
github.com/Masterminds/goutils v1.1.1 // indirect
13+
github.com/Masterminds/semver/v3 v3.3.1 // indirect
14+
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
15+
github.com/azure/azure-dev v0.0.0-20250725230316-fffc1a6a410c // indirect
16+
github.com/dlclark/regexp2 v1.10.0 // indirect
17+
github.com/dustin/go-humanize v1.0.1 // indirect
18+
github.com/google/go-cmp v0.7.0 // indirect
19+
github.com/google/uuid v1.6.0 // indirect
20+
github.com/goph/emperror v0.17.2 // indirect
21+
github.com/huandu/xstrings v1.3.3 // indirect
22+
github.com/imdario/mergo v0.3.13 // indirect
23+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
24+
github.com/json-iterator/go v1.1.12 // indirect
25+
github.com/mattn/go-colorable v0.1.14 // indirect
26+
github.com/mattn/go-isatty v0.0.20 // indirect
27+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
28+
github.com/mitchellh/copystructure v1.0.0 // indirect
29+
github.com/mitchellh/reflectwalk v1.0.0 // indirect
30+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
31+
github.com/modern-go/reflect2 v1.0.2 // indirect
32+
github.com/nikolalohinski/gonja v1.5.3 // indirect
33+
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
34+
github.com/pkg/errors v0.9.1 // indirect
35+
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
36+
github.com/rogpeppe/go-internal v1.12.0 // indirect
37+
github.com/shopspring/decimal v1.2.0 // indirect
38+
github.com/sirupsen/logrus v1.9.3 // indirect
39+
github.com/spf13/cast v1.3.1 // indirect
40+
github.com/spf13/pflag v1.0.6 // indirect
41+
github.com/stretchr/testify v1.10.0 // indirect
42+
github.com/yargevad/filepathx v1.0.0 // indirect
43+
go.opentelemetry.io/otel v1.35.0 // indirect
44+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
45+
go.opentelemetry.io/otel/trace v1.35.0 // indirect
46+
go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 // indirect
47+
golang.org/x/crypto v0.37.0 // indirect
48+
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
49+
golang.org/x/net v0.39.0 // indirect
50+
golang.org/x/oauth2 v0.25.0 // indirect
51+
golang.org/x/sync v0.13.0 // indirect
52+
golang.org/x/sys v0.32.0 // indirect
53+
golang.org/x/text v0.24.0 // indirect
54+
google.golang.org/genproto/googleapis/api v0.0.0-20250407143221-ac9807e6c755 // indirect
55+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250407143221-ac9807e6c755 // indirect
56+
google.golang.org/grpc v1.71.1 // indirect
57+
google.golang.org/protobuf v1.36.6 // indirect
58+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
59+
gopkg.in/yaml.v3 v3.0.1 // indirect
60+
)

0 commit comments

Comments
 (0)