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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pangea_openai-0.2.1.tar.gz
  • Upload date:
  • Size: 11.5 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.1.tar.gz
Algorithm Hash digest
SHA256 a95d3318ef4b2cdccee51e2b06d7f558c129308307b47e082bdd3994d8ad70e1
MD5 671965ca0dc179f7174caf5207fbbb25
BLAKE2b-256 d0ef0870742e13cc427683ca62b3bd58d2899bd27f286c366130a7859efa17cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pangea_openai-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ba05a54b558785ccb97a18a242faa8d9808edc13bca9de786e3929a1bd6b0bf
MD5 5d5855a42026f605e599d041bec6dd65
BLAKE2b-256 ef7957d8e2a0580b6f44683cd7ed70784cce9072d8e74b4c38961e920e1f03d0

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