From d6d56dc26ed7a44917fb4d2627d1c651c28bfb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Louf?= Date: Mon, 2 Dec 2024 11:26:01 +0100 Subject: [PATCH] Update the documentation for the Anthropic integration --- docs/reference/models/anthropic.md | 45 ++++++++++++++++++++++++++++++ pyproject.toml | 1 + 2 files changed, 46 insertions(+) create mode 100644 docs/reference/models/anthropic.md diff --git a/docs/reference/models/anthropic.md b/docs/reference/models/anthropic.md new file mode 100644 index 000000000..ffc510f43 --- /dev/null +++ b/docs/reference/models/anthropic.md @@ -0,0 +1,45 @@ +# Anthropic + +!!! Installation + + You need to install the `anthropic` library to be able to use the Anthropic API in Outlines. Or alternatively you can run: + + ```bash + pip install "outlines[anthropic]" + ``` + +## Anthropic models + +Outlines supports models available via the Anthropic API, e.g. Claude 3.5 Haiku or Claude 3.5 Sonner. You can initialize the model by passing the model name to `outlines.models.Anthropic`: + +```python +from outlines import models + +model = models.Anthropic("claude-3-5-haiku-latest") +model = models.Anthropic("claude-3-5-sonnet-latest") +``` + +Check the [Anthropic documentation](https://docs.anthropic.com/en/docs/about-claude/models) for an up-to-date list of available models. You can pass any paramater you would pass to the Anthropic SDK as keyword arguments: + +```python +model = models.Anthropic( + "claude-3.5-haiku-latest", + api_key="" +) +``` + +## Text generation + +To generate text using an Anthropic model you need to build a `Generator` object, possibly with the desired output type. You can then call the model by calling the `Generator`. The method accepts every argument that you could pass to the `client.completions.create` function, as keyword arguments: + +```python +from outlines import models, Generator + +model = models.Anthropic("claude-3-5-haiku-latest") +generator = Generator(model) +result = generator("Prompt", max_tokens=1024) +``` + +See the [Anthropic SDK documentation](https://github.com/anthropics/anthropic-sdk-python/blob/main/src/anthropic/resources/messages.py) for the list of available arguments. + +The Anthropic API currently does not support structured generation. diff --git a/pyproject.toml b/pyproject.toml index 88d6b7e12..a1650d58f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ vllm = ["vllm", "transformers", "numpy2"] transformers = ["transformers", "accelerate", "datasets", "numpy<2"] mlxlm = ["mlx-lm", "datasets"] openai = ["openai"] +anthropic = ["anthropic"] gemini = ["google-generativeai"] llamacpp = ["llama-cpp-python", "transformers", "datasets", "numpy<2"] exllamav2 = ["exllamav2"]