Official SDK for BReact OS
Project description
BReact SDK
A Python SDK for interacting with BReact's AI services, supporting both synchronous and asynchronous operations.
Installation
pip install breact-sdk
Configuration
The SDK can be configured using environment variables or programmatically:
Environment Variables
Create a .env file in your project root:
BREACT_API_KEY=your_api_key
BREACT_BASE_URL=https://api-os.breact.ai # Optional, defaults to this URL
Programmatic Configuration
from breactsdk.client import create_client
# Create client with custom configuration
client = create_client(
api_key="your_api_key", # If not provided, the SDK will use the one from the environment variable
base_url="https://api-os.breact.ai" # Optional
)
Usage Examples
Text Summarization
from breactsdk.client import create_client
# Async usage
async with create_client(async_client=True) as client:
summary = await client.aisummary.summarize(
text="Your text to summarize",
summary_type="executive",
model_id="mistral-small",
options={
"temperature": 0.7,
"max_tokens": 500
}
)
# Sync usage
with create_client() as client:
summary = client.aisummary.summarize(
text="Your text to summarize",
summary_type="executive",
model_id="mistral-small"
)
Email Analysis and Response Generation
async with create_client(async_client=True) as client:
# Analyze email thread
analysis = await client.email_response.analyze_thread(
email_thread=[{
"sender": "client@example.com",
"recipient": "support@company.com",
"subject": "Urgent: Service Downtime",
"content": "Email content here",
"timestamp": "2024-01-20T09:00:00Z"
}],
analysis_type=["sentiment", "key_points", "action_items", "response_urgency"]
)
# Generate email response
response = await client.email_response.generate_response(
email_thread=[{
"sender": "client@example.com",
"recipient": "support@company.com",
"subject": "Product Feature Inquiry",
"content": "Email content here",
"timestamp": "2024-01-20T10:30:00Z"
}],
tone="friendly",
style_guide={
"language": "en",
"max_length": 150,
"greeting_style": "casual",
"signature": "\nBest regards,\nSupport Team"
},
key_points=[
"Address AI capabilities",
"Explain pricing plans",
"Highlight support options"
]
)
Information Tracking
# Define your schema
schema = {
"type": "object",
"properties": {
"primary_symptom": {
"type": "string",
"enum": ["headache", "nausea", "dizziness"]
},
"duration": {
"type": "string"
}
},
"required": ["primary_symptom", "duration"]
}
# Process information
async with create_client(async_client=True) as client:
result = await client.information_tracker.process(
content="Your text content",
context={
"updateType": "medical_symptoms",
"currentInfo": {
"previous_symptoms": ["mild headache"]
}
},
config={
"modelId": "mistral-large-2411",
"temperature": 0.1,
"maxTokens": 2000,
"schema": schema
}
)
Concurrent Processing
async with create_client(async_client=True) as client:
tasks = [
client.aisummary.summarize(
text=f"Text {i}",
summary_type="executive",
model_id="mistral-small"
) for i in range(3)
]
results = await asyncio.gather(*tasks)
Error Handling
The SDK provides detailed error information:
try:
result = await client.aisummary.summarize(text="Your text")
except Exception as e:
if hasattr(e, 'response'):
print(f"Status code: {e.response.status_code}")
print(f"Error details: {e.response.text}")
print(f"Error: {str(e)}")
Available Services
-
AI Summary (
client.aisummary)summarize: Generate text summaries
-
Email Response (
client.email_response)analyze_thread: Analyze email threadsgenerate_response: Generate email responses
-
Information Tracker (
client.information_tracker)process: Extract structured information from text
Best Practices
- Always use context managers (
withorasync with) to ensure proper resource cleanup - Choose between sync and async clients based on your application's needs
- Set appropriate timeouts and model parameters for your use case
- Handle errors appropriately in production code
- Store API keys securely using environment variables
Running the Demo
A comprehensive demo script is included that showcases all features:
python demo.py
Support
For issues and feature requests, please contact office@breact.ai
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file breactsdk-0.1.1.tar.gz.
File metadata
- Download URL: breactsdk-0.1.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b367e793211758b13d36ab9c3c616988ad8a3eac1e7d2ea5ece994f15b47df39
|
|
| MD5 |
455695efe05050a3e9de2e536fc5b8f3
|
|
| BLAKE2b-256 |
28aaa5693336e2b10b1f519dd976b3de09428991d940686287dd3f204fde8866
|
File details
Details for the file breactsdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: breactsdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
464ad20af3908370fd8daeec4d9ecbbe06a53b99ebade617d7bf74819c3192c0
|
|
| MD5 |
f0d3de383c482a42b0d84c82590f8568
|
|
| BLAKE2b-256 |
937e41b245ecf18d78608a7a56f0f3731444b034b77d4f980c482a2a10785864
|