Skip to main content

A client library for accessing Prem APIs

Project description

Prem Python SDK

Installation

You can install the Prem Python SDK directly from PyPI.

pip install premai

Usage

Getting Started

To use the Prem Python SDK, you need to obtain an API key from the Prem platform. You can then create a Prem instance to make requests to the API.

from premai import Prem

client = Prem(
    api_key=YOUR_API_KEY
)

Chat completion

The chat.completions module allows you to generate completions based on user input. Here's an example:

messages = [
    {"role": "user", "content": "Who won the world series in 2020?"},
]
model = "gpt-3.5-turbo" # optional
system_prompt = "You are a helpful assistant." # optional
session_id = "my-session" # optional: a unique identifier to maintain session context, useful for tracking conversations or data across multiple requests
project_id = PROJECT_ID

# Create completion
response = client.chat.completions.create(
    project_id=project_id,
    messages=messages,
    model=model,
    session_id=session_id,
    system_prompt=system_prompt,
    stream=False
)

print(response.choices)

# Create completion with stream
response = client.chat.completions.create(
    project_id=project_id,
    messages=messages,
    model=model,
    session_id=session_id,
    system_prompt=system_prompt,
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta["content"]:
        print(chunk.choices[0].delta["content"], end="")

print(f"\nTrace ID: {response.trace_id}")

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

premai-0.3.19.tar.gz (24.4 kB view hashes)

Uploaded Source

Built Distribution

premai-0.3.19-py3-none-any.whl (65.4 kB view hashes)

Uploaded Python 3

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