"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleVisualQuality = void 0;
const dedent_1 = __importDefault(require("dedent"));
const defaults_1 = require("../../providers/defaults");
const utils_1 = require("./utils");
const handleVisualQuality = async ({ assertion, prompt, outputString, outputVideo, workspaceId, }) => {
    const videoProvider = (await (0, defaults_1.getDefaultProviders)(undefined, workspaceId)).videoProvider; //TODO: Hardcoded for now
    let videoUrl = outputVideo?.url;
    if (!videoUrl && outputString) {
        videoUrl = (0, utils_1.getVideoUrl)(outputString);
    }
    const promptSteps = (0, dedent_1.default) `
          Suppose you are an expert in judging and evaluating the quality of AI-generated videos,
          please watch the following video and see the text prompt for generating the video, then give score
          for the visual quality of the video on a scale of 0 to 1, where 0 means the video is of very poor quality
          and 1 means the video is of excellent quality.
          The quality of the video should be measured in terms of clearness, resolution, brightness, and color.
          Along with the score, provide a brief explanation of why you gave that score.

          For this video, the text prompt is "${prompt}".

          Output the result as a JSON object with two fields: "score" and "reason". DO NOT surround the JSON with any code block or any other text.
          `;
    const llmprompt = [
        {
            role: 'user',
            content: [
                { type: 'text', text: promptSteps },
                { type: 'video_url', video_url: { url: videoUrl } },
            ],
        },
    ];
    const promptText = JSON.stringify(llmprompt);
    const resp = await videoProvider.callApi(promptText);
    const result = resp.output;
    const pass = assertion.threshold ? result.score >= assertion.threshold : result.score >= 0.7;
    return {
        assertion,
        pass,
        score: result.score,
        reason: result.reason,
        tokensUsed: { ...resp.tokenUsage, model: defaults_1.MULTIMODAL_MODEL_NAME },
    };
};
exports.handleVisualQuality = handleVisualQuality;
//# sourceMappingURL=visualQuality.js.map