From a1ec25861b43e16790545d5cf0bf871b04f60b2f Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 17 Dec 2024 12:09:51 -0800 Subject: [PATCH] Rename plugin to llm-anthropic, refs #31 --- README.md | 40 +++++++++++++++++------------ llm_claude_3.py => llm_anthropic.py | 8 +----- pyproject.toml | 14 +++++----- 3 files changed, 32 insertions(+), 30 deletions(-) rename llm_claude_3.py => llm_anthropic.py (97%) diff --git a/README.md b/README.md index a5eab9b..99bbc13 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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 ``` diff --git a/llm_claude_3.py b/llm_anthropic.py similarity index 97% rename from llm_claude_3.py rename to llm_anthropic.py index ae1edc2..19d6cd4 100644 --- a/llm_claude_3.py +++ b/llm_anthropic.py @@ -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( @@ -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): diff --git a/pyproject.toml b/pyproject.toml index eb1b091..afb657d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"} @@ -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"]