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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file anthropic_mock_wrapper-0.2.7.tar.gz
.
File metadata
- Download URL: anthropic_mock_wrapper-0.2.7.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1aa33f6c6264091c481bc4cf86bc9491a5cc3d40caf0532ef4c27d04c64d5586 |
|
MD5 | 3817aa3ee08210a843e7ba019a08fdcd |
|
BLAKE2b-256 | c154d1b7760ea91a2651b2da277a3e27a9555804b1059880e4d701e63be75ea7 |
File details
Details for the file anthropic_mock_wrapper-0.2.7-py3-none-any.whl
.
File metadata
- Download URL: anthropic_mock_wrapper-0.2.7-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64253feb5e121e5b6533ff40520c6c8c9b1b1bde932774bc545d514731302dcd |
|
MD5 | ef40a70096a703a3e6500bf243c6a7af |
|
BLAKE2b-256 | 150b26493f4498653a1648caf67e304166cca8e32049ecc935cf166626284ecc |