/llm-claude-3

LLM plugin for interacting with the Claude 3 family of models

Primary LanguagePythonApache License 2.0Apache-2.0

llm-claude-3

PyPI Changelog Tests License

LLM access to Claude 3 by Anthropic

Installation

Install this plugin in the same environment as LLM.

llm install llm-claude-3

Usage

First, set an API key for Claude 3:

llm keys set claude
# Paste key here

You can also set the key in the environment variable ANTHROPIC_API_KEY

Run llm models to list the models, and llm models --options to include a list of their options.

Run prompts like this:

llm -m claude-3.5-sonnet 'Fun facts about pelicans'
llm -m claude-3.5-haiku 'Fun facts about armadillos'
llm -m claude-3-opus 'Fun facts about squirrels'

Images are supported too:

llm -m claude-3.5-sonnet 'describe this image' -a https://static.simonwillison.net/static/2024/pelicans.jpg
llm -m claude-3-haiku 'extract text' -a page.png

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd llm-claude-3
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

llm install -e '.[test]'

To run the tests:

pytest

This project uses pytest-recording to record Anthropic API responses for the tests.

If you add a new test that calls the API you can capture the API response like this:

PYTEST_ANTHROPIC_API_KEY="$(llm keys get claude)" pytest --record-mode once

You will need to have stored a valid Anthropic API key using this command first:

llm keys set claude
# Paste key here