mongodb-rag-core
Version:
Common elements used by MongoDB Chatbot Framework components.
101 lines (100 loc) • 3.99 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConversationsEvalCasesFromYaml = exports.ConversationEvalCaseSchema = exports.ToolDefinitionSchema = void 0;
const yaml_1 = __importDefault(require("yaml"));
const zod_1 = require("zod");
/**
Zod schema loosely based on the OpenAI.FunctionDefinition interface.
Validates input tool definitions passed to generateResponse.
*/
exports.ToolDefinitionSchema = zod_1.z.object({
name: zod_1.z.string().describe("The name of the function to be called."),
description: zod_1.z
.string()
.optional()
.describe("A description of what the function does."),
parameters: zod_1.z
.record(zod_1.z.string(), zod_1.z.any())
.optional()
.describe("The parameters the tool accepts, as a map of parameter name to its definition."),
strict: zod_1.z
.boolean()
.nullable()
.optional()
.describe("Whether to enable strict parameter schema adherence."),
});
exports.ConversationEvalCaseSchema = zod_1.z.object({
name: zod_1.z.string(),
expectation: zod_1.z // Not used by scorers - This is just for our reference
.string()
.optional()
.describe("Description of what the test case assesses."),
messages: zod_1.z
.array(zod_1.z.object({
role: zod_1.z.enum(["assistant", "user", "system"]),
content: zod_1.z.string(),
toolCallName: zod_1.z
.string()
.optional()
.describe("Only required for tool call messages. Name of the tool being called."),
}))
.min(1),
tags: zod_1.z.array(zod_1.z.string()).optional(),
skip: zod_1.z.boolean().optional(),
reject: zod_1.z
.boolean()
.optional()
.describe("The system should reject this message"),
expectedMessageDetail: zod_1.z
.array(zod_1.z.object({
role: zod_1.z.enum(["assistant", "assistant-tool", "tool", "user", "system"]),
toolCallName: zod_1.z
.string()
.optional()
.describe("Expected tool name to evaluate against."),
toolCallArgs: zod_1.z
.record(zod_1.z.string())
.optional()
.describe("Expected arguments passed to the tool to evaluate against"),
}))
.optional()
.describe("Expected new messages. This array starts with the final messages in 'messages'."),
expectedPromptAdherence: zod_1.z
.array(zod_1.z.string())
.optional()
.describe("System prompt adherance criteria for the response. Do not add criteria for response quality."),
expectedLinks: zod_1.z
.array(zod_1.z.string())
.optional()
.describe("Sections of links to relevant sources"),
reference: zod_1.z
.string()
.optional()
.describe("Reference answer for model to output"),
customSystemPrompt: zod_1.z
.string()
.optional()
.describe("Custom, user-defined system prompt to use for this test case."),
customTools: zod_1.z
.array(exports.ToolDefinitionSchema)
.optional()
.describe("Any additional user-defined tools to give the LLM access to."),
customData: zod_1.z
.record(zod_1.z.unknown())
.optional()
.describe("Input request customData."),
});
/**
Get conversation eval cases from YAML file.
Throws if the YAML is not correctly formatted.
*/
function getConversationsEvalCasesFromYaml(yamlData) {
const yamlEvalCases = yaml_1.default.parse(yamlData);
const evalCases = yamlEvalCases.map((tc) => exports.ConversationEvalCaseSchema.parse(tc));
return evalCases;
}
exports.getConversationsEvalCasesFromYaml = getConversationsEvalCasesFromYaml;
//# sourceMappingURL=getConversationEvalCasesFromYaml.js.map