Edit

Share via


Generative AI for JavaScript developers

Use JavaScript to build generative AI features into your web, mobile, and desktop apps. This overview highlights core concepts, tools, and learning resources to help you get started.

Why use JavaScript for AI?

Python is a common choice for training AI models, but most app developers use models through web APIs. Because JavaScript runs across browsers and servers and handles HTTP calls well, it's a practical choice for building AI apps.

Take the companion course

Use the companion course to learn through videos, code projects, and a full end-to-end sample.

If you're a student or new developer, this course gives you a practical way to learn AI. If you already build apps professionally, it helps you deepen your AI skills.

In this course, you:

  • Learn AI while you bring historical figures to life with generative AI.
  • Apply accessibility by using built-in browser APIs.
  • Use text and image generation to integrate AI into the app experience.
  • Learn architectural patterns for AI applications.

An AI-generated image of Leonardo Da Vinci used in the companion app to talk to historical characters.

Use the companion application to talk to historical characters

What to know about LLMs

Large language models (LLMs) are neural networks trained on large datasets to understand and generate text. Training usually starts with a broad base model and then adds fine-tuning for specific tasks. LLMs can help with scenarios such as code completion and chat, but they also have limits, including context windows and possible bias in training data. That's why responsible AI practices such as fairness, reliability, privacy, and accountability matter.

Learn more in the LLM session of the course:

Use prompt engineering techniques

Prompt engineering is the practice of writing prompts that guide the model toward better results. Use zero-shot prompts when you don't need examples, or few-shot prompts when examples help. Clear instructions, relevant context, and explicit output formats often improve responses and prepare you for more advanced patterns such as RAG.

Learn more in the prompt engineering session of the course:

Improve AI accuracy and reliability with RAG

Use retrieval-augmented generation (RAG) to ground model responses in current, trusted data. RAG combines a retriever that finds relevant content with a generator that uses that content to answer questions. This approach can improve accuracy, make responses easier to verify, and control costs. For example, a real estate support app can use company documents to answer detailed customer questions.

Learn more in the RAG session of the course:

Speed up your AI development with LangChain.js

Speed up your AI projects with LangChain.js. This JavaScript library helps you build prompt templates, connect models and vector stores, and compose complex workflows. It works well for rapid prototyping, such as an API that answers questions from YouTube transcripts. When you're ready for production, you can swap local models and vector stores for Azure services without rewriting your app.

Learn more in the LangChain.js session of the course:

Run AI models on your local machine with Ollama

Use Ollama to run local AI models, including Phi-3, on your machine. Local models reduce cloud dependencies, support offline development, and shorten your inner loop while you test ideas. Because Ollama exposes an OpenAI-compatible API, you can integrate it into existing JavaScript workflows with minimal changes.

Learn more in the Ollama session of the course:

Get started with AI for free

You can run AI for free by using Foundry Local, which lets you download AI models and interact with them locally. There's also AI Toolkit for Visual Studio Code, an extension that supports model download, fine-tuning, and more. Ollama is another popular choice for running local models.

You can also try models without any local setup by creating a GitHub Codespace and using a Jupyter notebook to test prompt engineering, few-shot learning, and RAG.

Learn more in the Phi-3 session of the course:

Introduction to Microsoft Foundry

Use Microsoft Foundry to start building generative AI apps with JavaScript. Organize resources with hubs and projects, browse models, and deploy a model to test in a playground. Whether you use managed compute or serverless APIs, the workflow stays the same: choose a model, deploy it, and integrate it into your app.

Learn more in the Foundry session of the course:

Build generative AI apps with Azure Cosmos DB

Learn more in the Azure Cosmos DB session of the course:

Azure tools and services for hosting and storing AI apps

Learn which Azure tools and services fit common AI app architectures, including chat apps, RAG apps, and autonomous agents. This session also shows how to use Azure Developer CLI (AZD) to deploy apps and compare serverless and container-based hosting options.

Learn more in the Azure tools and services session of the course:

Stream generative AI output with the AI Chat Protocol

Use the AI Chat Protocol to support real-time communication between your AI service and client apps. You can stream responses from the browser or from an AI inference server, depending on your architecture. As you implement streaming, plan for API key protection, data safety, and protocol choice. The protocol client supports methods such as getCompletion and getStreamedCompletion, as shown in the serverless RAG with LangChain.js example.

Learn more in the Streaming session of the course: