import { logger } from "../../../logger/index.mjs";
import { readAsset } from "../../../_virtual/_utils_asset.mjs";
import { extractJson } from "../../extractJSON.mjs";
import { generateText } from "@intlayer/ai";

//#region src/utils/AI/auditTag/index.ts
const CHAT_GPT_PROMPT = readAsset("./PROMPT.md");
const aiDefaultOptions = {};
/**
* Audits a tag by constructing a prompt for AI models.
* The prompt includes details about the tag and related dictionaries.
*/
const auditTag = async ({ dictionaries, tag, aiConfig, applicationContext }) => {
	const prompt = CHAT_GPT_PROMPT.replace("{{tag.description}}", tag.description ?? "").replace("{{tag.key}}", tag.key).replace("{{applicationContext}}", applicationContext ?? "");
	const { text: newContent, usage } = await generateText({
		...aiConfig,
		messages: [{
			role: "system",
			content: prompt
		}, {
			role: "user",
			content: [
				"**Tag to audit:**",
				"This is the tag that you should consider to audit:",
				JSON.stringify(tag)
			].join("\n")
		}]
	});
	logger.info(`${usage?.totalTokens ?? 0} tokens used in the request`);
	return {
		fileContent: extractJson(newContent),
		tokenUsed: usage?.totalTokens ?? 0
	};
};

//#endregion
export { aiDefaultOptions, auditTag };
//# sourceMappingURL=index.mjs.map