|
| 1 | +import { createDataset } from "@arizeai/phoenix-client/datasets"; |
| 2 | +import { |
| 3 | + asExperimentEvaluator, |
| 4 | + runExperiment, |
| 5 | +} from "@arizeai/phoenix-client/experiments"; |
| 6 | +import { createDocumentRelevancyEvaluator } from "@arizeai/phoenix-evals/llm/createDocumentRelevancyEvaluator"; |
| 7 | + |
| 8 | +import "dotenv/config"; |
| 9 | + |
| 10 | +import { spaceKnowledgeApplication } from "./app"; |
| 11 | + |
| 12 | +import { openai } from "@ai-sdk/openai"; |
| 13 | + |
| 14 | +const DATASET = [ |
| 15 | + "Which moon might harbor life due to its unique geological features?", |
| 16 | + "What theoretical region marks the outer boundary of the Solar System?", |
| 17 | + "Which planet defies the typical rotation pattern observed in most celestial bodies?", |
| 18 | + "Where in the Solar System would you experience the most extreme atmospheric conditions?", |
| 19 | + "How dominant is the Sun's gravitational influence compared to all other objects in our solar system?", |
| 20 | + "What region of the Solar System contains remnants from its early formation beyond the gas giants?", |
| 21 | + "What significant change occurred in our understanding of planetary classification in 2006?", |
| 22 | + "What environmental challenge would explorers face during certain seasons on Mars?", |
| 23 | + "What makes Venus one of the most hostile environments for robotic exploration?", |
| 24 | + "What unique liquid features exist on Saturn's largest moon?", |
| 25 | + "What is the duration of the longest-observed storm in our Solar System?", |
| 26 | + "Which celestial body experiences the most intense geological activity?", |
| 27 | + "Which planet experiences the most dramatic temperature swings between day and night?", |
| 28 | + "What region separates the inner and outer planets in our Solar System?", |
| 29 | + "What unusual orbital characteristic makes Uranus unique among the planets?", |
| 30 | +]; |
| 31 | + |
| 32 | +async function main() { |
| 33 | + async function task(example) { |
| 34 | + const question = example.input.question; |
| 35 | + const result = await spaceKnowledgeApplication(question); |
| 36 | + return result.context || ""; |
| 37 | + } |
| 38 | + |
| 39 | + const dataset = await createDataset({ |
| 40 | + name: "document-relevancy-eval", |
| 41 | + description: |
| 42 | + "Queries that are answered by extracting context from the space knowledge base", |
| 43 | + examples: DATASET.map((question) => ({ |
| 44 | + input: { |
| 45 | + question: question, |
| 46 | + }, |
| 47 | + })), |
| 48 | + }); |
| 49 | + |
| 50 | + const documentRelevancyEvaluator = createDocumentRelevancyEvaluator({ |
| 51 | + model: openai("gpt-5"), |
| 52 | + }); |
| 53 | + |
| 54 | + const documentRelevancyCheck = asExperimentEvaluator({ |
| 55 | + name: "document-relevancy", |
| 56 | + kind: "LLM", |
| 57 | + evaluate: async ({ input, output }) => { |
| 58 | + // Use the document relevancy evaluator from phoenix-evals |
| 59 | + const result = await documentRelevancyEvaluator.evaluate({ |
| 60 | + input: String(input.question), |
| 61 | + documentText: String(output), |
| 62 | + }); |
| 63 | + |
| 64 | + return result; |
| 65 | + }, |
| 66 | + }); |
| 67 | + |
| 68 | + await runExperiment({ |
| 69 | + experimentName: "document-relevancy-experiment", |
| 70 | + experimentDescription: |
| 71 | + "Evaluate the relevancy of extracted context from a knowledge base", |
| 72 | + dataset: dataset, |
| 73 | + task, |
| 74 | + evaluators: [documentRelevancyCheck], |
| 75 | + }); |
| 76 | +} |
| 77 | + |
| 78 | +main().catch((error) => { |
| 79 | + // eslint-disable-next-line no-console |
| 80 | + console.error(error); |
| 81 | + process.exit(1); |
| 82 | +}); |
0 commit comments