Python SDK for PromptStudio
Project description
PromptStudio Python SDK
A Python SDK for interacting with PromptStudio's API, providing seamless integration with various AI models including OpenAI, Google's Gemini, and Anthropic's Claude.
Installation
You can install the PromptStudio SDK using pip:
pip install promptstudio-sdk
Or using poetry:
poetry add promptstudio-sdk
Features
- Support for multiple AI platforms (OpenAI, Gemini, Claude)
- Local model integration with bypass mode
- Multiple memory management strategies
- Built-in caching system
- Async/await support
- Type safety with Pydantic
- Support for text and file inputs
- Conversation summarization
Quick Start
Here's a simple example to get you started:
import asyncio
from promptstudio import PromptManager
from promptstudio.prompt.types import MessageType, Memory, MessageContent
async def main():
# Initialize the SDK
prompt_manager = PromptManager(
api_key="your_api_key_here",
env="test" # or "prod" for production
)
# Create a request
request = {
"user_message": [
{
"type": "text",
"text": "What is artificial intelligence?"
}
],
"memory_type": "summarizedMemory",
"window_size": 10,
"session_id": "test_session",
"variables": {},
"version": 1.0
}
try:
response = await prompt_manager.chat_with_prompt(
"your_prompt_id_here",
request
)
print(response)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(main())
Advanced Usage
Using Bypass Mode
Bypass mode allows direct interaction with AI models:
prompt_manager = PromptManager(
api_key="your_api_key_here",
env="test",
bypass=True # Enable local model integration
)
Memory Types
The SDK supports three types of memory management:
- Full Memory
request = {
"memory_type": "fullMemory",
"window_size": -1,
# ... other parameters
}
- Window Memory
request = {
"memory_type": "windowMemory",
"window_size": 10,
# ... other parameters
}
- Summarized Memory
request = {
"memory_type": "summarizedMemory",
"window_size": 12,
# ... other parameters
}
Working with Files
You can include files (images) in your messages:
request = {
"user_message": [
{
"type": "text",
"text": "Describe this image"
},
{
"type": "file",
"file_url": {
"url": "https://example.com/image.jpg"
}
}
],
# ... other parameters
}
Configuration
Environment Variables
You can set these environment variables:
PROMPTSTUDIO_API_KEY=your_api_key
PROMPTSTUDIO_ENV=test # or prod
Development Setup
For development, install with extra dependencies:
pip install "promptstudio-sdk[dev]"
This includes:
- pytest for testing
- black for formatting
- mypy for type checking
- flake8 for linting
API Reference
PromptManager
Main class for interacting with PromptStudio:
class PromptManager:
def __init__(
self,
api_key: str,
env: str = "prod",
bypass: bool = False
)
async def chat_with_prompt(
self,
prompt_id: str,
request: RequestPayload
) -> Dict[str, Any]
Types
from promptstudio.prompt.types import (
MessageType,
Memory,
MessageContent,
RequestPayload
)
Error Handling
The SDK uses FastAPI's HTTPException for error handling:
try:
response = await prompt_manager.chat_with_prompt(prompt_id, request)
except HTTPException as e:
print(f"HTTP Error {e.status_code}: {e.detail}")
except Exception as e:
print(f"Error: {str(e)}")
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support, email support@promptstudio.dev or open an issue on GitHub.
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 promptstudio_sdk_python-1.0.0.tar.gz
.
File metadata
- Download URL: promptstudio_sdk_python-1.0.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2485f4873bed965fad3057cef52d6c3a07cbe603a472aeff9ad52052eb04186 |
|
MD5 | 6b41529c4bcca54317a8fad2ed3e4379 |
|
BLAKE2b-256 | 8c9983cd2ec11d8328016436549fd8cbe857d4797e6b99f57298d981aa4f95b2 |
File details
Details for the file promptstudio_sdk_python-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: promptstudio_sdk_python-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea88453de9a3a3c1e9cf817f8fa5d6894ef472d6d4fc2fa25ce0ccf698dee998 |
|
MD5 | 5724f51fff0cf056ae4f98b6ec95f664 |
|
BLAKE2b-256 | 63f0001e586495e2769f3d6bfd7bac991d131afc377726975ca7e05079ce7ccf |