-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34aabc3
commit fda326a
Showing
9 changed files
with
173 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,85 @@ | ||
This is a [LlamaIndex](https://www.llamaindex.ai/) project using [Next.js](https://nextjs.org/) bootstrapped with [`create-llama`](https://github.com/run-llama/LlamaIndexTS/tree/main/packages/create-llama). | ||
<div align="center"> | ||
|
||
## Getting Started | ||
# Serverless Azure OpenAI Quick Start with LlamaIndex (JavaScript) | ||
|
||
First, install the dependencies: | ||
[![Open project in GitHub Codespaces](https://img.shields.io/badge/Codespaces-Open-blue?style=flat-square&logo=github)](https://codespaces.new/Azure-Samples/llama-index-javascript?hide_repo_select=true&ref=main&quickstart=true) | ||
[![Build Status](https://img.shields.io/github/actions/workflow/status/Azure-Samples/llama-index-javascript/build.yaml?style=flat-square&label=Build)](https://github.com/Azure-Samples/llama-index-javascript/actions) | ||
![Node version](https://img.shields.io/badge/Node.js->=20-3c873a?style=flat-square) | ||
[![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](LICENSE) | ||
|
||
``` | ||
:star: Like and fork this sample to receive lastest changes and updates! | ||
|
||
[Overview](#overview) • [Get started](#get-started) • [Run the sample](#run-the-sample) • [Resources](#resources) | ||
|
||
<img src="./docs/llama-index-javascript.png" alt="Screenshot showing the LlamaIndex app in action" width="640px" /> | ||
|
||
</div> | ||
|
||
This sample shows how to quickly get started with [LlamaIndex.ai](https://www.llamaindex.ai/) on Azure. The application is hosted on [Azure Container Apps](https://learn.microsoft.com/azure/container-apps/). You can use it as a starting point for building more complex AI applications. | ||
|
||
## Get Started | ||
|
||
There are multiple ways to get started with this project. | ||
|
||
The quickest way is to use [GitHub Codespaces](#use-github-codespaces) that provides a preconfigured environment for you. Alternatively, you can [set up your local environment](#use-your-local-environment) following the instructions below. | ||
|
||
### Use your local environment | ||
|
||
You need to install following tools to work on your local machine: | ||
|
||
- [Node.js LTS](https://nodejs.org/download/) | ||
- [Azure Developer CLI](https://aka.ms/azure-dev/install) | ||
- [Docker](https://docs.docker.com/get-docker/) | ||
- [Git](https://git-scm.com/downloads) | ||
- [PowerShell 7+](https://github.com/powershell/powershell) _(for Windows users only)_ | ||
- **Important**: Ensure you can run `pwsh.exe` from a PowerShell command. If this fails, you likely need to upgrade PowerShell. | ||
- Instead of Powershell, you can also use Git Bash or WSL to run the Azure Developer CLI commands. | ||
|
||
Then you can get the project code: | ||
|
||
1. [**Fork**](https://github.com/Azure-Samples/llama-index-javascript/fork) the project to create your own copy of this repository. | ||
2. On your forked repository, select the **Code** button, then the **Local** tab, and copy the URL of your forked repository. | ||
3. Open a terminal and run this command to clone the repo: <code> git clone <your-repo-url> </code> | ||
|
||
### Use GitHub Codespaces | ||
|
||
You can run this project directly in your browser by using GitHub Codespaces, which will open a web-based VS Code: | ||
|
||
[![Open in GitHub Codespaces](https://img.shields.io/static/v1?style=for-the-badge&label=GitHub+Codespaces&message=Open&color=blue&logo=github)](https://codespaces.new/Azure-Samples/azure-openai-assistant-javascript?hide_repo_select=true&ref&quickstart=true) | ||
|
||
### Use a VS Code dev container | ||
|
||
A similar option to Codespaces is VS Code Dev Containers, that will open the project in your local VS Code instance using the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). | ||
|
||
You will also need to have [Docker](https://www.docker.com/products/docker-desktop) installed on your machine to run the container. | ||
|
||
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/Azure-Samples/llama-index-javascript) | ||
|
||
## Run the sample locally (with Azure OpenAI models) | ||
|
||
> [!IMPORTANT] | ||
> If you want to run this sample locally with other models such as Ollama, please visit the [LlamaIndexTS Documentation](https://ts.llamaindex.ai/modules/llms/available_llms/ollama) for more information. | ||
|
||
First you need to provision the Azure resources needed to run the sample. Follow the instructions in the [Deploy the sample to Azure](#deploy-the-sample-to-azure) section to deploy the sample to Azure, then you'll be able to run the sample locally using the deployed Azure resources. | ||
|
||
Once your deployment is complete, you should see a `.env` file at the root of the project. This file contains the environment variables needed to run the application using Azure resources. | ||
|
||
To run the sample, run the following commands, which will start the web app, and the API locally. | ||
|
||
1. Open a terminal and navigate to the root of the project, then run the API server first: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
Second, generate the embeddings of the documents in the `./data` directory (if this folder exists - otherwise, skip this step): | ||
2. Generate the embeddings of the documents in the `./data` directory (if this folder exists - otherwise, skip this step): | ||
|
||
``` | ||
npm run generate | ||
``` | ||
|
||
Third, run the development server: | ||
3. Run the development server: | ||
|
||
``` | ||
npm run dev | ||
|
@@ -26,7 +91,8 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update | |
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Using Docker | ||
|
||
### Using Docker | ||
|
||
1. Build an image for the Next.js app: | ||
|
||
|
@@ -61,27 +127,45 @@ docker run \ | |
<your_app_image_name> | ||
``` | ||
|
||
## Deploying to Azure | ||
## Deploy the sample to Azure | ||
|
||
### Azure prerequisites | ||
|
||
- **Azure account**. If you're new to Azure, [get an Azure account for free](https://azure.microsoft.com/free) to get free Azure credits to get started. If you're a student, you can also get free credits with [Azure for Students](https://aka.ms/azureforstudents). | ||
- **Azure subscription with access enabled for the Azure OpenAI service**. You can request access with [this form](https://aka.ms/oaiapply). | ||
|
||
### Cost estimation | ||
|
||
See the [cost estimation](./docs/cost.md) details for running this sample on Azure. | ||
|
||
### Deploy the sample | ||
|
||
### Provision infrastructure and deploy application code | ||
#### Provision infrastructure and deploy application code | ||
|
||
Run `azd up` to provision your infrastructure and deploy to Azure (or run `azd provision` then `azd deploy` to accomplish the tasks separately). Visit the service endpoints listed to see your application up-and-running! | ||
|
||
To troubleshoot any issues, see [troubleshooting](#troubleshooting). | ||
1. Open a terminal and navigate to the root of the project. | ||
2. Authenticate with Azure by running `azd auth login`. | ||
3. Run `azd up` to deploy the application to Azure. This will provision Azure resources, deploy this sample. | ||
- You will be prompted to select a base location for the resources. | ||
- By default, the OpenAI resource will be deployed to `swedencentral`. For more information about models availability in other regions, [see the models guide](https://learn.microsoft.com/azure/ai-services/openai/concepts/models).** | ||
|
||
### Configure environment variables for running services | ||
The deployment process will take a few minutes. Once it's done, you'll see the URL of the web app in the terminal. | ||
|
||
<div align="center"> | ||
<img src="./docs/azd-up.png" alt="Screenshot of the azd up command result" width="600px" /> | ||
</div> | ||
|
||
Configure environment variables for running services by updating `settings` in [main.parameters.json](./infra/main.parameters.json). | ||
|
||
### Configure CI/CD pipeline | ||
You can now open the web app in your browser and start chatting with the bot. | ||
|
||
1. Create a workflow pipeline file locally. The following starters are available: | ||
- [Deploy with GitHub Actions](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.github/workflows/azure-dev.yml) | ||
- [Deploy with Azure Pipelines](https://github.com/Azure-Samples/azd-starter-bicep/blob/main/.azdo/pipelines/azure-dev.yml) | ||
2. Run `azd pipeline config` to configure the deployment pipeline to connect securely to Azure. | ||
To troubleshoot any issues, see [troubleshooting](#troubleshooting). | ||
|
||
#### Configure environment variables for running services | ||
|
||
Configure environment variables for running services by updating `settings` in [main.parameters.json](./infra/main.parameters.json). | ||
|
||
### Infrastructure Configuration | ||
#### Infrastructure Configuration | ||
|
||
To describe the infrastructure and application, `azure.yaml` along with Infrastructure as Code files using Bicep were added with the following directory structure: | ||
|
||
|
@@ -103,6 +187,15 @@ Each bicep file declares resources to be provisioned. The resources are provisio | |
|
||
More information about [Bicep](https://aka.ms/bicep) language. | ||
|
||
#### Clean up | ||
|
||
To clean up all the Azure resources created by this sample: | ||
|
||
1. Run `azd down --purge` | ||
2. When asked if you are sure you want to continue, enter `y` | ||
|
||
The resource group and all the resources will be deleted. | ||
|
||
### Billing | ||
|
||
Visit the *Cost Management + Billing* page in Azure Portal to track current spend. For more information about how you're billed, and how you can monitor the costs incurred in your Azure subscriptions, visit [billing overview](https://learn.microsoft.com/azure/developer/intro/azure-developer-billing). | ||
|
@@ -122,16 +215,40 @@ A: Your service may have failed to start, or it may be missing some configuratio | |
|
||
For more troubleshooting information, visit [Container Apps troubleshooting](https://learn.microsoft.com/azure/container-apps/troubleshooting). | ||
|
||
### Additional information | ||
If you can't find a solution to your problem, please [open an issue](https://github.com/Azure-Samples/llama-index-javascript/issues) in this repository. | ||
|
||
For additional information about setting up your `azd` project, visit our official [docs](https://learn.microsoft.com/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-convert). | ||
## Resources | ||
|
||
Here are some resources to learn more about the technologies used in this sample: | ||
|
||
## Learn More about LlamaIndex | ||
|
||
To learn more about LlamaIndex, take a look at the following resources: | ||
|
||
- [LlamaIndex Documentation](https://docs.llamaindex.ai) - learn about LlamaIndex (Python features). | ||
- [LlamaIndexTS Documentation](https://ts.llamaindex.ai) - learn about LlamaIndex (Typescript features). | ||
- [Generative AI For Beginners](https://github.com/microsoft/generative-ai-for-beginners) | ||
- [Azure OpenAI Service](https://learn.microsoft.com/azure/ai-services/openai/overview) | ||
- [Azure OpenAI Assistant Builder](https://github.com/Azure-Samples/azure-openai-assistant-builder) | ||
- [Chat + Enterprise data with Azure OpenAI and Azure AI Search](https://github.com/Azure-Samples/azure-search-openai-javascript) | ||
|
||
You can also find [more Azure AI samples here](https://github.com/Azure-Samples/azureai-samples). | ||
|
||
You can check out [the LlamaIndexTS GitHub repository](https://github.com/run-llama/LlamaIndexTS) - your feedback and contributions are welcome! | ||
|
||
## 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 [[email protected]](mailto:[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](https://www.microsoft.com/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. |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Cost estimation | ||
|
||
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. | ||
However, you can use the [Azure pricing calculator](https://azure.com/e/bf51ef20b57a4da08e47511938ad5415) for the resources below to get an estimate. | ||
|
||
- Azure Container Apps: Consumption plan, Free for the first 2M executions. Pricing per execution and memory used. [Pricing](https://azure.microsoft.com/en-us/pricing/details/container-apps/) | ||
- Azure OpenAI: Standard tier, GPT and Ada models. Pricing per 1K tokens used, and at least 1K tokens are used per question. [Pricing](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/) | ||
|
||
⚠️ To avoid unnecessary costs, remember to take down your app if it's no longer in use, | ||
either by deleting the resource group in the Portal or running `azd down --purge`. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
page_type: sample | ||
languages: | ||
- azdeveloper | ||
- javascript | ||
- typescript | ||
- nodejs | ||
- bicep | ||
- html | ||
products: | ||
- azure | ||
- azure-openai | ||
- azure-container-apps | ||
- entra-id | ||
urlFragment: llama-index-javascript | ||
name: "Serverless Azure OpenAI Quick Start with LlamaIndex" | ||
description: A sample project that showcases how to use and deploy LlamaIndex application on Azure using azd. | ||
--- |
This file was deleted.
Oops, something went wrong.