2023-06-15 16:51:12 +00:00
# Setup
## Installation
Install this tool using `pip` :
2023-06-17 09:21:30 +00:00
```bash
pip install llm
```
2023-06-15 16:51:12 +00:00
Or using [pipx ](https://pypa.github.io/pipx/ ):
2023-06-17 09:21:30 +00:00
```bash
pipx install llm
```
2023-06-17 15:13:59 +00:00
Or using [Homebrew ](https://brew.sh/ ):
```bash
brew install simonw/llm/llm
```
2023-06-17 21:54:11 +00:00
## Upgrading to the latest version
If you installed using `pip` :
```bash
pip install -U llm
```
For `pipx` :
```bash
pipx upgrade llm
```
For Homebrew:
```bash
brew tap --repair simonw/llm
brew upgrade simonw/llm/llm
```
2023-06-15 16:51:12 +00:00
## Authentication
Many LLM models require an API key. These API keys can be provided to this tool using several different mechanisms.
2023-06-17 09:20:35 +00:00
You can obtain an API key for OpenAI's language models from [the API keys page ](https://platform.openai.com/account/api-keys ) on their site.
2023-06-15 16:51:12 +00:00
2023-06-17 09:20:35 +00:00
### Saving and using stored keys
2023-06-15 16:51:12 +00:00
2023-06-17 09:20:35 +00:00
The easiest way to store an API key is to use the `llm keys set` command:
2023-06-15 16:51:12 +00:00
2023-06-17 09:20:35 +00:00
```bash
2023-06-15 16:51:12 +00:00
llm keys set openai
```
You will be prompted to enter the key like this:
```
% llm keys set openai
Enter key:
```
2023-06-17 09:20:35 +00:00
Once stored, this key will be automatically used for subsequent calls to the API:
2023-06-15 16:51:12 +00:00
2023-06-17 09:20:35 +00:00
```bash
2023-06-15 16:51:12 +00:00
llm "Five ludicrous names for a pet lobster"
```
2023-06-17 09:20:35 +00:00
Keys that are stored in this way live in a file called `keys.json` . This file is located at the path shown when you run the following command:
```bash
llm keys path
```
On macOS this will be `~/Library/Application Support/io.datasette.llm/keys.json` . On Linux it may be something like `~/.config/io.datasette.llm/keys.json` .
2023-06-15 16:51:12 +00:00
### Passing keys using the --key option
Keys can be passed directly using the `--key` option, like this:
2023-06-17 09:21:30 +00:00
```bash
2023-06-15 16:51:12 +00:00
llm "Five names for pet weasels" --key sk-my-key-goes-here
```
You can also pass the alias of a key stored in the `keys.json` file. For example, if you want to maintain a personal API key you could add that like this:
2023-06-17 09:21:30 +00:00
```bash
2023-06-15 16:51:12 +00:00
llm keys set personal
```
And then use it for prompts like so:
2023-06-17 09:21:30 +00:00
```bash
2023-06-15 16:51:12 +00:00
llm "Five friendly names for a pet skunk" --key personal
```
### Keys in environment variables
Keys can also be set using an environment variable. These are different for different models.
For OpenAI models the key will be read from the `OPENAI_API_KEY` environment variable.
The environment variable will be used only if no `--key` option is passed to the command.
If no environment variable is found, the tool will fall back to checking `keys.json` .
You can force the tool to use the key from `keys.json` even if an environment variable has also been set using `llm "prompt" --key openai` .
2023-07-01 21:01:29 +00:00
## Custom directory location
This tool stores various files - prompt templates, stored keys, preferences, a database of logs - in a directory on your computer.
On macOS this is `~/Library/Application Support/io.datasette.llm/` .
On Linux it may be something like `~/.config/io.datasette.llm/` .
You can set a custom location for this directory by setting the `LLM_USER_PATH` environment variable:
```bash
export LLM_USER_PATH=/path/to/my/custom/directory
```