|
1 | 1 | # Command Line Interface (CLI)
|
2 | 2 |
|
3 |
| -**PydanticAI** comes with a simple reference CLI application which you can use to interact with various LLMs directly from the command line. |
| 3 | +**PydanticAI** comes with a CLI, `clai` (pronounced "clay") which you can use to interact with various LLMs from the command line. |
4 | 4 | It provides a convenient way to chat with language models and quickly get answers right in the terminal.
|
5 | 5 |
|
6 | 6 | We originally developed this CLI for our own use, but found ourselves using it so frequently that we decided to share it as part of the PydanticAI package.
|
7 | 7 |
|
8 | 8 | We plan to continue adding new features, such as interaction with MCP servers, access to tools, and more.
|
9 | 9 |
|
10 |
| -## Installation |
| 10 | +## Usage |
11 | 11 |
|
12 |
| -To use the CLI, you need to either install [`pydantic-ai`](install.md), or install |
13 |
| -[`pydantic-ai-slim`](install.md#slim-install) with the `cli` optional group: |
| 12 | +<!-- Keep this in sync with clai/README.md --> |
14 | 13 |
|
15 |
| -```bash |
16 |
| -pip/uv-add "pydantic-ai[cli]" |
17 |
| -``` |
| 14 | +You'll need to set an environment variable depending on the provider you intend to use. |
18 | 15 |
|
19 |
| -To enable command-line argument autocompletion, run: |
| 16 | +E.g. if you're using OpenAI, set the `OPENAI_API_KEY` environment variable: |
20 | 17 |
|
21 | 18 | ```bash
|
22 |
| -register-python-argcomplete pai >> ~/.bashrc # for bash |
23 |
| -register-python-argcomplete pai >> ~/.zshrc # for zsh |
| 19 | +export OPENAI_API_KEY='your-api-key-here' |
24 | 20 | ```
|
25 | 21 |
|
26 |
| -## Usage |
| 22 | +Then with [`uvx`](https://docs.astral.sh/uv/guides/tools/), run: |
27 | 23 |
|
28 |
| -You'll need to set an environment variable depending on the provider you intend to use. |
| 24 | +```bash |
| 25 | +uvx clai |
| 26 | +``` |
29 | 27 |
|
30 |
| -If using OpenAI, set the `OPENAI_API_KEY` environment variable: |
| 28 | +Or to install `clai` globally [with `uv`](https://docs.astral.sh/uv/guides/tools/#installing-tools), run: |
31 | 29 |
|
32 | 30 | ```bash
|
33 |
| -export OPENAI_API_KEY='your-api-key-here' |
| 31 | +uv tool install clai |
| 32 | +... |
| 33 | +clai |
34 | 34 | ```
|
35 | 35 |
|
36 |
| -Then simply run: |
| 36 | +Or with `pip`, run: |
37 | 37 |
|
38 | 38 | ```bash
|
39 |
| -pai |
| 39 | +pip install clai |
| 40 | +... |
| 41 | +clai |
40 | 42 | ```
|
41 | 43 |
|
42 |
| -This will start an interactive session where you can chat with the AI model. Special commands available in interactive mode: |
| 44 | +Either way, running `clai` will start an interactive session where you can chat with the AI model. Special commands available in interactive mode: |
43 | 45 |
|
44 | 46 | - `/exit`: Exit the session
|
45 | 47 | - `/markdown`: Show the last response in markdown format
|
46 | 48 | - `/multiline`: Toggle multiline input mode (use Ctrl+D to submit)
|
47 | 49 |
|
48 |
| -### Choose a model |
| 50 | +### Help |
49 | 51 |
|
50 |
| -You can specify which model to use with the `--model` flag: |
| 52 | +To get help on the CLI, use the `--help` flag: |
51 | 53 |
|
52 | 54 | ```bash
|
53 |
| -$ pai --model=openai:gpt-4 "What's the capital of France?" |
| 55 | +uvx clai --help |
54 | 56 | ```
|
55 | 57 |
|
56 |
| -### Usage with `uvx` |
| 58 | +### Choose a model |
57 | 59 |
|
58 |
| -If you have [uv](https://docs.astral.sh/uv/) installed, the quickest way to run the CLI is with `uvx`: |
| 60 | +You can specify which model to use with the `--model` flag: |
59 | 61 |
|
60 | 62 | ```bash
|
61 |
| -uvx --from pydantic-ai pai |
| 63 | +uvx clai --model anthropic:claude-3-7-sonnet-latest |
62 | 64 | ```
|
| 65 | + |
| 66 | +(a full list of models available can be printed with `uvx clai --list-models`) |
0 commit comments