How to score Google Gemini answers with ClearRun

Get the answer with the Google Gen AI SDK, read response.text, then pass the prompt and the text to clearrun.evaluate().

Last updated

Steps

  1. Install both

    npm install @google/genai @clearrun/sdk
  2. Get an answer, then score it

    import { GoogleGenAI } from '@google/genai';
    import { createKernelClient } from '@clearrun/sdk';
    const clearrun = createKernelClient(); // reads CLEARRUN_API_KEY
    
    const ai = new GoogleGenAI({});
    const prompt = 'When was the Eiffel Tower finished?';
    
    const response = await ai.models.generateContent({
      model: process.env.GEMINI_MODEL,
      contents: prompt,
    });
    const answer = response.text ?? '';
    
    const { verdict } = await clearrun.evaluate({ prompt, responseText: answer });
    console.log(verdict.score, verdict.verdictId);