https://github.com/sinedied/azure-functions-langchainjs-demo
Build a generative AI application using Azure Functions and LangChain.js
https://github.com/sinedied/azure-functions-langchainjs-demo
ai azure functions langchain-js openai retrieval-augmented-generation serverless
Last synced: 6 months ago
JSON representation
Build a generative AI application using Azure Functions and LangChain.js
- Host: GitHub
- URL: https://github.com/sinedied/azure-functions-langchainjs-demo
- Owner: sinedied
- License: mit
- Created: 2024-03-06T09:48:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-06T12:50:45.000Z (over 1 year ago)
- Last Synced: 2025-03-29T01:11:56.191Z (6 months ago)
- Topics: ai, azure, functions, langchain-js, openai, retrieval-augmented-generation, serverless
- Language: TypeScript
- Homepage:
- Size: 74.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Support: SUPPORT.md
Awesome Lists containing this project
README
# ⚡ + 🦜️🔗 azure-functions-langchainjs-demo
Discover the journey of building a generative AI application using LangChain.js and Azure.
This demo explore the development process from idea to production, using a RAG-based approach for a Q&A system based on YouTube video transcripts.The code comes in two versions:
- [local version](src/local.ts): uses FAISS and Ollama with LLaMa2 model for completion and all-minilm-l6-v2 for embeddings
- [Azure cloud version](src/azure.ts): uses Azure AI Search and GPT-4 Turbo model for completion and text-embedding-3-large for embeddings> **NOTE**: This sample using 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](https://techcommunity.microsoft.com/t5/apps-on-azure-blog/azure-functions-support-for-http-streams-in-node-js-is-now-in/ba-p/4066575).
## Installation
You need [Node.js](https://nodejs.org/en) and [Ollama](https://ollama.com/download) installed to run this demo.
```bash
npm install
ollama pull llama2
ollama pull all-minilm:l6-v2
```## Running the local prototype
```bash
npm start
```Once the server is running, you can test the API in another terminal:
```bash
curl http://localhost:7071/api/ask --json '{ "question": "Will GPT-4 Turbo be available on Azure?" }'
```## Running the 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](https://azure.microsoft.com/free/) to get started.
For Azure OpenAI, you can [request access with this form](https://aka.ms/oaiapply).
### Create the Azure resources
First you need to create an Azure OpenAI instance. You can deploy a version on Azure Portal following [this guide](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal).
In Azure AI Studio, you'll need to deploy these two models:
- `text-embedding-3-large` with a deployment name of `text-embedding-3-large`
- `gpt-4` version `0125-preview` (aka GPT-4 Turbo) with a deployment name of `gpt4-turbo`> **Note**: GPT-4 Turbo is currently in preview and may not be available in all regions, see [this table](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#gpt-4-and-gpt-4-turbo-preview-models) 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](https://learn.microsoft.com/azure/search/search-create-service-portal).
### Set up the environment
You need to create a `.env` file with the following content:
```bash
AZURE_AISEARCH_ENDPOINT=https://.search.windows.net
AZURE_AISEARCH_KEY=
AZURE_OPENAI_API_KEY=
AZURE_OPENAI_API_ENDPOINT=
AZURE_OPENAI_API_DEPLOYMENT_NAME="gpt4-turbo"
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME="text-embedding-3-large"
USE_AZURE=true
```Then you can run:
```bash
npm run start
```And test the API like before.
## 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](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) 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](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
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.