Skip to Content
PurAI is SHUT DOWN. This website is purely for archival purposes. No such services exist anymore.

purai.py Methods

Testing

test()

Test the API by recieving a test message. The AI will respond and tell a funny joke if it is online.

Returns

  • (dict or str): If in development mode (dev=True), returns the full JSON response or an error message. Otherwise, returns the AI’s response or an error message.

Generate

generate(prompt, provider="openai", beta=False)

Generate individual text based on a prompt.

API Reference

  • prompt Required (str): The text prompt for the AI.
  • provider Optional (str): The provider for text generation (default is “openai”).
  • beta Optional (bool): Whether to use the beta version (default is False).

Code sample

main.py
import purai ai = purai.PurAI(token, dev = False) print(ai.generate("hi!"))

Chat

chat(messages, provider="openai", beta=False)

Engage in a chat conversation with AI.

API Reference

  • messages Required (list): List of message objects for the conversation. (Same formatting as with OpenAI’s package!)
  • provider Optional (str): The provider for chat completion (default is “openai”).
  • beta Optional (bool): Whether to use the beta version (default is False).

Code sample

main.py
import purai ai = purai.PurAI(token, dev = False) messages = { "role": "user", "content": "Hello! How are you?" } print(ai.chat(messages))

Content Moderation

moderations(prompt, beta=False)

Perform content moderation on text and analyze its safety.

API Reference

  • prompt Required (str): The text to be moderated.
  • beta Optional (bool): Whether to use the beta version (default is False).

Code sample

main.py
import purai ai = purai.PurAI(token, dev = False) print(ai.moderations(prompt = "You are a terrible person."))

Image Generation

image(prompt, provider="openai", beta=False)

Generate images based on a text prompt.

API Reference

  • prompt Required (str): The text prompt for image generation.
  • provider Optional (str): The provider for image generation (default is “openai”).
  • beta Optional (bool): Whether to use the beta version (default is False).

Code sample

main.py
import purai ai = purai.PurAI(token, dev = False) print(ai.image("A yellow duck walking around the street with a bird as a pet"))

Audio Transcription

transcribe(file_url, beta=False)

Transcribe an audio file from its URL.

API Reference

  • file_url Required (str): The URL of the audio file.
  • beta Optional (bool): Whether to use the beta version (default is False).

Code sample

main.py
import purai ai = purai.PurAI(token, dev = False) print(ai.transcribe("https://some.audio/file.mp3"))

Audio Translation

translate(file_url, beta=False)

Translate an audio file from its URL.

API Reference

  • file_url Required (str): The URL of the audio file.
  • beta Optional (bool): Whether to use the beta version (default is False).

Code sample

main.py
import purai ai = purai.PurAI(token, dev = False) print(ai.translate("https://file.audio/some.mp3"))

Custom

custom(owner, endpoint, body, subdomain)

Use a premade API endpoint within the PurAI project that isn’t listed here (usually for beta stuff).

API Reference

  • owner Required (str): The owner/provider of the custom endpoint.
  • endpoint Required (str): The custom endpoint to call.
  • body Required (dict): The request body as a dictionary.
  • subdomain Required (str): The subdomain to use for the custom request.

Code sample

This method lets you reach endpoints that don’t have a dedicated method yet — for example, a beta endpoint served from a different subdomain. The endpoint and subdomain arguments indicate where, within the ai.purlabs.xyz domain, the request is sent (https://beta.ai.purlabs.xyz/chat/completions in the example below).
main.py
import purai ai = purai.PurAI(token, dev = False) body = { "model": "gpt-3.5-turbo", "messages": [ { "role": "user", "content": "Hello! How are you?" } ] } print(ai.custom("openai", "/chat/completions", body, "beta"))
Last updated on