Skip to content

Commit

Permalink
feat: allow to run the model locally with ollama and faiss (#17) (#28)
Browse files Browse the repository at this point in the history
* feat: add ollama support in post-documents api (#17)

* docs: add docs on how to change ollama models

* docs: fix sample url

* docs: formatting

* chore: update lockfile

* refactor: rename function

* refactor: move http-response

* refactor: rename ollama.ts

* refactor: simplify http helpers

* refactor: add data http response

* refactor: update api.http

* chore: update packages and clean up dependencies

* refactor: rename functions and ids

* refactor: move code

* refactor: rename models to constants

* feat: persist local storage

* chore: enable streaming

* feat: implement local mode for chat api

* chore: update .gitignore

* fix: use last user message as question

* refactor: consistent error messages

* refactor: formatting

* refactor: clean up frontend

* docs: simplify api docs

* fix: generate .env file in api folder

* chore: update sample env file
  • Loading branch information
sinedied authored Apr 4, 2024
1 parent 12b6e13 commit af4e4be
Show file tree
Hide file tree
Showing 25 changed files with 1,925 additions and 2,044 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- prettier-ignore -->
<div align="center">

<img src="./packages/webapp/public/favicon.png" alt="" align="center" height="64" />
Expand Down Expand Up @@ -68,7 +69,7 @@ You need to install following tools to work on your local machine:

Then you can get the project code:

1. [**Fork**](https://github.com/Azure-Samples/langchainjs-quickstart-demo/fork) the project to create your own copy of this repository.
1. [**Fork**](https://github.com/Azure-Samples/serverless-ai-langchainjs/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.
<div align="center">
<img src="./docs/images/clone-url.png" alt="Screenshot showing how to copy the repository URL" width="400px" />
Expand Down Expand Up @@ -123,15 +124,18 @@ This will start the web app and the API locally. Open the URL `http://localhost:

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 can run the following commands to start the application locally:
Once your deployment is complete, you should see a `.env` file in the `src/api` folder. This file contains the environment variables needed to run the application using Azure resources.

1. Run `azd env get-values > .env` to get the environment variables.
2. Run `npm start` to start the application.
To run the sample, you can then use the same commands as for the Ollama setup:

```bash
npm start
```

This will start the web app and the API locally. Open the URL `http://localhost:8000` in your browser to start chatting with the bot.

> [!TIP]
> You can switch back to using Ollama models by simply deleting the `.env` file and starting the application again.
> You can switch back to using Ollama models by simply deleting the `src/api/.env` file and starting the application again. To regenerate the `.env` file, you can run `azd env get-values > src/api/.env`.
### Deploy the sample to Azure

Expand Down
2 changes: 1 addition & 1 deletion azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
hooks:
postprovision:
shell: sh
run: azd env get-values > .env
run: azd env get-values > src/api/.env
postup:
windows:
shell: pwsh
Expand Down
21 changes: 17 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Invoke-RestMethod -Uri "http://localhost:7071/api/documents" -Method Post -InFil

### For the deployed version

First you need to find the URL of the deployed function. You can either look at the `.env` file at the root of the project and search for the `API_URI` variable, or run this command to get the URL:
First you need to find the URL of the deployed function. You can either look at the `src/api/.env` file and search for the `API_URI` variable, or run this command to get the URL:

```bash
azd env get-values | grep API_URI
Expand Down Expand Up @@ -76,9 +76,22 @@ azd env set AZURE_OPENAI_API_EMBEDDINGS_MODEL_VERSION 1

You may also need to adjust the capacity in `infra/main.bicep` file, depending on how much TPM your account is allowed.

<!--
TODO: how to change local models version with Ollama
-->
### Local models

To change the local models used by Ollama, you can edit the file `packages/api/src/constants.ts`:

```typescript
export const ollamaEmbeddingsModel = 'all-minilm:l6-v2';
export const ollamaChatModel = 'mistral';
```

You can see the complete list of available models at https://ollama.ai/models.

After changing the models, you also need to fetch the new models by running the command:

```bash
ollama pull <model-name>
```

</details>

Expand Down
5 changes: 2 additions & 3 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: Create your own serverless ChatGPT with Retrieval-Augmented-Generat
---

<!-- Learn samples onboarding: https://review.learn.microsoft.com/en-us/help/contribute/samples/process/onboarding?branch=main -->

<!-- prettier-ignore -->
This sample shows how to build a serverless ChatGPT-like experience with Retrieval-Augmented Generation using [LangChain.js](https://js.langchain.com/) and Azure. The application is hosted on [Azure Static Web Apps](https://learn.microsoft.com/azure/static-web-apps/overview) and [Azure Functions](https://learn.microsoft.com/azure/azure-functions/functions-overview?pivots=programming-language-javascript), with [Azure Cosmos DB for MongoDB vCore](https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/) as the vector database. You can use it as a starting point for building more complex AI applications.

<!-- TODO: gif -->
Expand Down Expand Up @@ -53,12 +53,11 @@ This application is made from multiple components:

You can run this project directly in your browser by using GitHub Codespaces, which will open a web-based VS Code.

1. [**Fork**](https://github.com/Azure-Samples/langchainjs-quickstart-demo/fork) the project to create your own copy of this repository.
1. [**Fork**](https://github.com/Azure-Samples/serverless-ai-langchainjs/fork) the project to create your own copy of this repository.
2. On your forked repository, select the **Code** button, then the **Codespaces** tab, and clink on the button **Create codespace on main**.
<div align="center">
<img src="./images/codespaces.png" alt="Screenshot showing how to create a new codespace" width="400px" />
</div>

3. Wait for the Codespace to be created, it should take a few minutes.

## Deploy on Azure
Expand Down
Loading

0 comments on commit af4e4be

Please sign in to comment.