Integration: OpenAI
Integration with an OpenAI application is straightforward with openllmtelemetry
package.
First, you need to set a few environment variables. This can be done via your container set up or via code.
import openllmtelemetry
openllmtelemetry.instrument()
Output
Set WhyLabs API Key: ··········
Using WhyLabs API key with ID: D66fSX6Znf
Set GuardRails endpoint (leave blank to skip guardrail): https://<guardrails-endpoint>
Set GuardRails API Key: ··········
Using GuardRails API key with prefix: wjYDn8
Do you want to save these settings to a configuration file? [y/n]: y
Once this is done, all of your OpenAI interactions will be automatically traced. If you have rulesets enabled for blocking in WhyLabs Secure policy, the library will block requests accordingly
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You are a helpful chatbot. "
},
{
"role": "user",
"content": "Noodles are amazing?"
}
],
temperature=0.7,
max_tokens=64,
top_p=1
)