1
0
Fork 0
local-llm/README.md

128 lines
4.6 KiB
Markdown
Raw Normal View History

2024-04-04 14:16:41 +00:00
# local-llm
2024-02-02 17:19:32 +00:00
2024-04-04 14:16:41 +00:00
A quick prototype to self-host [Open WebUI](https://docs.openwebui.com/) backed by [Ollama](https://ollama.com/) to run LLM inference locally.
2024-02-06 18:29:57 +00:00
## Goals
* Streamline deployment of a local LLM for experimentation purpose.
2024-02-06 18:29:57 +00:00
* Deploy a ChatGPT Clone for daily use.
* Deploy an OpenAI-like API for hacking on Generative AI using well-supported libraries.
* Use docker to prepare for an eventual deployment on a container orchestration platform like Kubernetes.
## Getting started
### Prerequisites
2024-02-08 04:19:26 +00:00
* Linux or WSL2
2024-02-06 18:29:57 +00:00
* docker
2024-02-08 04:19:26 +00:00
### Steps for NVIDIA GPU
1. Make sure your drivers are up to date.
2. Install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html).
3. Clone the repo.
2024-04-04 14:16:41 +00:00
4. Copy the NVIDIA compose spec to select it. `cp docker-compose.nvidia.yml docker.compose.yml`
5. Run `docker compose up`. Wait for a few minutes for the model to be downloaded and served.
2024-04-04 14:16:41 +00:00
6. Browse http://localhost:8080/
7. Create an account and start chatting!
2024-02-08 04:19:26 +00:00
### Steps for AMD GPU
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
**Warning: AMD was not tested on Windows.**
1. Make sure your drivers are up to date.
2. Clone the repo.
3. Copy the AMD compose spec to select it. `cp docker-compose.amd.yml docker.compose.yml`
2024-04-04 14:16:41 +00:00
4. Run `docker compose up`. Wait for a few minutes for the model to be downloaded and served.
5. Browse http://localhost:8080/
6. Create an account and start chatting!
2024-02-06 18:29:57 +00:00
2024-02-22 03:01:24 +00:00
### Steps for NO GPU (use CPU)
**Warning: This may be very slow depending on your CPU and may us a lot of RAM depending on the model**
1. Make sure your drivers are up to date.
2. Clone the repo.
3. Copy the CPU compose spec to select it. `cp docker-compose.cpu.yml docker.compose.yml`
4. Run `docker compose up`. Wait for a few minutes for the model to be downloaded and served.
2024-04-04 14:16:41 +00:00
5. Browse http://localhost:8080/
6. Create an account and start chatting!
2024-02-06 18:29:57 +00:00
## Configuring additional models
2024-04-04 14:16:41 +00:00
### Self-hosted (Ollama)
Browse the [Ollama models library](https://ollama.ai/library) to find a model you wish to add. For this example we will add [gemma](https://ollama.com/library/gemma)
#### Configuring via the command-line
``` sh
docker compose exec ollama ollama pull gemma
```
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
### External providers (OpenAI, Mistral, Anthropic, etc.)
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
External providers can be configured through a [LiteLLM](https://github.com/BerriAI/litellm) instance embedded into open-webui. A full list of supported providers, and how to configure them, can be found in the [documentation](https://docs.litellm.ai/docs/providers).
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
Let say we want to configure gpt-3.5-turbo with an OpenAI API key.
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
#### Configuring via a config file
1. Open the file *./litellm/config.yaml* in your editor.
2. Add an entry under `model_list`:
``` yaml
model_list:
- model_name: gpt-3.5-turbo
litellm_params:
model: gpt-3.5-turbo
api_key: <put your OpenAI API key here>
```
3. Run `docker compose restart open-webui` to restart Open WebUI.
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
## Using the API
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
Open WebUI act as a proxy to Ollama and LiteLLM. For both API, authentication is done though a JWT token which can be fetched in the **Settings > About** page in Open WebUI.
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
Open WebUI exposes the Ollama API at the url http://localhost:8080/ollama/api.
Example usage:
``` sh
curl -H "Authorization: Bearer <Paste your JWT token here>" http://localhost:8080/ollama/api/tags
```
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
The Ollama API can also be queried directly on port 11434, without proxing through Open WebUI. In some cases, like when working locally, it may be easier to use without having to proxy through Open WebUI. In that case, there is no authentification.
Example usage:
``` sh
curl http://localhost:11434/api/tags
2024-02-06 18:29:57 +00:00
```
2024-04-04 14:16:41 +00:00
[Ollama also have some OpenAI-compatible APIs](https://ollama.com/blog/openai-compatibility). See the blog post for more detailed usage instructions.
Example usage:
``` sh
curl http://localhost:11434/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "mistral",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'
2024-02-06 18:29:57 +00:00
```
2024-04-04 14:16:41 +00:00
Open WebUI exposes the LiteLLM API (for external providers) at the url http://localhost:8080/litellm/api/v1.
Example usage:
``` sh
curl -H "Authorization: Bearer <Paste your JWT token here>" http://localhost:8080/litellm/api/v1/models
```
2024-02-06 18:29:57 +00:00
2024-04-04 14:16:41 +00:00
The JWT token can be used in place of the OpenAI API key for OpenAI-compatible libraries/applications.
2024-02-22 02:45:43 +00:00
2024-02-22 03:05:38 +00:00
## Alternatives
Check out [LM Studio](https://lmstudio.ai/) for a more integrated, but non web-based alternative!