

Integrating Llumo evaluation API in LLM Pipeline
This guide will explain how to integrate Llumo’s evaluation API into a LLM pipeline build on top of OpenAI APIs. LLUMO can help you gain complete insights on you LLM outputs and customer success using proprietary framework- EvalLM. We’ll go through the process step-by-step to make it easy for developers of all levels. ##Setting up the environment ###Importing libraries:- os: This module provides a way to use operating system dependent functionality, like reading environment variables.
- OpenAI: This is the official OpenAI Python client, used to interact with OpenAI’s API.
- requests: A popular library for making HTTP requests in Python.
- json: Used for parsing JSON data, which is common in API responses.
- logging: Provides a flexible framework for generating log messages in Python.
- getpass: Allows secure password prompts where the input is not displayed on the screen.
- We use
logging.basicConfig()
to configure the logging system. Thelevel=logging.INFO
argument sets the threshold for logging messages to INFO level and above. - We create a logger object named logger that we’ll use throughout our script to log important information and errors.
- We use
getpass()
to prompt the user for their API keys. This function hides the input, making it more secure than using regular input(). - This approach is safer than hardcoding API keys in your script, which could accidentally be shared or exposed.
- We use
os.environ
to set environment variables for both API keys. - Environment variables are a secure way to store sensitive information, as they’re not part of your code and are only accessible within the current process.
- We create an instance of the OpenAI client using the API key we just set.
- Using
os.getenv("OPENAI_API_KEY")
retrieves the API key from the environment variables.
Llumo Evaluation Function Documentation
Define Llumo Evaluation Function
Function Definition:
- We define a function
evaluate_with_llumo
that takes aprompt
andoutput
as inputs.
API Setup:
- We retrieve the Llumo API key from environment variables.
- We set the API endpoint and prepare headers for the HTTP request.
Payload Preparation:
- We create a payload dictionary with the
prompt
,output
, and predefined analytics type (“Clarity”).
API Request:
- We use
requests.post()
to send a POST request to the Llumo API. response.raise_for_status()
will raise an exception for HTTP errors.
Response Parsing:
- We parse the JSON response and extract the evaluation data.
- We print the API response for debugging purposes.
Error Handling:
-
We use a try-except block to catch potential errors:
- JSON decoding errors
- Request exceptions
- If an error occurs, we log it and return an empty dictionary with a failure indicator.
Return Values:
- The function returns a tuple containing:
- Evaluation data (or empty dictionary if evaluation failed)
- Success boolean
Getting Respone from OpenAI
Define Example Prompt:
- We define an example prompt to be used for testing without compression.
Example Prompt:
Evaluating Responses with Llumo
Evaluate the OpenAI Response:
- We evaluate the response generated by the OpenAI API using the Llumo evaluation function.
- We call the evaluate_with_llumo function with the example prompt and the openai_output.
- We check if the evaluation was successful:
- If successful, we print the Llumo evaluation results.
- If the evaluation fails, we print an error message and indicate that the original prompt can be used if evaluation fails.