Skip to content
This repository has been archived by the owner on Feb 2, 2025. It is now read-only.

Commit

Permalink
Rename plugin to llm-anthropic, refs #31
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Dec 17, 2024
1 parent 8c08d56 commit a1ec258
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# llm-claude-3
# llm-anthropic

[![PyPI](https://img.shields.io/pypi/v/llm-claude-3.svg)](https://pypi.org/project/llm-claude-3/)
[![Changelog](https://img.shields.io/github/v/release/simonw/llm-claude-3?include_prereleases&label=changelog)](https://github.com/simonw/llm-claude-3/releases)
[![Tests](https://github.com/simonw/llm-claude-3/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/llm-claude-3/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/llm-claude-3/blob/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/llm-anthropic.svg)](https://pypi.org/project/llm-anthropic/)
[![Changelog](https://img.shields.io/github/v/release/simonw/llm-anthropic?include_prereleases&label=changelog)](https://github.com/simonw/llm-anthropic/releases)
[![Tests](https://github.com/simonw/llm-anthropic/actions/workflows/test.yml/badge.svg)](https://github.com/simonw/llm-anthropic/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/llm-anthropic/blob/main/LICENSE)

LLM access to Claude 3 by Anthropic
LLM access to models by Anthropic, including the Claude series

## Installation

Install this plugin in the same environment as [LLM](https://llm.datasette.io/).
```bash
llm install llm-claude-3
llm install llm-anthropic
```

## Usage

First, set [an API key](https://console.anthropic.com/settings/keys) for Claude 3:
First, set [an API key](https://console.anthropic.com/settings/keys) for Anthropic:
```bash
llm keys set claude
llm keys set anthropic
# Paste key here
```

Expand All @@ -28,21 +28,29 @@ Run `llm models` to list the models, and `llm models --options` to include a lis

Run prompts like this:
```bash
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'
llm -m anthropic/claude-3.5-sonnet 'Fun facts about pelicans'
llm -m anthropic/claude-3.5-haiku 'Fun facts about armadillos'
llm -m anthropic/claude-3-opus 'Fun facts about squirrels'
```
Images are supported too, for models other than Claude 3.5 Haiku:
```bash
llm -m anthropic/claude-3.5-sonnet 'describe this image' -a https://static.simonwillison.net/static/2024/pelicans.jpg
llm -m anthropic/claude-3-haiku 'extract text' -a page.png
```
Images are supported too:
Claude 3.5 Sonnet can handle PDF files:
```bash
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
llm -m anthropic/claude-3.5-sonnet 'extract text' -a page.pdf
```
The plugin sets up `claude-3.5-sonnet` and similar as aliases, usable like this:
```bash
llm -m claude-3.5-sonnet 'Fun facts about pelicans'
```

## Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:
```bash
cd llm-claude-3
cd llm-anthropic
python3 -m venv venv
source venv/bin/activate
```
Expand Down
8 changes: 1 addition & 7 deletions llm_claude_3.py → llm_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,11 @@ def __init__(
self,
model_id,
claude_model_id=None,
extra_headers=None,
supports_images=True,
supports_pdf=False,
):
self.model_id = model_id
self.model_id = 'anthropic/' + model_id
self.claude_model_id = claude_model_id or model_id
self.extra_headers = extra_headers or {}
if supports_pdf:
self.extra_headers["anthropic-beta"] = "pdfs-2024-09-25"
self.attachment_types = set()
if supports_images:
self.attachment_types.update(
Expand Down Expand Up @@ -227,8 +223,6 @@ def build_kwargs(self, prompt, conversation):
if prompt.system:
kwargs["system"] = prompt.system

if self.extra_headers:
kwargs["extra_headers"] = self.extra_headers
return kwargs

def set_usage(self, response):
Expand Down
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "llm-claude-3"
name = "llm-anthropic"
version = "0.10"
description = "LLM access to Claude 3 by Anthropic"
description = "LLM access to models by Anthropic, including the Claude series"
readme = "README.md"
authors = [{name = "Simon Willison"}]
license = {text = "Apache-2.0"}
Expand All @@ -14,13 +14,13 @@ dependencies = [
]

[project.urls]
Homepage = "https://github.com/simonw/llm-claude-3"
Changelog = "https://github.com/simonw/llm-claude-3/releases"
Issues = "https://github.com/simonw/llm-claude-3/issues"
CI = "https://github.com/simonw/llm-claude-3/actions"
Homepage = "https://github.com/simonw/llm-anthropic"
Changelog = "https://github.com/simonw/llm-anthropic/releases"
Issues = "https://github.com/simonw/llm-anthropic/issues"
CI = "https://github.com/simonw/llm-anthropic/actions"

[project.entry-points.llm]
claude_3 = "llm_claude_3"
anthropic = "llm_anthropic"

[project.optional-dependencies]
test = ["pytest", "pytest-recording", "pytest-asyncio"]

0 comments on commit a1ec258

Please sign in to comment.