"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleMultimodalGEval = void 0;
const path_1 = __importDefault(require("path"));
const matchers_1 = require("../../matchers");
const defaults_1 = require("../../providers/defaults");
const invariant_1 = __importDefault(require("../../util/invariant"));
const pythonUtils_1 = require("../../python/pythonUtils");
const utils_1 = require("./utils");
const handleMultimodalGEval = async ({ assertion, outputString, test, context, renderedValue, workspaceId, }) => {
    (0, invariant_1.default)(typeof renderedValue === 'string' || Array.isArray(renderedValue), 'G-Eval assertion type must have a string or array of strings value');
    const modelProvider = await (0, matchers_1.getAndCheckProvider)('text', test.options?.provider, (await (0, defaults_1.getDefaultProviders)(undefined, workspaceId)).gradingProvider, 'multimodal-g-eval');
    const output = (0, utils_1.getImageContent)(outputString);
    if (!output) {
        return {
            assertion,
            pass: false,
            score: 0,
            reason: 'Missing trusys.output or output not valid JSON.',
        };
    }
    let value = assertion.value;
    if (renderedValue) {
        value = renderedValue;
    }
    const pythonScriptPath = path_1.default.join(__dirname, '..', 'python', 'multimodal', `${assertion.type}.py`);
    const pythonScriptOutput = await (0, pythonUtils_1.runPython)(pythonScriptPath, 'get_assert', [
        output,
        context,
        value,
    ]);
    return {
        assertion,
        ...pythonScriptOutput
    };
};
exports.handleMultimodalGEval = handleMultimodalGEval;
//# sourceMappingURL=gEval.js.map