ChatPredictionGuard
Prediction Guard is a secure, scalable GenAI platform that safeguards sensitive data, prevents common AI malfunctions, and runs on affordable hardware.
Overview
Integration details
This integration utilizes the Prediction Guard API, which includes various safeguards and security features.
Model features
The models supported by this integration only feature text-generation currently, along with the input and output checks described here.
Setup
To access Prediction Guard models, contact us here to get a Prediction Guard API key and get started.
Credentials
Once you have a key, you can set it with
import os
if "PREDICTIONGUARD_API_KEY" not in os.environ:
os.environ["PREDICTIONGUARD_API_KEY"] = "<Your Prediction Guard API Key>"
Installation
Install the Prediction Guard Langchain integration with
%pip install -qU langchain-predictionguard
Note: you may need to restart the kernel to use updated packages.
Instantiation
from langchain_predictionguard import ChatPredictionGuard
# If predictionguard_api_key is not passed, default behavior is to use the `PREDICTIONGUARD_API_KEY` environment variable.
chat = ChatPredictionGuard(model="Hermes-3-Llama-3.1-8B")
Invocation
messages = [
("system", "You are a helpful assistant that tells jokes."),
("human", "Tell me a joke"),
]
ai_msg = chat.invoke(messages)
ai_msg
AIMessage(content="Why don't scientists trust atoms? Because they make up everything!", additional_kwargs={}, response_metadata={}, id='run-cb3bbd1d-6c93-4fb3-848a-88f8afa1ac5f-0')
print(ai_msg.content)
Why don't scientists trust atoms? Because they make up everything!
Streaming
chat = ChatPredictionGuard(model="Hermes-2-Pro-Llama-3-8B")
for chunk in chat.stream("Tell me a joke"):
print(chunk.content, end="", flush=True)
Why don't scientists trust atoms?
Because they make up everything!