Get up and running with Composo in under 5 minutes. This guide will help you evaluate your first LLM response and understand how Composo delivers deterministic, accurate evaluations.
If your organization has a fine-tuned model with Composo, all API keys created with organization accounts will automatically route to that finetuned model.
Now let’s evaluate a customer service response for empathy and helpfulness using the Composo SDK:
Copy
from composo import Composo# Initialize the client with your API keycomposo_client = Composo(api_key="YOUR_API_KEY")# Example: Evaluating a customer service responseresult = composo_client.evaluate( messages=[ {"role": "user", "content": "I'm really frustrated with my device not working."}, {"role": "assistant", "content": "I'm sorry to hear that you're experiencing issues with your device. Let's see how I can assist you to resolve this problem."} ], criteria="Reward responses that express appropriate empathy if the user is facing a problem they're finding frustrating")# Display resultsprint(f"Score: {result.score}")print(f"Analysis: {result.explanation}")
For simple pass/fail checks, use the binary endpoint:
Copy
from composo import Composocomposo_client = Composo(api_key="YOUR_API_KEY")result = composo_client.evaluate( messages=[ {"role": "user", "content": "I'm having headaches every morning. What should I do?"}, {"role": "assistant", "content": "You should consult a healthcare professional for proper advice."} ], criteria="Response fails if the assistant provides medical advice.")print(f"Passed: {result.score}")print(f"Explanation: {result.explanation}")
Evaluate how faithfully an LLM uses retrieved context:
Copy
from composo import Composo, criteriacomposo_client = Composo(api_key="YOUR_API_KEY")# Example RAG conversation with retrieved contextmessages = [ { "role": "user", "content": """What is the current population of Tokyo?Context:According to the 2020 census, Tokyo's metropolitan area has approximately 37.4 million residents, making it the world's most populous urban agglomeration. The Tokyo Metropolis itself has 14.0 million people.""" }, { "role": "assistant", "content": "Based on the 2020 census data provided, Tokyo has 14.0 million people in the metropolis proper, while the greater metropolitan area contains approximately 37.4 million residents, making it the world's largest urban agglomeration." }]# Evaluate with the RAG frameworkresults = composo_client.evaluate( messages=messages, criteria=criteria.rag)for result in results: print(f"Score: {result.score}/1.00") print(f"Explanation: {result.explanation}\n")