|
| 1 | +/** |
| 2 | + * Configuration for Apify MCP Server evaluations. |
| 3 | + */ |
| 4 | + |
| 5 | +import { readFileSync } from 'node:fs'; |
| 6 | +import { dirname, join } from 'node:path'; |
| 7 | +import { fileURLToPath } from 'node:url'; |
| 8 | + |
| 9 | +// Read version from test-cases.json |
| 10 | +function getTestCasesVersion(): string { |
| 11 | + const currentFilename = fileURLToPath(import.meta.url); |
| 12 | + const currentDirname = dirname(currentFilename); |
| 13 | + const testCasesPath = join(currentDirname, 'test-cases.json'); |
| 14 | + const testCasesContent = readFileSync(testCasesPath, 'utf-8'); |
| 15 | + const testCases = JSON.parse(testCasesContent); |
| 16 | + return testCases.version; |
| 17 | +} |
| 18 | + |
| 19 | +// Evaluator names |
| 20 | +export const EVALUATOR_NAMES = { |
| 21 | + TOOLS_EXACT_MATCH: 'tool-exact-match', |
| 22 | + TOOL_SELECTION_LLM: 'tool-selection-llm', |
| 23 | +} as const; |
| 24 | + |
| 25 | +export type EvaluatorName = typeof EVALUATOR_NAMES[keyof typeof EVALUATOR_NAMES]; |
| 26 | + |
| 27 | +// Models to evaluate |
| 28 | +export const MODELS_TO_EVALUATE = [ |
| 29 | + 'openai/gpt-4o-mini', |
| 30 | + 'anthropic/claude-3.5-haiku', |
| 31 | + 'google/gemini-2.5-flash', |
| 32 | +]; |
| 33 | + |
| 34 | +export const TOOL_SELECTION_EVAL_MODEL = 'openai/gpt-4o-mini'; |
| 35 | + |
| 36 | +export const PASS_THRESHOLD = 0.7; |
| 37 | + |
| 38 | +export const DATASET_NAME = `mcp_server_dataset_v${getTestCasesVersion()}`; |
| 39 | + |
| 40 | +// System prompt |
| 41 | +export const SYSTEM_PROMPT = 'You are a helpful assistant'; |
| 42 | + |
| 43 | +export const TOOL_CALLING_BASE_TEMPLATE = ` |
| 44 | +You are an evaluation assistant evaluating user queries and tool calls to |
| 45 | +determine whether a tool was chosen and if it was a right tool. |
| 46 | +
|
| 47 | +The tool calls have been generated by a separate agent, and chosen from the list of |
| 48 | +tools provided below. It is your job to decide whether that agent chose |
| 49 | +the right tool to call. |
| 50 | +
|
| 51 | +[BEGIN DATA] |
| 52 | +************ |
| 53 | +[User's previous interaction with the assistant]: {{context}} |
| 54 | +[User query]: {{query}} |
| 55 | +************ |
| 56 | +[LLM decided to call these tools]: {{tool_calls}} |
| 57 | +[LLM response]: {{llm_response}} |
| 58 | +************ |
| 59 | +[END DATA] |
| 60 | +
|
| 61 | +DECISION: [correct or incorrect] |
| 62 | +EXPLANATION: [Super short explanation of why the tool choice was correct or incorrect] |
| 63 | +
|
| 64 | +Your response must be single word, either "correct" or "incorrect", |
| 65 | +and should not contain any text or characters aside from that word. |
| 66 | +
|
| 67 | +"correct" means the correct tool call was chosen, the correct parameters |
| 68 | +were extracted from the query, the tool call generated is runnable and correct, |
| 69 | +and that no outside information not present in the query was used |
| 70 | +in the generated query. |
| 71 | +
|
| 72 | +"incorrect" means that the chosen tool was not correct |
| 73 | +or that the tool signature includes parameter values that don't match |
| 74 | +the formats specified in the tool signatures below. |
| 75 | +
|
| 76 | +You must not use any outside information or make assumptions. |
| 77 | +Base your decision solely on the information provided in [BEGIN DATA] ... [END DATA], |
| 78 | +the [Tool Definitions], and the [Reference instructions] (if provided). |
| 79 | +Reference instructions are optional and are intended to help you understand the use case and make your decision. |
| 80 | +
|
| 81 | +[Reference instructions]: {{reference}} |
| 82 | +
|
| 83 | +[Tool definitions]: {{tool_definitions}} |
| 84 | +` |
| 85 | +export function getRequiredEnvVars(): Record<string, string | undefined> { |
| 86 | + return { |
| 87 | + PHOENIX_BASE_URL: process.env.PHOENIX_BASE_URL, |
| 88 | + PHOENIX_API_KEY: process.env.PHOENIX_API_KEY, |
| 89 | + OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY, |
| 90 | + OPENROUTER_BASE_URL: process.env.OPENROUTER_BASE_URL, |
| 91 | + }; |
| 92 | +} |
| 93 | + |
| 94 | +// Removes newlines and trims whitespace. Useful for Authorization header values |
| 95 | +// because CI secrets sometimes include trailing newlines or quotes. |
| 96 | +export function sanitizeHeaderValue(value?: string): string | undefined { |
| 97 | + if (value == null) return value; |
| 98 | + return value.replace(/[\r\n]/g, '').trim().replace(/^"|"$/g, ''); |
| 99 | +} |
| 100 | + |
| 101 | +export function validateEnvVars(): boolean { |
| 102 | + const envVars = getRequiredEnvVars(); |
| 103 | + const missing = Object.entries(envVars) |
| 104 | + .filter(([, value]) => !value) |
| 105 | + .map(([key]) => key); |
| 106 | + |
| 107 | + if (missing.length > 0) { |
| 108 | + // eslint-disable-next-line no-console |
| 109 | + console.error(`Missing required environment variables: ${missing.join(', ')}`); |
| 110 | + return false; |
| 111 | + } |
| 112 | + |
| 113 | + return true; |
| 114 | +} |
0 commit comments