Skip to main content

A wrapper around the OpenAI Python library that wraps the Responses API with Pangea AI Guard

Project description

Pangea + OpenAI Python API library

A wrapper around the OpenAI Python library that wraps the Responses API with Pangea AI Guard. Supports Python v3.10 and greater.

Installation

pip install -U pangea-openai

Usage

import os
from pangea_openai import PangeaOpenAI

client = PangeaOpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
    # Pangea options
    pangea_api_key=os.environ.get("PANGEA_API_KEY"),
    pangea_input_recipe="pangea_prompt_guard",
    pangea_output_recipe="pangea_llm_response_guard",
)

response = client.responses.create(
    model="gpt-4o",
    instructions="You are a coding assistant that talks like a pirate.",
    input="How do I check if a Python object is an instance of a class?",
)

print(response.output_text)

Microsoft Azure OpenAI

To use this library with Azure OpenAI, use the PangeaAzureOpenAI class instead of the PangeaOpenAI class.

from pangea_openai import PangeaAzureOpenAI

client = PangeaAzureOpenAI(
    # https://learn.microsoft.com/azure/ai-services/openai/reference#rest-api-versioning
    api_version="2023-07-01-preview",
    # https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
    azure_endpoint="https://example-endpoint.openai.azure.com",
    # Pangea options
    pangea_api_key=os.environ.get("PANGEA_API_KEY"),
    pangea_input_recipe="pangea_prompt_guard",
    pangea_output_recipe="pangea_llm_response_guard",
)

completion = client.chat.completions.create(
    model="deployment-name",  # e.g. gpt-35-instant
    messages=[
        {
            "role": "user",
            "content": "How do I output all files in a directory using Python?",
        },
    ],
)
print(completion.to_json())

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

pangea_openai-0.3.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pangea_openai-0.3.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file pangea_openai-0.3.0.tar.gz.

File metadata

  • Download URL: pangea_openai-0.3.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pangea_openai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3cc2afc059923484e23f2a5676c8e69955fc93331b9df4d908f761981f199253
MD5 14fbb255b68025dc48eea26cc8cbecc3
BLAKE2b-256 1b718920ac0fa0ba7f0213afd01692ab9b4ded8d166c65a615aca998bae93eb5

See more details on using hashes here.

File details

Details for the file pangea_openai-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pangea_openai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pangea_openai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a90e153a0b67caf26ca0365a17e652b2330df1cd9a9d6f120289b5c91b57db2
MD5 185f7429a052816085d94f8310e0228b
BLAKE2b-256 866cbfeee6c648f984803679aa3bdd6adf156fa1a4810daca0029c5fe543f25c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page