This guide will help you build a simple Python application that demonstrates how to use Pulze.ai with OpenAI’s Python SDK.

Step 1: Setup

Firstly, you need to install OpenAI’s Python SDK. You can do this using pip:

pip3 install openai

Next, setup your Pulze API key and base URL:

import openai

openai.api_key = "<$PULZE_API_KEY>"
openai.base_url = "https://api.pulze.ai/v1/"

Replace <$PULZE_API_KEY> with your actual Pulze API key.

Step 2: Creating a Text Response

Create a text response using a custom model from Pulze:

text_response = openai.completions.create(
  model="pulze-v0",
  prompt="Say Hello World!",
)

Step 3: Creating a Chat Response

chat_response = openai.chat.completions.create(
  model="pulze-v0",
  messages=[{
    "role": "user",
    "content": "Say Hello World!"
  }],
)

Step 4: Adding Custom Labels

You can add custom labels as headers for your model requests. These labels will appear in the logs, making it easier for you to filter and locate specific requests.

import json

labels = {"mode": "internal", "type": "testing", "foo": "bar"}

response = openai.chat.completions.create(
  model="pulze-v0",
  messages=[{"role": "user", "content": "Say Hello World!"}],
  headers={"Pulze-Labels": json.dumps(labels)},
)

Step 5: Output

Finally, print your responses:

print(text_response, chat_response, response)

By following these steps, you should have a basic app that interacts with Pulze.ai using OpenAI’s Python SDK. The app sends a text and chat request and gets responses from the Pulze.ai platform. The app also shows you how to use custom labels, which can be useful for filtering and locating specific requests.