The Prem Python SDK is a Python library for interacting with [premai-saas](https://app.premai.io)
Project description
Table of Contents
Installation
From Source
-
Clone the Prem Python SDK repository:
git clone https://github.com/premAI-io/prem-python-sdk.git
-
Install the SDK
cd prem-python-sdk python -m venv venv source venv/bin/activate pip install .
From PyPI
You can also install the Prem Python SDK directly from PyPI.
python -m venv venv
source venv/bin/activate
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 prem import Prem
api_key = "YOUR_API_KEY"
base_url = "https://api.prem.com" # Update with the base URL of the Prem API
client = Prem(api_key=api_key, base_url=base_url)
Completions
The completions
module allows you to generate completions based on user input. Here's an example:
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
]
model = "gpt-3.5-turbo"
# Create completion
response = client.completions.create(project_id=1, messages=messages, model=model, stream=False)
print(response)
Embeddings
The embeddings
module enables you to create embeddings for given input. Example:
input_text = "What is a transformer?"
model = "text-embedding-ada-002"
# Create embeddings
response = client.embeddings.create(project_id=1, input=input_text, model=model)
print(response)
Data Points
The datapoints
module allows you to manage data points, including creating, updating, retrieving, and deleting. Example:
input_text = "What is a transformer?"
output_text = "A transformer is a deep learning model that uses self-attention."
# Create 10 data points
for _ in range(10):
data_point = client.datapoints.create(project_id=1, input=input_text, output=output_text, positive=True)
# Update the last data point
patched_data_point = client.datapoints.update(datapoint_id=data_point.id, data={"positive": False})
# Retrieve the updated data point
print(client.datapoints.retrieve(datapoint_id=data_point.id))
# Delete the updated data point
client.datapoints.delete(datapoint_id=data_point.id)
# List all data points
datapoints = client.datapoints.list(project_id=1)
print("Total number of datapoints:", len(datapoints))
for datapoint in datapoints:
print("Deleted data point with ID:", datapoint.id)
client.datapoints.delete(datapoint_id=datapoint.id)
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.