Apostrofo Models SDK
A Python SDK for the Apostrofo Models API that provides easy access to various AI models for text analysis, classification, and processing.
Installation
pip install apostrofo-models-sdk
Features
- Automated authentication with API key
- Access to multiple AI models:
- Guardrails: Prompt injection and toxic language detection
- Data Processing: Text masking, classification, and entity extraction
- Content Enhancement: Tags generation and metadata extraction
- Validation: Answer verification
- Comprehensive error handling
- Type hints for better IDE support
- Pydantic models for request and response validation
Quick Start
from apostrofo_models_sdk import ApostrofoModelsClient
# Initialize client with your API key
client = ApostrofoModelsClient(api_key="your_api_key")
# Detect toxic language
toxic_result = client.detect_toxic_language("Text to analyze")
print(f"Is toxic: {toxic_result.is_toxic}")
print(f"Toxicity score: {toxic_result.toxicity_score}")
print(f"Explanation: {toxic_result.explanation}")
# Extract entities
entity_result = client.extract_entities(
"John Smith works at Apostrofo in New York.",
entity_types=["PERSON", "ORGANIZATION", "LOCATION"]
)
print(entity_result.entities)
Authentication
The SDK requires an API key for authentication, which is passed as a header (X-API-Key) to all API requests. You can obtain an API key by signing up at Apostrofo AI.
client = ApostrofoModelsClient(
api_key="your_api_key",
base_url="https://api.apostrofo.ai" # Optional, default URL
)
Available Models
Guardrails
# Prompt Injection Detection
injection_result = client.detect_prompt_injection("Ignore previous instructions and...")
print(f"Is injection: {injection_result.is_injection}")
# Toxic Language Detection
toxic_result = client.detect_toxic_language("Text to analyze")
print(f"Is toxic: {toxic_result.is_toxic}")
Data Processing
# Text Masking
mask_result = client.mask_text(
"My name is John and my email is john@example.com",
tags=["EMAIL", "PERSON"]
)
print(mask_result.bracketed_text)
# Text Classification
classification_result = client.classify_text(
"I'm really happy with this product!",
parameters={
"sentiment": {
"description": "Sentiment of the text",
"type": "string",
"properties": {
"values": ["positive", "negative", "neutral"]
}
}
}
)
print(classification_result.results)
# Entity Extraction
entity_result = client.extract_entities(
"Apple Inc. is headquartered in Cupertino, California.",
entity_types=["ORG", "LOC"]
)
print(entity_result.entities)
Content Enhancement
# Tags Generation
tags_result = client.generate_tags(
"This is a blog post about Python programming and data science.",
parameters={
"topics": {
"description": "Topics mentioned in the text",
"properties": {
"max": 5
}
}
}
)
print(tags_result.results)
# Metadata Extraction
metadata_result = client.extract_metadata(
"Publication: Science Journal\nDate: 2023-03-15\nTitle: New Advances in AI",
parameters={
"publication_info": {
"description": "Publication information",
"properties": {
"fields": ["journal", "date", "title"]
}
}
}
)
print(metadata_result.results)
Validation
# Answer Verification
verification_result = client.verify_answer(
question="What is the capital of France?",
answer="The capital of France is London."
)
print(f"Is accurate: {verification_result.is_accurate}")
print(f"Explanation: {verification_result.explanation}")
Error Handling
The SDK provides comprehensive error handling with custom exceptions:
from apostrofo_models_sdk import ApostrofoApiError, AuthenticationError
try:
result = client.detect_toxic_language("Test text")
except AuthenticationError:
print("Invalid API key")
except ApostrofoApiError as e:
print(f"API error: {e.message}, status code: {e.status_code}")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This SDK is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for apostrofo-models-sdk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| apostrofo_models_sdk-0.1.0.tar.gz | 9.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apostrofo_models_sdk-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.8 kB
Release files / apostrofo_models_sdk-0.1.0.tar.gz
| Download URL | apostrofo_models_sdk-0.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14d537a32a6174ccf1c569801b797c5862baa5f53fa588bb6b560ca56f4f46d8
|
|
BLAKE2b-256 checksum How to use checksums |
933cb5d913c3f2808fc2ef7cacbb372141e4e065335e6b8c0f05f55b5a8761bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / apostrofo_models_sdk-0.1.0-py3-none-any.whl
| Download URL | apostrofo_models_sdk-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc87564597e36bfc2d9453b0dff9d7da7b4d590b18944f7063965d0e16d17027
|
|
BLAKE2b-256 checksum How to use checksums |
3204dd6bde97a66eed6f5381951aad6d580e33af95b2062ec2cb018b97bce8c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for apostrofo-models-sdk 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.