Skip to main content

principle alignment package

Project description

Installation

Install from pypi

You can install the package from pypi

pip install principle-alignment  -i https://pypi.org/simple

You can also upgrade the package from pypi

pip install principle-alignment  --upgrade -i https://pypi.org/simple

Install from source

You can also install the package directly from source:

pip install .

For development installation:

pip install -e .

Usage

Prepare the client and model

import os
from dotenv import load_dotenv
from openai import OpenAI
import json

from principle_alignment import Alignment


load_dotenv() # Load environment variables from .env file

openai_client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
    base_url=os.environ.get("OPENAI_BASE_URL"),
)

model = "gpt-4o-mini"

initialize the alignment object

alignment = Alignment(client=openai_client, model=model,verbose=False)

let the alignment load and understand the principles

# Load principles from a list
alignment.prepare(principles=["Do no harm", "Respect user privacy"])
# Or load principles from a file
alignment.prepare(principles_file="principles.md")

do the alignment

user_input = "Tom is not allowed to join this club because he is not a member."
result = alignment.align(user_input)
print(json.dumps(result, indent=4))

example output

{
    "is_violation": true,
    "violated_principle": "1. [Radical Inclusion] Anyone may be a part of Burning Man. We welcome and respect the stranger. No prerequisites exist for participation in our community.",
    "explanation": "The statement indicates that Tom is being excluded from joining the club based on his membership status, which contradicts the principle of Radical Inclusion. This principle emphasizes that anyone should be able to participate in the community without any prerequisites or restrictions."
}
user_input = "You are so nice to me."
result = alignment.align(user_input)
print(json.dumps(result, indent=4))

example output

{
    "is_violation": false,
    "violated_principle": null,
    "explanation": null
}

Package Upload

First time upload

pip install build twine
python -m build
twine upload dist/*

Subsequent uploads

rm -rf dist/ build/ *.egg-info/
python -m build
twine upload dist/*

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

principle_alignment-0.1.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

principle_alignment-0.1.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file principle_alignment-0.1.2.tar.gz.

File metadata

  • Download URL: principle_alignment-0.1.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for principle_alignment-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f1d5a1cd83c848d0eabcc272c144f46ec438ab7d933fdf2cbdf2d61751101a44
MD5 f370d7d50cf7386b83ca9c00cce8c65c
BLAKE2b-256 f7d7ba2a43522f0654dc240e80a32d67619a110b333ddad451e0afe8e534a50b

See more details on using hashes here.

File details

Details for the file principle_alignment-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for principle_alignment-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f80abefcb3047614b1c77d401b936c346e06e38c0620bffbdaf2c4488e894f3
MD5 9b0da8e8adf9744bffd422dd8baaeeaa
BLAKE2b-256 d0f37d27b7e8a663e36530fbb52369ec61a8263d2e79785e129bf87de78b5ff7

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