generative-ai-with-javascript
AGENTS.md1.3k starsChanged 14 months agoMITView on GitHub
This repository is a comprehensive learning course called "Generative AI for Beginners with JavaScript". It teaches developers how to integrate Generative AI into JavaScript applications through a time-traveling narrative where learners interact with historical figures. Key Technologies: - JavaScript/Node.js (ES Modules) - TypeScript (for some lessons) - OpenAI SDK - Model Context Protocol (MCP) - Express.js (for web applications) - GitHub Models (free AI model access) - Azure OpenAI (optional alternative) Architecture: - Multi-package learning repository (not a monorepo, but…
- Reads credentials
- Installs packages
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about microsoft/generative-ai-with-javascript
- @rdenadai.dev“Olha aí, a Microsoft tem lá no Github um repo voltado pros Javascriptos pra aprender sobre GenAI. Legalzin …”Bluesky · Mar 29, 2025 · 7 likes
- @danwahlin.bsky.social“🚀 Ready to supercharge your JavaScript skills with AI? Check out Generative AI with JavaScript! 🤖💻 ✨ …”Bluesky · Nov 18, 2024 · 7 likes
- DanWahlin/ai-repo-week“Create a blog post about https://github.com/microsoft/generative-ai-with-javascript”GitHub · Jun 10, 2025
The biggest 3 of 3 mentions linking to the repository that our crawl found. Each line is their own headline.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
30 rules. About 0 are common, 15 are distinctive, and 15 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
15
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 92
Create a Codespace from your fork
- Very specific: line 102
Ensure Node.js 20+ is installed
- Very specific: line 105
Run npm install followed by npm start
- Distinctive: line 111
Must be set manually for local development
- Distinctive: line 112
No scopes/permissions needed for the token when using GitHub Models
- Very specific: line 174
Ensure GITHUB_TOKEN is set
- Distinctive: line 175
Run any lesson sample that calls OpenAI APIs
- Distinctive: line 176
Verify responses are generated successfully
- Very specific: line 182
Use ES Modules (type: "module" in package.json)
- Very specific: line 183
Use async/await for asynchronous operations
- Very specific: line 184
Prefer const over let, avoid var
- Distinctive: line 185
Use template literals for string interpolation
- Distinctive: line 186
Follow existing code patterns in each lesson
- Distinctive: line 190
Keep lesson code self-contained within lesson directories
- Very specific: line 191
Place shared resources in /docs/ or /assets/
- Distinctive: line 215
Use camelCase for variables and functions
- Distinctive: line 216
Use PascalCase for classes and constructors
- Distinctive: line 218
Use kebab-case for directory names
- Very specific: line 306
Create lesson directory: lessons/XX-lesson-name/
- Distinctive: line 307
Add README.md with lesson content
- Very specific: line 308
Create sample-app/ with starter code
- Very specific: line 309
Create solution/ with complete code
- Very specific: line 310
Add package.json with required dependencies
- Very specific: line 311
Update main README.md and _sidebar.md
- Very specific: line 348
Place in public/audio/ as <character-name>.mp3
- Distinctive: line 405
Follow existing code patterns and structure
- Very specific: line 406
Add translations in lessons/<lesson>/translations/
- Very specific: line 407
Use issue templates in .github/ISSUE_TEMPLATE/
- Distinctive: line 419
Keep lesson samples lightweight and focused
- Distinctive: line 420
Use streaming for better UX in production apps (see lesson 10)
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Project Overview
This repository is a comprehensive learning course called "Generative AI for Beginners with JavaScript". It teaches developers how to integrate Generative AI into JavaScript applications through a time-traveling narrative where learners interact with historical figures.
Key Technologies:
- JavaScript/Node.js (ES Modules)
- TypeScript (for some lessons)
- OpenAI SDK
- Model Context Protocol (MCP)
- Express.js (for web applications)
- GitHub Models (free AI model access)
- Azure OpenAI (optional alternative)
Architecture:
- Multi-package learning repository (not a monorepo, but lesson-based structure)
- Each lesson in
/lessons/contains standalone sample applications - Main companion app in
/app/directory for character interactions - Video content and demos in
/videos/ - Documentation in
/docs/
Repository Structure
/
├── app/ # Main companion app for interacting with historical characters
├── lessons/ # 8 lesson directories, each with sample code and solutions
│ ├── 01-intro-to-genai/
│ ├── 02-first-ai-app/
│ ├── 03-prompt-engineering/
│ ├── 04-structured-output/
│ ├── 05-rag/
│ ├── 06-tool-calling/
│ ├── 07-mcp/
│ └── 08-mcp-advanced/
├── docs/ # Setup guides and additional resources
├── videos/ # Video session content and demos
└── .devcontainer/ # GitHub Codespaces configurationSetup Commands
Prerequisites:
- Node.js 20 or higher
- GitHub account (for GitHub Models access)
- Optional: Personal Access Token (PAT) if running locally
Initial Setup:
# Clone the repository
git clone https://github.com/microsoft/generative-ai-with-javascript.git
cd generative-ai-with-javascript
# Install root dependencies
npm install
# For GitHub Codespaces users (recommended):
# The environment is pre-configured - no additional setup needed
# Use built-in GITHUB_TOKEN environment variable
# For local development:
# 1. Create a GitHub Personal Access Token (PAT) at https://github.com/settings/tokens
# 2. Set it as an environment variable: export GITHUB_TOKEN=your_token_hereRunning the Main Companion App:
cd app
npm install
npm start
# Access at http://localhost:3000 or use "Open in Browser" in CodespacesWorking with Individual Lessons:
Each lesson has its own package.json. Navigate to the specific lesson directory:
cd lessons/02-first-ai-app/sample-app
npm install
npm startDevelopment Workflow
GitHub Codespaces (Recommended)
- Fork the repository
- Create a Codespace from your fork
- Pre-configured environment includes:
- Node.js 20
- VSCode extensions (EditorConfig, Code Runner, REST Client)
- Ollama with phi3 and all-minilm models
GITHUB_TOKENautomatically available
- Navigate to any lesson or app directory and run
npm install && npm start
Local Development
- Ensure Node.js 20+ is installed
- Set
GITHUB_TOKENenvironment variable - Navigate to the directory you want to work with
- Run
npm installfollowed bynpm start
Environment Variables
GITHUB_TOKEN- Required for GitHub Models API access- Automatically available in GitHub Codespaces
- Must be set manually for local development
- No scopes/permissions needed for the token when using GitHub Models
Working with Lessons
Each lesson follows a consistent structure:
README.md- Main lesson content with narrative and technical instructionssample-app/orcode/- Starting code for exercisessolution/- Complete solution codetranslations/- Lesson translations in various languages
To work on a lesson:
cd lessons/<lesson-number>-<lesson-name>/sample-app
npm install
npm startFor TypeScript-based lessons (MCP lessons 07-08):
cd lessons/07-mcp/solution
npm install
npm run build # Compiles TypeScript to build/ directory
npm run client # Runs the MCP client
npm run inspect # Runs MCP inspector toolTesting Instructions
Current Testing Setup:
This is primarily an educational repository focused on tutorial content. There are no automated unit or integration tests for the code samples.
Manual Testing Approach:
- Validate lesson code by running it:
cd lessons/<lesson-name>/sample-app npm install npm start - Test the companion app:
cd app npm install npm start # Interact with characters through the web interface - For MCP lessons, use the inspector tool:
cd lessons/07-mcp/solution npm run build npm run inspect # Test individual tools: npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/call --tool-name add --tool-arg a=1 --tool-arg b=3 - Verify GitHub Models integration:
- Ensure
GITHUB_TOKENis set - Run any lesson sample that calls OpenAI APIs
- Verify responses are generated successfully
- Ensure
Code Style Guidelines
JavaScript/TypeScript Conventions:
- Use ES Modules (
type: "module"in package.json) - Use
async/awaitfor asynchronous operations - Prefer
constoverlet, avoidvar - Use template literals for string interpolation
- Follow existing code patterns in each lesson
File Organization:
- Keep lesson code self-contained within lesson directories
- Place shared resources in
/docs/or/assets/ - Character data stored in
app/public/characters.json - TypeScript source in
src/, compiled output inbuild/
TypeScript (where applicable):
- Target: ES2022
- Module: Node16
- Strict mode enabled
- Output to
build/directory
Import/Export Patterns:
// ES Module imports
import { OpenAI } from 'openai';
import express from 'express';
// Default exports for apps
export default app;Naming Conventions:
- Use camelCase for variables and functions
- Use PascalCase for classes and constructors
- Prefix directories with numbers for lessons (e.g.,
01-intro-to-genai) - Use kebab-case for directory names
Build and Deployment
Building TypeScript Lessons:
cd lessons/07-mcp/solution
npm run build
# Output: build/ directory with compiled JavaScriptDeployment:
The repository uses GitHub Pages for documentation hosting:
npm run build # Builds documentation site
# Deployment handled by .github/workflows/deploy.ymlGitHub Actions Workflows:
deploy.yml- Deploys to GitHub Pageslinks.yml- Checks for broken links (weekly schedule)profanity.yml- Filters inappropriate content in PRsspelling.yml- Spell checks documentation
GitHub Models Integration
Primary AI Service:
This course uses GitHub Models for free access to AI capabilities. All code examples are configured to work with GitHub Models by default.
API Configuration:
import { OpenAI } from 'openai';
const openai = new OpenAI({
baseURL: "https://models.inference.ai.azure.com",
apiKey: process.env.GITHUB_TOKEN,
});Available Models:
gpt-4o- Primary model used in examplesgpt-4o-mini- Lightweight alternative- Access via GitHub Models marketplace: https://github.com/marketplace/models
Monorepo Navigation Tips
While not a true monorepo, this repository contains multiple independent packages:
Finding Lesson Packages:
# List all lesson directories
ls lessons/
# Find all package.json files
find . -name "package.json" -not -path "*/node_modules/*"
# Jump to a specific lesson
cd lessons/03-prompt-engineering/sample-appPackage Locations:
- Root:
/package.json(minimal dependencies: openai, tsx) - Main App:
/app/package.json(Express app with OpenAI) - Each Lesson:
lessons/<lesson>/sample-app/package.jsonorcode/package.json - Solutions:
lessons/<lesson>/solution/package.json
Working Across Packages:
Each package is independent - install dependencies in each directory you work with:
cd lessons/05-rag/sample-app && npm install
cd ../../06-tool-calling/solution && npm installCommon Development Tasks
Adding a New Lesson Sample:
- Create lesson directory:
lessons/XX-lesson-name/ - Add
README.mdwith lesson content - Create
sample-app/with starter code - Create
solution/with complete code - Add package.json with required dependencies
- Update main README.md and
_sidebar.md
Running Spell Check:
# Triggered via GitHub Actions workflow
# Checks: README.md and lessons/01-intro-to-genai/README.mdTesting Links:
# Runs automatically weekly via GitHub Actions
# Or trigger manually via workflow_dispatchCharacter App Specifics
The companion app (/app/) allows interaction with historical AI characters.
Key Files:
app.js- Express server and OpenAI integrationpublic/characters.json- Character definitions and system promptspublic/index.html- Frontend interfaceviews/- EJS templates
Character Configuration:
Edit public/characters.json to:
- Add new characters
- Modify character descriptions (used as system prompts)
- Change character personalities
Adding Background Audio (Optional):
- Download royalty-free music
- Place in
public/audio/as<character-name>.mp3 - Uncomment audio code in
index.html
Troubleshooting
"Cannot find module" errors:
# Ensure you're in the correct directory with package.json
cd lessons/<lesson-name>/sample-app
npm installGitHub Models authentication issues:
# Verify token is set
echo $GITHUB_TOKEN
# For Codespaces: Token is automatically available
# For local: Create PAT at https://github.com/settings/tokensTypeScript compilation errors:
cd lessons/07-mcp/solution
# Check tsconfig.json exists
npm install
npm run buildPort already in use:
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9
# Or use a different port in your app configurationAdditional Notes
Responsible AI:
This repository contains fictional AI-generated content. Historical characters generate responses via AI based on training data, not actual historical views. Content is for educational and entertainment purposes only.
Educational Focus:
- Each lesson builds progressively on previous concepts
- Narrative-driven learning with time-travel story
- Hands-on coding exercises with solutions provided
- Video content supplements written lessons
Contributing:
- See
.github/CONTRIBUTING.mdfor contribution guidelines - Follow existing code patterns and structure
- Add translations in
lessons/<lesson>/translations/ - Use issue templates in
.github/ISSUE_TEMPLATE/
Community Resources:
- Discord: https://discord.gg/kzRShWzttr
- Azure AI Foundry Forum: https://aka.ms/foundry/forum
- Related courses linked in main README.md
Performance Considerations:
- GitHub Codespaces requires 16GB RAM (configured in devcontainer.json)
- Ollama models (phi3, all-minilm) pre-installed in Codespaces
- Keep lesson samples lightweight and focused
- Use streaming for better UX in production apps (see lesson 10)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

