PAIG Client Library
The paig_client library allows you to seamlessly integrate Privacera AI Governance into your Langchain projects.
This README provides a step-by-step guide on how to set up and use the library.
Installation
You can install the paig_client library using pip:
pip3 install paig_client
Initialization
Start your PAIG-Server. Create your AI application and
download the Shield Configuration file. Place the file in a folder called privacera relative to
where you are running the app.
# Import paig_client
import paig_client.client
# Setup Privacera Shield
paig_client.client.setup(frameworks=["langchain"])
Usage
Once you have completed the setup of paig_client, you can set the user in the context for Privacera Shield to use.
Using context manager
import paig_client.client
paig_client.client.setup(frameworks=["langchain"])
# Set the current user_name in the context
try:
with paig_client.client.create_shield_context(username="user"):
response = llm_chain.run(prompt_text)
except paig_client.exception.AccessControlException as e:
# If access is denied, then this exception will be thrown. You can handle it accordingly.
print(f"AccessControlException: {e}")
Completed example using OpenAI
import os
import paig_client.client
import paig_client.exception
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
api_key=os.getenv("OPENAI_API_KEY") #
# Initialize Privacera Shield
paig_client.client.setup(frameworks=["langchain"])
llm = OpenAI(openai_api_key=api_key)
template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"])
# Let's assume the user is "testuser"
user = "testuser"
prompt_text = "Who is first President of USA and where did they live?"
llm_chain = LLMChain(prompt=prompt, llm=llm)
try:
with paig_client.client.create_shield_context(username=user):
response = llm_chain.run(prompt_text)
print(f"LLM Response: {response}")
except paig_client.exception.AccessControlException as e:
# If access is denied, then this exception will be thrown. You can handle it accordingly.
print(f"AccessControlException: {e}")
Additional ways of passing the application config file to set up Privacera Shield
- Place the file in
privacerafolder relative to where you are running the app - Set the environment variable
PRIVACERA_SHEILD_CONFIG_FILEto the path of the file - Set the environment variable
PRIVACERA_SHEILD_CONFIG_DIRto a folder that contains the file. Only one application config file should be present in the folder. - Pass the file path as
application_config_fileparameter to the setup function - Pass the string contents of the file to the setup function as
application_configparameter - Pass a dict by converting file contents which is in json format and pass to the setup function as
application_configparameter
You can create multiple applications
If your application has multiple AI models to be governed, you can create multiple applications as follows:
app1 = paig_client.client.setup_app(...)
app2 = paig_client.client.setup_app(...)
You can pass the following parameters to the setup_app function:
- Pass the file path as
application_config_fileparameter to the setup function - Pass the string contents of the file to the setup function as
application_configparameter - Pass a dict by converting file contents which is in json format and pass to the setup function as
application_configparameter
And then you can pass the application object to the context manager as follows:
with paig_client.client.create_shield_context(appplication=app1, username="user"):
response = llm_chain.run(prompt_text)
Note that you still need to invoke the privacera.client.setup() method before calling the privacera.client.setup_app(...) method.
Metadata
Release files for paig-client 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paig_client-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for paig_client-0.0.6-py3-none-any.whl |
Release files / paig_client-0.0.6-py3-none-any.whl
| Download URL | paig_client-0.0.6-py3-none-any.whl |
|---|---|
| Size | 49.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d1722524954a35bf171198da38c19ac6199a66f59a8e0f999fccc1fff955c8b6
|
|
BLAKE2b-256 checksum How to use checksums |
063db849337590803a09bcaf160a4af86bb0d96655117cf134060a9b436d0a0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.18
|
Security for paig-client 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.