Skip to main content

A Python SDK for Prompt Studio

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

prompt_studio_python-0.1.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

prompt_studio_python-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file prompt_studio_python-0.1.0.tar.gz.

File metadata

  • Download URL: prompt_studio_python-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for prompt_studio_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ba8a5689c3768ef9216c692a8f0ef6fa61d954fc87da45e5fc2e32402db2aee
MD5 e23ef6c138b6f031db926425131815fb
BLAKE2b-256 f4c57a77ebb47147d6b3882b0a4e7b88cd1ac59eceede36491206acb88cb1557

See more details on using hashes here.

File details

Details for the file prompt_studio_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_studio_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7f7d7e477a6b44ac09795da24a2c26a5bcc256dfb8e3452a3c4c59517527aea
MD5 49112d842273a9e84c51db4e5eece25d
BLAKE2b-256 fa27200f1ec136cb6997406a80244a810f83174ddd818fb8dcf7041e8a5bcdd6

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