You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+11-46Lines changed: 11 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ This document provides comprehensive instructions for coding agents working on t
4
4
5
5
## Overview
6
6
7
-
This repository contains a collection of Python scripts that demonstrate how to use the OpenAI API (and compatible APIs like Azure OpenAI, GitHub Models, and Ollama) to generate chat completions. The repository includes examples of:
7
+
This repository contains a collection of Python scripts that demonstrate how to use the OpenAI API (and compatible APIs like Azure OpenAI and Ollama) to generate chat completions. The repository includes examples of:
- Function calling (basic to advanced multi-function scenarios)
11
11
- Structured outputs using Pydantic models
12
12
- Retrieval-Augmented Generation (RAG) with various complexity levels
13
13
- Prompt engineering and safety features
14
14
15
-
The scripts are designed to be educational and can run with multiple LLM providers: **GitHub Models (preferred for agents)**, Azure OpenAI, OpenAI.com, or local Ollama models.
15
+
The scripts are designed to be educational and can run with multiple LLM providers: **Azure OpenAI (preferred)**, OpenAI.com, or local Ollama models.
16
16
17
17
## Code Layout
18
18
@@ -98,7 +98,6 @@ These scripts are automatically run by `azd provision` via the `azure.yaml` post
98
98
**Environment Variables:**
99
99
-`.env.sample` - Example .env file showing all possible configurations
100
100
-`.env.sample.azure` - Azure-specific example
101
-
-`.env.sample.github` - GitHub Models example
102
101
-`.env.sample.ollama` - Ollama example
103
102
-`.env.sample.openai` - OpenAI.com example
104
103
@@ -110,17 +109,10 @@ These scripts are automatically run by `azd provision` via the `azure.yaml` post
110
109
- Runs: `uv run ruff check .` and `uv run black . --check --verbose`
111
110
-**Important:** The CI uses `uv` but local development typically uses standard `pip`
112
111
113
-
**`test-github-models.yaml` - Integration Test:**
114
-
- Runs on: push to main, pull requests to main (limited paths)
115
-
- Tests: `chat.py` and `spanish/chat.py` with GitHub Models
116
-
- Uses: uv for setup, requires models: read permission
-`.devcontainer/devcontainer.json` - Default dev container (Azure OpenAI setup with azd)
122
115
-`.devcontainer/Dockerfile` - Base Python 3.12 image, installs all requirements-dev.txt
123
-
-`.devcontainer/github/` - GitHub Models variant
124
116
-`.devcontainer/ollama/` - Ollama variant
125
117
-`.devcontainer/openai/` - OpenAI.com variant
126
118
@@ -156,31 +148,9 @@ All dev containers install all dependencies from `requirements-dev.txt` which in
156
148
157
149
### Configuring LLM Provider
158
150
159
-
**For agents, ALWAYS prefer GitHub Models** since the agent often won't have access to Azure OpenAI or paid API keys.
160
-
161
151
The scripts read environment variables from a `.env` file. Create one based on your provider:
162
152
163
-
#### Option 1: GitHub Models (RECOMMENDED for agents)
164
-
165
-
**For agents:** Check if `GITHUB_TOKEN` environment variable is available:
166
-
```bash
167
-
if [ -n"$GITHUB_TOKEN" ];then
168
-
echo"GitHub Models available - GITHUB_TOKEN is set"
169
-
else
170
-
echo"GitHub Models not available - GITHUB_TOKEN not found"
171
-
fi
172
-
```
173
-
174
-
In GitHub Codespaces, `GITHUB_TOKEN` is already set, so **no .env file is needed** - scripts will work immediately.
175
-
176
-
If `GITHUB_TOKEN` is available, you can optionally set a different model (default is `gpt-4o`):
177
-
```bash
178
-
export GITHUB_MODEL=openai/gpt-4o-mini
179
-
```
180
-
181
-
**Models that support function calling:**`gpt-4o`, `gpt-4o-mini`, `o3-mini`, `AI21-Jamba-1.5-Large`, `AI21-Jamba-1.5-Mini`, `Codestral-2501`, `Cohere-command-r`, `Ministral-3B`, `Mistral-Large-2411`, `Mistral-Nemo`, `Mistral-small`
182
-
183
-
#### Option 2: Azure OpenAI (requires Azure resources and costs)
153
+
#### Option 1: Azure OpenAI (recommended)
184
154
185
155
**For agents:** Check if Azure OpenAI environment variables are already configured:
186
156
```bash
@@ -199,7 +169,7 @@ azd provision
199
169
200
170
This creates real Azure resources that incur costs. The `.env` file would be created automatically with all needed variables after provisioning.
201
171
202
-
#### Option 3: OpenAI.com (requires API key and costs)
172
+
#### Option 2: OpenAI.com (requires API key and costs)
203
173
204
174
**For agents:** Check if OpenAI.com API key is available:
205
175
```bash
@@ -212,7 +182,7 @@ fi
212
182
213
183
If `OPENAI_API_KEY` is available, ensure `API_HOST=openai` and `OPENAI_MODEL` are also set (e.g., `gpt-4o-mini`).
214
184
215
-
#### Option 4: Ollama (requires local Ollama installation)
185
+
#### Option 3: Ollama (requires local Ollama installation)
216
186
217
187
**For agents:** Check if Ollama is installed and running:
218
188
```bash
@@ -292,13 +262,9 @@ pre-commit run --all-files
292
262
293
263
### Integration Tests
294
264
295
-
The repository has limited automated testing via GitHub Actions. The primary test runs basic scripts with GitHub Models:
265
+
The repository has limited automated testing via GitHub Actions. Changes to scripts should be manually verified by running them:
296
266
297
267
```bash
298
-
# This is what the CI does (requires GitHub token):
299
-
export API_HOST=github
300
-
export GITHUB_TOKEN=$YOUR_TOKEN
301
-
export GITHUB_MODEL=openai/gpt-4o-mini
302
268
python chat.py
303
269
python spanish/chat.py
304
270
```
@@ -309,13 +275,13 @@ python spanish/chat.py
309
275
310
276
### Environment Variables
311
277
312
-
-**All scripts default to `API_HOST=github`** if no .env file is present and no environment variable is set.
278
+
-**All scripts default to `API_HOST=azure`** if no .env file is present and no environment variable is set.
313
279
- Scripts use `load_dotenv(override=True)` which means .env values override environment variables.
314
280
315
281
### Model Compatibility
316
282
317
283
-**Function calling scripts require models that support tools**. Not all models support this:
318
-
- ✅ Supported: `gpt-4o`, `gpt-4o-mini`, and many others (see GitHub Models list above)
284
+
- ✅ Supported: `gpt-4o`, `gpt-4o-mini`, `gpt-5.4`, and many others
319
285
- ❌ Not supported: Older models, some local Ollama models
320
286
- If a script fails with a function calling error, check if your model supports the `tools` parameter.
- Solution: Your `.env` file is missing required Azure variables, or `API_HOST` is set to `azure` but you haven't configured Azure. Switch to GitHub Models or configure Azure properly.
334
+
- Solution: Your `.env` file is missing required Azure variables, or `API_HOST` is set to `azure` but you haven't configured Azure. Run `azd provision` or configure Azure properly.
369
335
370
336
**Error: `openai.APIError: content_filter`**
371
337
- This is expected behavior for `chat_safety.py` - it's demonstrating content filtering.
372
338
- The script catches this error and prints a message.
373
339
374
340
**Error: Function calling not supported**
375
-
- Solution: Use a model that supports tools. For GitHub Models, use `gpt-4o`, `gpt-4o-mini`, or another compatible model from the list above.
341
+
- Solution: Use a model that supports tools, such as `gpt-4o`, `gpt-4o-mini`, or `gpt-5.4`.
These scripts can be run with Azure OpenAI account, OpenAI.com, local Ollama server, or GitHub models,
96
+
These scripts can be run with Azure OpenAI account, OpenAI.com, or local Ollama server,
98
97
depending on the environment variables you set. All the scripts reference the environment variables from a `.env` file, and an example `.env.sample` file is provided. Host-specific instructions are below.
99
98
100
-
## Using GitHub Models
101
-
102
-
If you open this repository in GitHub Codespaces, you can run the scripts for free using GitHub Models without any additional steps, as your `GITHUB_TOKEN` is already configured in the Codespaces environment.
103
-
104
-
If you want to run the scripts locally, you need to set up the `GITHUB_TOKEN` environment variable with a GitHub [personal access token (PAT)](https://github.com/settings/tokens). You can create a PAT by following these steps:
105
-
106
-
1. Go to your GitHub account settings.
107
-
2. Click on "Developer settings" in the left sidebar.
108
-
3. Click on "Personal access tokens" in the left sidebar.
109
-
4. Click on "Tokens (classic)" or "Fine-grained tokens" depending on your preference.
110
-
5. Click on "Generate new token".
111
-
6. Give your token a name and select the scopes you want to grant. For this project, you don't need any specific scopes.
112
-
7. Click on "Generate token".
113
-
8. Copy the generated token.
114
-
9. Set the `GITHUB_TOKEN` environment variable in your terminal or IDE:
115
-
116
-
```shell
117
-
export GITHUB_TOKEN=your_personal_access_token
118
-
```
119
-
120
-
10. Optionally, you can use a model other than "gpt-4o" by setting the `GITHUB_MODEL` environment variable. Use a model that supports functioncalling, such as: `gpt-4o`, `gpt-4o-mini`, `o3-mini`, `AI21-Jamba-1.5-Large`, `AI21-Jamba-1.5-Mini`, `Codestral-2501`, `Cohere-command-r`, `Ministral-3B`, `Mistral-Large-2411`, `Mistral-Nemo`, `Mistral-small`
121
-
122
99
## Using Azure OpenAI models
123
100
124
-
You can run all examples in this repository using GitHub Models. If you want to run the examples using models from Azure OpenAI instead, you need to provision the Azure AI resources, which will incur costs.
125
-
126
101
This project includes infrastructure as code (IaC) to provision Azure OpenAI deployments of "gpt-4o" and "text-embedding-3-large". The IaC is defined in the `infra` directory and uses the Azure Developer CLI to provision the resources.
127
102
128
103
1. Make sure the [Azure Developer CLI (azd)](https://aka.ms/install-azd) is installed.
@@ -133,12 +108,6 @@ This project includes infrastructure as code (IaC) to provision Azure OpenAI dep
133
108
azd auth login
134
109
```
135
110
136
-
For GitHub Codespaces users, if the previous command fails, try:
0 commit comments