"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleMultimodalContextualRelevancy = void 0;
const child_process_1 = require("child_process");
const path_1 = __importDefault(require("path"));
const matchers_1 = require("../matchers");
const defaults_1 = require("../providers/defaults");
const invariant_1 = __importDefault(require("../util/invariant"));
async function evalMultiModelContextualRelevancy(outputString, context, provider) {
    const script = path_1.default.join(__dirname, 'python', 'multimodal_contextual_relevancy_eval.py');
    const res = await new Promise((res_, rej) => {
        const py = (0, child_process_1.spawn)('python', [script, outputString, JSON.stringify(context)], {
            env: process.env,
        });
        let out = '', err = '';
        py.stdout.on('data', (d) => (out += d));
        py.stderr.on('data', (d) => (err += d));
        py.on('close', (c) => (c === 0 ? res_(out) : rej(new Error(err))));
    });
    return JSON.parse(res);
}
const handleMultimodalContextualRelevancy = async ({ assertion, outputString, test, context, workspaceId, }) => {
    (0, invariant_1.default)(typeof outputString === 'string', 'output must string');
    const provider = await (0, matchers_1.getAndCheckProvider)('text', test.options?.provider, (await (0, defaults_1.getDefaultProviders)(undefined, workspaceId)).gradingProvider, 'multimodal-contextual-relevancy');
    //const context = { ...test, options: { provider: { modelName: (provider as any).modelName } } };
    const result = await evalMultiModelContextualRelevancy(outputString, context, provider);
    return { assertion, pass: result.pass, score: result.score, reason: result.reason };
};
exports.handleMultimodalContextualRelevancy = handleMultimodalContextualRelevancy;
//# sourceMappingURL=handleMultimodalContextualRelevancy.js.map