Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.17.0 #345

Merged
merged 14 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

USER vscode

RUN curl -sSf https://rye-up.com/get | RYE_VERSION="0.15.2" RYE_INSTALL_OPTION="--yes" bash
RUN curl -sSf https://rye-up.com/get | RYE_VERSION="0.24.0" RYE_INSTALL_OPTION="--yes" bash
ENV PATH=/home/vscode/.rye/shims:$PATH

RUN echo "[[ -d .venv ]] && source .venv/bin/activate" >> /home/vscode/.bashrc
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
if: github.repository == 'anthropics/anthropic-sdk-python'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Rye
run: |
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: 0.15.2
RYE_VERSION: 0.24.0
RYE_INSTALL_OPTION: "--yes"

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: 0.15.2
RYE_VERSION: 0.24.0
RYE_INSTALL_OPTION: "--yes"

- name: Publish to PyPI
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: 0.15.2
RYE_VERSION: 0.24.0
RYE_INSTALL_OPTION: "--yes"

- name: Publish to PyPI
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.16.0"
".": "0.17.0"
}
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Changelog

## 0.17.0 (2024-03-04)

Full Changelog: [v0.16.0...v0.17.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.16.0...v0.17.0)

### Features

* **messages:** add support for image inputs ([#359](https://github.com/anthropics/anthropic-sdk-python/issues/359)) ([579f013](https://github.com/anthropics/anthropic-sdk-python/commit/579f013dd294f34b3c44e2b331a4aa25b6cdfd6a))


### Chores

* **client:** use anyio.sleep instead of asyncio.sleep ([#351](https://github.com/anthropics/anthropic-sdk-python/issues/351)) ([2778a22](https://github.com/anthropics/anthropic-sdk-python/commit/2778a2228e82704dde9176d970274e806422c02b))
* **docs:** mention install from git repo ([#356](https://github.com/anthropics/anthropic-sdk-python/issues/356)) ([9d503ba](https://github.com/anthropics/anthropic-sdk-python/commit/9d503ba9cc462e33166594ca19f666819a3a5a87))
* **docs:** remove references to old bedrock package ([#344](https://github.com/anthropics/anthropic-sdk-python/issues/344)) ([3323883](https://github.com/anthropics/anthropic-sdk-python/commit/3323883750b9d61fa084cadc99519b2f6cf8d39c))
* **internal:** bump pyright ([#350](https://github.com/anthropics/anthropic-sdk-python/issues/350)) ([ee0161c](https://github.com/anthropics/anthropic-sdk-python/commit/ee0161c2d7d2fefd06ee5b1001131cd6d6d236d7))
* **internal:** bump rye to v0.24.0 ([#348](https://github.com/anthropics/anthropic-sdk-python/issues/348)) ([be8597b](https://github.com/anthropics/anthropic-sdk-python/commit/be8597b33c2f2f6e8b9ae77738f4c898e48c8e91))
* **internal:** improve bedrock streaming setup ([#354](https://github.com/anthropics/anthropic-sdk-python/issues/354)) ([2b55c68](https://github.com/anthropics/anthropic-sdk-python/commit/2b55c688514e4b13abce547362f0c0a3e7f0e97f))
* **internal:** refactor release environment script ([#347](https://github.com/anthropics/anthropic-sdk-python/issues/347)) ([a87443a](https://github.com/anthropics/anthropic-sdk-python/commit/a87443a90374aedaac80451f61046c6f1aefeaa9))
* **internal:** split up transforms into sync / async ([#357](https://github.com/anthropics/anthropic-sdk-python/issues/357)) ([f55ee71](https://github.com/anthropics/anthropic-sdk-python/commit/f55ee71b0b517f3e605bfd7a4aa948a9c2fc6552))
* **internal:** support more input types ([#358](https://github.com/anthropics/anthropic-sdk-python/issues/358)) ([35b0347](https://github.com/anthropics/anthropic-sdk-python/commit/35b0347bfddecc94fc8ac09b42ff3d96f4523bf8))
* **internal:** update deps ([#349](https://github.com/anthropics/anthropic-sdk-python/issues/349)) ([ab82b2d](https://github.com/anthropics/anthropic-sdk-python/commit/ab82b2d7ce16f3fed4b20e60f0c8e7981c22c191))


### Documentation

* **contributing:** improve wording ([#355](https://github.com/anthropics/anthropic-sdk-python/issues/355)) ([f9093a0](https://github.com/anthropics/anthropic-sdk-python/commit/f9093a0ee8d590185f572749d58280f7eda5ed8b))


### Refactors

* **api:** mark completions API as legacy ([#346](https://github.com/anthropics/anthropic-sdk-python/issues/346)) ([2bb25a1](https://github.com/anthropics/anthropic-sdk-python/commit/2bb25a12509b87557f3da2125ab955b60e32713f))

## 0.16.0 (2024-02-13)

Full Changelog: [v0.15.1...v0.16.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.15.1...v0.16.0)
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```bash
pip install git+ssh://[email protected]:anthropics/anthropic-sdk-python.git
pip install git+ssh://[email protected]/anthropics/anthropic-sdk-python.git
```

Alternatively, you can build from source and install the wheel file:
Expand All @@ -82,7 +82,7 @@ pip install ./path-to-wheel-file.whl

## Running tests

Most tests will require you to [setup a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```bash
# you will need npm installed
Expand Down Expand Up @@ -117,7 +117,7 @@ the changes aren't made through the automated pipeline, you may want to make rel

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/anthropics/anthropic-sdk-python/actions/workflows/publish-pypi.yml). This will require a setup organization or repository secret to be set up.
You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/anthropics/anthropic-sdk-python/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

Expand Down
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ The Anthropic Python library provides convenient access to the Anthropic REST AP
application. It includes type definitions for all request params and response fields,
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).

For the AWS Bedrock API, see [`anthropic-bedrock`](https://github.com/anthropics/anthropic-bedrock-python).

## Documentation

The REST API documentation can be found [on docs.anthropic.com](https://docs.anthropic.com/claude/reference/). The full API of this library can be found in [api.md](api.md).

## Installation

```sh
# install from PyPI
pip install anthropic
```

Expand All @@ -36,10 +35,10 @@ message = client.messages.create(
messages=[
{
"role": "user",
"content": "How does a court case get to the supreme court?",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
print(message.content)
```
Expand Down Expand Up @@ -70,10 +69,10 @@ async def main() -> None:
messages=[
{
"role": "user",
"content": "How does a court case get to the supreme court?",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
print(message.content)

Expand All @@ -97,10 +96,10 @@ stream = client.messages.create(
messages=[
{
"role": "user",
"content": "your prompt here",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
stream=True,
)
for event in stream:
Expand All @@ -119,10 +118,10 @@ stream = await client.messages.create(
messages=[
{
"role": "user",
"content": "your prompt here",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
stream=True,
)
async for event in stream:
Expand All @@ -148,7 +147,7 @@ async def main() -> None:
"content": "Say hello there!",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
) as stream:
async for text in stream.text_stream:
print(text, end="", flush=True)
Expand Down Expand Up @@ -191,11 +190,12 @@ For a more fully fledged example see [`examples/bedrock.py`](https://github.com/

## Token counting

You can estimate billing for a given request with the `client.count_tokens()` method, eg:
You can see the exact usage for a given request through the `usage` response property, e.g.

```py
client = Anthropic()
client.count_tokens('Hello world!') # 3
message = client.messages.create(...)
message.usage
# Usage(input_tokens=25, output_tokens=13)
```

## Using types
Expand Down Expand Up @@ -228,10 +228,10 @@ try:
messages=[
{
"role": "user",
"content": "your prompt here",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
except anthropic.APIConnectionError as e:
print("The server could not be reached")
Expand Down Expand Up @@ -280,10 +280,10 @@ client.with_options(max_retries=5).messages.create(
messages=[
{
"role": "user",
"content": "Can you help me effectively ask for a raise at work?",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
```

Expand Down Expand Up @@ -312,10 +312,10 @@ client.with_options(timeout=5 * 1000).messages.create(
messages=[
{
"role": "user",
"content": "Where can I get a good coffee in my neighbourhood?",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
```

Expand Down Expand Up @@ -375,9 +375,9 @@ response = client.messages.with_raw_response.create(
max_tokens=1024,
messages=[{
"role": "user",
"content": "Where can I get a good coffee in my neighbourhood?",
"content": "Hello, Claude",
}],
model="claude-2.1",
model="claude-3-opus-20240229",
)
print(response.headers.get('X-My-Header'))

Expand Down Expand Up @@ -408,10 +408,10 @@ with client.messages.with_streaming_response.create(
messages=[
{
"role": "user",
"content": "Where can I get a good coffee in my neighbourhood?",
"content": "Hello, Claude",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
) as response:
print(response.headers.get("X-My-Header"))

Expand Down
19 changes: 1 addition & 18 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
# Anthropic

Methods:

- <code>client.<a href="./src/anthropic/_client.py">count_tokens</a>(\*args) -> int</code>

# Completions

Types:

```python
from anthropic.types import Completion
```

Methods:

- <code title="post /v1/complete">client.completions.<a href="./src/anthropic/resources/completions.py">create</a>(\*\*<a href="src/anthropic/types/completion_create_params.py">params</a>) -> <a href="./src/anthropic/types/completion.py">Completion</a></code>

# Messages

Types:
Expand All @@ -26,6 +8,7 @@ from anthropic.types import (
ContentBlockDeltaEvent,
ContentBlockStartEvent,
ContentBlockStopEvent,
ImageBlockParam,
Message,
MessageDeltaEvent,
MessageDeltaUsage,
Expand Down
4 changes: 2 additions & 2 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ if [ -z "${PYPI_TOKEN}" ]; then
errors+=("The ANTHROPIC_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
fi

len=${#errors[@]}
lenErrors=${#errors[@]}

if [[ len -gt 0 ]]; then
if [[ lenErrors -gt 0 ]]; then
echo -e "Found the following errors in the release environment:\n"

for error in "${errors[@]}"; do
Expand Down
30 changes: 30 additions & 0 deletions examples/images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path

from anthropic import Anthropic

client = Anthropic()

response = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Hello!",
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": Path(__file__).parent.joinpath("logo.png"),
},
},
],
},
],
model="claude-3-opus-20240229",
)
print(response.model_dump_json(indent=2))
Binary file added examples/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"content": "Hello!",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
print(response)

Expand All @@ -30,6 +30,6 @@
"content": "How are you?",
},
],
model="claude-2.1",
model="claude-3-opus-20240229",
)
print(response2)
2 changes: 1 addition & 1 deletion examples/messages_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def main() -> None:
"content": "Say hello there!",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
) as stream:
async for text in stream.text_stream:
print(text, end="", flush=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/messages_stream_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def main() -> None:
"content": "Say hello there!",
}
],
model="claude-2.1",
model="claude-3-opus-20240229",
event_handler=MyStream,
) as stream:
accumulated = await stream.get_final_message()
Expand Down
Loading