Setting up the Validate SDK

Installing the Validate SDK

To install tonic_validate, you use pip:

pip install tonic-validate

Setting the Validate API key environment variable

To log metrics using tonic_validate, you need to set the API key by passing it into ValidateApi

from tonic_validate import ValidateApi
validate_api = ValidateApi("your-api-key")

Obtaining and providing an API key for the LLM evaluator

Validate uses LLM-assisted evaluation. You must provide an API key for the LLM evaluator model that you want to use.

Validate currently supports the following models:

Using the OpenAI API

To use the OpenAI models, you must:

  • Have an OpenAI API key

  • Set the API key as the value of the environment variable OPENAI_API_KEY

To get an Open AI API key, go to the OpenAI API key page.

In your Python script or Jupyter notebook, set your Open AI API key as the value of OPENAI_API_KEY:

import os
os.environ["OPENAI_API_KEY"] = "put-your-openai-api-key-here"

Using Azure's OpenAI service

Validate also supports Azure's OpenAI API service.

To use Azure, you must set up an Azure OpenAI deployment.

For information on how to set up a deployment, go to this Azure OpenAI service quickstart.

After you set up your deployment, copy your API key and API endpoint to the following environment variables:

import os
os.environ["AZURE_OPENAI_KEY"] = "put-your-azure-openai-api-key-here"
os.environ["AZURE_OPENAI_ENDPOINT"] = "put-your-azure-endpoint-here"

When you start a Validate run, you must provide the deployment name.

Using the Gemini API

To use Gemini models, you must:

  • Have a Gemini API key

  • Set the API key as the value of the environment variable GEMINI_API_KEY

To get a Gemini API key, go to the Gemini home page.

In your Python script or Jupyter notebook, set your Gemini API key as the value of GEMINI_API_KEY:

import os
os.environ["GEMINI_API_KEY"] = "put-your-gemini-api-key-here"

Using the Anthropic API

To use Anthropic models, you must:

  • Have a Anthropic API key

  • Set the API key as the value of the environment variable ANTHROPIC_API_KEY

To get a Anthropic API key, go to the Anthropic API page.

In your Python script or Jupyter notebook, set your Anthropic API key as the value of ANTHROPIC_API_KEY:

import os
os.environ["ANTHROPIC_API_KEY"] = "put-your-anthropic-api-key-here"

Last updated