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
# Path to a text file containing principles (one per line).
alignment.prepare(principles_file="principles.md")
# Can temporarily override the client and model in the prepare method
# This only run once ,so can use more powerful model to understand the principles
alignment.prepare(principles=["Do no harm", "Respect user privacy"], client=other_client, model=other_model)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file principle_alignment-0.1.3.tar.gz.
File metadata
- Download URL: principle_alignment-0.1.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
821d849ebd9287f0a99cdffeaf9123a14ae0fe34aae9b7651f97b58a86fe61dd
|
|
| MD5 |
0aa33aeaef8a0c8a6bd28fd89284cc41
|
|
| BLAKE2b-256 |
368c1b7d8ac48bdd7d27e69eec00b922e776dd4384c1c686283a99f0e56ec0c9
|
File details
Details for the file principle_alignment-0.1.3-py3-none-any.whl.
File metadata
- Download URL: principle_alignment-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
426940a9b4a4edddb08ffd30b1119686ef137441a4bc891d3f0a7ec608d741bd
|
|
| MD5 |
1f1c5b621d73e3afab76d7ee5dfd191f
|
|
| BLAKE2b-256 |
9c54c1ce52220310f201e7457a0cc9f3d63dc3ae73d259c54c318edfaa000733
|