langchainjs-quickstart-demo
langchainjs-quickstart-demo copied to clipboard
Build a generative AI application using LangChain.js, from local to Azure

Ask YouTube: LangChain.js + Azure Quickstart
⭐ If you like this sample, star it on GitHub — it helps a lot!
Overview • Installation • Run the demo • Resources
Discover the journey of building a generative AI application using LangChain.js and Azure. This demo explores the development process from idea to production, using a RAG-based approach for a Q&A system based on YouTube video transcripts.
Overview
This application allows to ask text-based questions about a YouTube video, and uses the transcript of the video to generate responses.
The code comes in two versions:
- local prototype: uses FAISS and Ollama with LLaMa3 model for completion and all-minilm-l6-v2 for embeddings
- Azure cloud version: uses Azure AI Search and GPT-4 Turbo model for completion and text-embedding-3-large for embeddings
Either version can be run as an API using the Azure Functions runtime.
[!NOTE] This sample uses the new HTTP streaming support in Azure Functions that's currently in preview. You can find more information about this feature in the blog post announcement.

Installation
You need Node.js and Ollama installed to run this demo.
After you complete the installation, the next step is to clone this repository on your machine:
- Fork the project to create your own copy of this repository.
- On your forked repository, select the Code button, then the Local tab, and copy the URL of your forked repository.
- Open a terminal and run this command to clone the repo:
git clone <your-repo-url>
Then open a terminal inside the project directory and run the following commands:
npm install
ollama pull llama3
ollama pull all-minilm:l6-v2
This will install the required dependencies and download the models needed for the demo.
Run the demo
This demo comes in three versions: a local prototype, an Azure cloud version, and an API version using Azure Functions. The fastest way to get started is to run the local prototype.
Local prototype
npm run start:local
Azure version
To run the Azure version, you need to have an Azure account and a subscription enabled for Azure OpenAI usage. If you don't have an Azure account, you can create a free account to get started.
For Azure OpenAI, you can request access with this form.
Create the Azure resources
First you need to create an Azure OpenAI instance. You can deploy a version on Azure Portal following this guide.
In Azure AI Studio, you'll need to deploy these two models:
-
text-embedding-3-large
with a deployment name oftext-embedding-3-large
-
gpt-4
version0125-preview
(aka GPT-4 Turbo) with a deployment name ofgpt-4-turbo
[!IMPORTANT] GPT-4 Turbo is currently in preview and may not be available in all regions, see this table for region availability.
You'll also need to have an Azure AI Search instance running. You can deploy a free version on Azure Portal without any cost, following this guide.
Set up the environment
You need to create a .env
file with the following content:
AZURE_AISEARCH_ENDPOINT=https://<your-service-name>.search.windows.net
AZURE_AISEARCH_KEY=<your-aisearch-key>
AZURE_OPENAI_API_KEY=<your-openai-key>
AZURE_OPENAI_API_ENDPOINT=<your-openai-endpoint>
AZURE_OPENAI_API_DEPLOYMENT_NAME="gpt-4-turbo"
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME="text-embedding-3-large"
Then you can run:
npm run start:azure
API version
npm start
Once the server is running, you can test the API in another terminal:
curl http://localhost:7071/api/ask --json '{ "question": "Will GPT-4 Turbo be available on Azure?" }'
By default, the API runs the local version. To run the Azure version, you need to set the USE_AZURE
environment variable to true
:
USE_AZURE=true npm start
[!TIP] The API respond as a stream of text. You can use the
curl
command with the-N
option to disable buffering and see the response in real-time.
Resources
If you want to learn more about the technologies used in this demo, check out the following resources:
You can also find more Azure AI samples here.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.