A Python SDK for PromptStudio
Project description
PromptStudio Python SDK
A Python SDK for interacting with PromptStudio API and AI platforms directly.
Installation
From PyPI (Coming Soon)
pip install promptstudio-sdk
From Source
git clone https://github.com/your-repo/promptstudio-sdk.git
cd promptstudio-sdk
pip install -e .
Development Setup
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
# On Windows
venv\Scripts\activate
# On Unix or MacOS
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
Usage
Initializing the SDK
from promptstudio_sdk import PromptStudio
client = PromptStudio({
'api_key': 'YOUR_API_KEY',
'env': 'test' # Use 'prod' for production environment
})
Getting All Prompts
# Get all prompts from a specific folder
prompts = client.get_all_prompts("your_folder_id")
print(prompts)
Chatting with a Prompt
response = client.chat_with_prompt(
prompt_id="your_prompt_id",
user_message=[
{
"type": "text",
"text": "Hello, how are you?"
}
],
memory_type="fullMemory",
window_size=10,
session_id="test_session",
variables={}
)
print(response)
Complete Example
from promptstudio_sdk import PromptStudio
def main():
# Initialize the client
client = PromptStudio({
'api_key': 'YOUR_API_KEY',
'env': 'test'
})
try:
# Get all prompts
prompts = client.get_all_prompts("your_folder_id")
print("Available prompts:", prompts)
# Chat with a specific prompt
response = client.chat_with_prompt(
prompt_id="your_prompt_id",
user_message=[
{
"type": "text",
"text": "Hello, how are you?"
}
],
memory_type="windowMemory",
window_size=10,
session_id="test_session",
variables={}
)
print("Chat response:", response)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()
Testing
Setting Up Tests
- Install test dependencies:
pip install pytest pytest-cov
- Create a
.env
file in the root directory with your test credentials:
PROMPTSTUDIO_API_KEY=your_test_api_key
PROMPTSTUDIO_ENV=test
Running Tests
Run all tests:
pytest
Run tests with coverage:
pytest --cov=promptstudio_sdk
Writing Tests
Create test files in the tests
directory. Here's an example test:
import pytest
from promptstudio_sdk import PromptStudio
def test_chat_with_prompt():
client = PromptStudio({
'api_key': 'test_api_key',
'env': 'test'
})
response = client.chat_with_prompt(
prompt_id="test_prompt",
user_message=[{"type": "text", "text": "Hello"}],
memory_type="fullMemory",
window_size=10,
session_id="test_session",
variables={}
)
assert isinstance(response, dict)
assert 'response' in response
Type Hints
The SDK uses Python type hints for better IDE support and code documentation. Here are some key types:
from typing import Dict, List, Union, Optional
# Message types
ImageMessage = Dict[str, Union[str, Dict[str, str]]] # {"type": "image_url", "image_url": {"url": "..."}}
TextMessage = Dict[str, str] # {"type": "text", "text": "..."}
UserMessage = List[Union[ImageMessage, TextMessage]]
# Memory types
Memory = Literal["fullMemory", "windowMemory", "summarizedMemory"]
# Request payload
RequestPayload = Dict[str, Union[UserMessage, Memory, int, str, Dict[str, str], Optional[int]]]
Error Handling
The SDK raises exceptions for various error cases:
from promptstudio_sdk import PromptStudio
try:
client = PromptStudio({
'api_key': 'YOUR_API_KEY',
'env': 'test'
})
response = client.chat_with_prompt(...)
except requests.exceptions.HTTPError as e:
print(f"HTTP error occurred: {e}")
except requests.exceptions.RequestException as e:
print(f"Network error occurred: {e}")
except Exception as e:
print(f"An error occurred: {e}")
Contributing
- Fork the repository
- Create a new branch for your feature
- Make your changes
- Run the tests to ensure everything works
- Submit a pull request
License
This SDK is released under the MIT License.
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
promptstudio_sdk-1.0.79.tar.gz
(23.5 kB
view details)
Built Distribution
File details
Details for the file promptstudio_sdk-1.0.79.tar.gz
.
File metadata
- Download URL: promptstudio_sdk-1.0.79.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4caeb4d965469a6489b6e131b94549994f7ee0a5f93b0b9f14ce6afae294b00 |
|
MD5 | 5fc506d30e44aa9063844d8c3fcf6474 |
|
BLAKE2b-256 | e9c8392ea3c97785d2c84cf8410523e2e106bcff4da9b2f2fbf894c0a391e6fd |
File details
Details for the file promptstudio_sdk-1.0.79-py3-none-any.whl
.
File metadata
- Download URL: promptstudio_sdk-1.0.79-py3-none-any.whl
- Upload date:
- Size: 25.3 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 | 46c89563b01adbf486d8f98a99b7e6a2112affc1e83255a651267574531faf2f |
|
MD5 | 0f7f341850b1c1498fbc3591596a7a79 |
|
BLAKE2b-256 | 034954999239136e9e2ae2db5c7bc6520035f22e473662bdb0dfda36c2698928 |