Skip to main content

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:

  1. Full Memory
request = {
    "memory_type": "fullMemory",
    "window_size": -1,
    # ... other parameters
}
  1. Window Memory
request = {
    "memory_type": "windowMemory",
    "window_size": 10,
    # ... other parameters
}
  1. 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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


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_python-1.0.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

promptstudio_sdk_python-1.0.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file promptstudio_sdk_python-1.0.0.tar.gz.

File metadata

File hashes

Hashes for promptstudio_sdk_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b2485f4873bed965fad3057cef52d6c3a07cbe603a472aeff9ad52052eb04186
MD5 6b41529c4bcca54317a8fad2ed3e4379
BLAKE2b-256 8c9983cd2ec11d8328016436549fd8cbe857d4797e6b99f57298d981aa4f95b2

See more details on using hashes here.

File details

Details for the file promptstudio_sdk_python-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for promptstudio_sdk_python-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea88453de9a3a3c1e9cf817f8fa5d6894ef472d6d4fc2fa25ce0ccf698dee998
MD5 5724f51fff0cf056ae4f98b6ec95f664
BLAKE2b-256 63f0001e586495e2769f3d6bfd7bac991d131afc377726975ca7e05079ce7ccf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page