Skip to main content

A lightweight wrapper around the Anthropic Python client for testing purposes

Project description

anthropic_mock_wrapper

A lightweight wrapper around the Anthropic Python client for testing purposes.

Save money on your Anthropic API usage by mocking responses when your API key is prefixed with TEST_.

Installation

You can install the anthropic_mock_wrapper package using pip:

pip install anthropic_mock_wrapper
from anthropic_mock_wrapper import AnthropicMockWrapper

Initialize the client

client = AnthropicMockWrapper(api_key="TEST_your_api_key_here")

Use the client to interact with Anthropic's API

response = client.complete(
prompt="Hello, world!",
model="claude-2",
max_tokens_to_sample=100
)
print(response)
from anthropic_mock_wrapper import AnthropicMockWrapper
# Initialize the testable client
testable_client = AnthropicMockWrapper(api_key="test_key")
#Set a mock response
testable_client.set_mock_response({
"completion": "This is a mock response",
"stop_reason": "stop_sequence",
"model": "claude-2"
})
# Use the client in your tests
response = testable_client.complete(
prompt="Test prompt",
model="claude-2",
max_tokens_to_sample=100
)
assert response["completion"] == "This is a mock response"

Build

python -m build

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is an unofficial Mocker and is not affiliated with or endorsed by Anthropic. Use at your own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anthropic_mock_wrapper-0.2.4.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

anthropic_mock_wrapper-0.2.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file anthropic_mock_wrapper-0.2.4.tar.gz.

File metadata

File hashes

Hashes for anthropic_mock_wrapper-0.2.4.tar.gz
Algorithm Hash digest
SHA256 6321d7f9f6ac764f1edd9e0a803ad0e56df8c458eaf463150a9497285e067070
MD5 8da2c3ae47f43857fa6c671fe3cdb929
BLAKE2b-256 7c9468f66b4d5bd3028aea6f6d1d06fb6cb5f8d7057f8e5e92184ad260bb1e26

See more details on using hashes here.

File details

Details for the file anthropic_mock_wrapper-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for anthropic_mock_wrapper-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d94c38666a4171641e5bfb20e74229602f75100951671b284b9f93b6eafa4ee5
MD5 b7f63dd6adebb2aa69885f3ab5bc4678
BLAKE2b-256 9b43b12159632e65e6cbf2ea08e4dab6cc1f2c270e75f3b68e80f44dfbbd95a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page