Privacera AI Governance (PAIG) Shield Plugin Library
Project description
Privacera AI Goverance (PAIG) Shield Plugin Library
The privacera_shield
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 privacera_shield
library using pip
:
pip3 install privacera_shield
Initialization
You can initialize the privacera_shield SDK in multiple ways. Ensure that you set up the SDK at the application level.
Method 1: Environment Variable
The simplest way is to set the environment variable PRIVACERA_APPLICATION_KEY
to your Privacera Application Key. Then, include the following lines in your program to initialize the privacera_shield instance globally:
# Import privacera_shield
import privacera_shield.client
# Setup Privacera Shield
privacera_shield.api.setup(api_key="my_api_key")
Method 2: Initialization with Application Key
Alternatively, you can initialize the library by creating a privacera_shield plugin instance with your Privacera Application Key:
# Import privacera_shield
import privacera_shield.client
# Setup Privacera Shield
privacera_shield.api.setup(api_key="my_api_key", application_key='<YOUR_PRIVACERA_APPLICATION_KEY>')
Method 3: Custom Application Key Provider
If you want to create a custom way to provide the PRIVACERA_APPLICATION_KEY
, you can write your own logic by implementing a custom key provider. Here's how to do it:
# Import the required classes
import privacera_shield.client
# Define your custom key provider
class CustomApplicationKeyProvider(privacera_shield.api.APIKeyProvider):
def get_key(self):
# Implement your logic to retrieve the key using your preferred method
return '<YOUR_PRIVACERA_APPLICATION_KEY>'
# Create an instance of CustomApplicationKeyProvider
key_provider = CustomApplicationKeyProvider()
# Initialize and setup Privacera Shield with the custom key provider
privacera_shield.api.setup(application_key_provider=key_provider)
Setting User Context
Once you have completed the setup of privacera_shield, you can set the user in the context for Privacera Shield using one of the following methods, depending on how you have set up the privacera_shield plugin:
Method 1: Using direct API
import privacera_shield.client
privacera_shield.api.setup(...)
# Set the current user_name in the context
privacera_shield.api.set_current_user
# <call llm>
privacera_shield.api.clear()
Method 2: Using context manager
import privacera_shield.client
privacera_shield.api.setup(...)
# Set the current user_name in the context
with privacera_shield.api.create_shield_context(username="my_user_name"):
< call
llm >
Direct API
import privacera_shield.client
import privacera_shield.model
privacera_shield.api.setup(...)
with privacera_shield.api.create_shield_context(username='user1'):
response_text = privacera_shield.api.check_access(text='Hello world!',
conversation_type=privacera_shield.model.ConversationType.PROMPT)
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 Distributions
Built Distribution
Hashes for privacera_shield-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 677b5bdb3810dc96c17b00f2ffb57399cbc51bc26365554a4708cdf612d41e3a |
|
MD5 | c1bd1133caf05ba37b06cc7638d97f7b |
|
BLAKE2b-256 | c351445c7dd6a60b891667bad733dad5e4c17638227a2e57b96a85c35c192558 |