import { logger } from "../../../logger/index.mjs";
import { AIProvider, generateText } from "@intlayer/ai";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

//#region src/utils/AI/autocomplete/index.ts
const CHAT_GPT_PROMPT = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "./PROMPT.md"), "utf-8");
const aiDefaultOptions = {
	provider: AIProvider.OPENAI,
	model: "gpt-4o-mini",
	temperature: .7
};
/**
* Autocompletes a content declaration file by constructing a prompt for AI models.
* The prompt includes details about the project's locales, file paths of content declarations,
* and requests for identifying issues or inconsistencies.
*/
const autocomplete = async ({ text, aiConfig, applicationContext, contextBefore, currentLine, contextAfter }) => {
	const prompt = CHAT_GPT_PROMPT.replace("{{applicationContext}}", applicationContext ?? "").replace("{{contextBefore}}", contextBefore ?? "").replace("{{currentLine}}", currentLine ?? "").replace("{{contextAfter}}", contextAfter ?? "");
	const { text: newContent, usage } = await generateText({
		...aiConfig,
		messages: [{
			role: "system",
			content: prompt
		}, {
			role: "assistant",
			content: text
		}]
	});
	logger.info(`${usage?.totalTokens ?? 0} tokens used in the request`);
	return {
		autocompletion: newContent,
		tokenUsed: usage?.totalTokens ?? 0
	};
};

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