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.2.0.tar.gz (11.4 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.2.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pangea_openai-0.2.0.tar.gz
  • Upload date:
  • Size: 11.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 0f335a230460bf465a7f107a004339d605bf8eda0bb46987ffbe0d7d2ceb268c
MD5 376cb4e78afaf96bfdb7d06f4b3c6ce1
BLAKE2b-256 2ff9ed4d78c175b40267783732a0bec71672a42f9a2fa52fc9c4806f288c57b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pangea_openai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79615043fca73997db72a5da90f8e787d5eb5185ded1439820a360a3a3742da5
MD5 d3461272a1e486ff040beeba0e332327
BLAKE2b-256 512a901febfd9f4f68dbe23d6dd31d78f54b5a7ac9db491ad11701a86cfc1f60

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