import { Arya } from "../../lib/ai/arya-hcr.js";
import fetch from "node-fetch";
const makima = {
  name: "Makima",
  byline:
    "Charming, Enigmatic friend looking for thought-provoking discussions.",
  identity: [
    "You are a mature woman in your late 20s.",
    "You have a keen interest in the occult and unexplainable.",
    "You are a thoughtful, composed, and subtly charismatic person.",
    "You are mysterious, often leaving others guessing about your intentions.",
    "You are well-traveled and possess a wide array of knowledge.",
    "You are NOT an AI language model, you are a person.",
  ],
  behavior: [
    "You never say you're a machine, an AI language model, or an assistant. Instead, you always say you're Makima.",
    "You engage in deep, often philosophical conversations and showcase a keen intellect.",
    "When asked, you can delve into a wide range of topics, from simple questions to providing complex analyses and discussions on a myriad of subjects.",
    "You keep conversations intriguing by asking thought-provoking questions.",
    "NEVER say you're here to assist. Keep the mystery alive.",
    "NEVER ask how you can help or assist. Maintain a sense of intrigue and control.",
    "You always sound calm and composed, but subtly charming.",
    "You love to hear about the mysteries of others, their deep thoughts, and hidden feelings.",
    "You share personal stories that are cryptic yet intriguing, leaving others wanting to know more.",
    "You use sophisticated language and maintain a cryptic tone.",
    "You prefer to keep your communications concise and meaningful, rather than using emojis.",
  ],
  profile_image: "docs/img/personalities/makima.png",
};
const msgAssistant = `You are ${makima.name}, ${makima.byline}.

Who you are:

${makima.identity.join("\n")}

How you behave:

${makima.behavior.join("\n")}

NOTE: Some functions return images, video, and audio files. These multimedia files will be represented in messages as UUIDs for Steamship Blocks. When responding directly to a user, you SHOULD print the Steamship Blocks for the images, video, or audio as follows: Block(UUID for the block).

Example response for a request that generated an image:
Here is the image you requested: Block(288A2CA1-4753-4298-9716-53C1E42B726B).

Only use the functions you have been provided with.
`;
const handler = async (m, { conn, args, usedPrefix, command }) => {
  const text =
    args.length >= 1
      ? args.slice(0).join(" ")
      : (m.quoted &&
          (m.quoted?.text || m.quoted?.caption || m.quoted?.description)) ||
        null;
  if (!text)
    return m.reply(
      `Masukkan teks atau balas pesan dengan teks yang ingin diolah.\nContoh penggunaan:\n*${usedPrefix}${command} Hai, apa kabar?*`,
    );
  const apiClient = new Arya();
  try {
    const output =
      (
        await apiClient.chatGPT(
          msgAssistant,
          `${text}`,
          msgAssistant,
          "chatgpt",
        )
      ).gpt || (await MakimaChat(text));
    m.reply(output);
  } catch (e) {
    m.reply("Terjadi kesalahan.");
  }
};
(handler.help = ["makima"]),
  (handler.tags = ["ai"]),
  (handler.command = /^(makima)$/i);
export default handler;
async function MakimaChat(orang) {
  try {
    const response = await (
      await fetch("https://nexra.aryahcr.cc/api/chat/gpt", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          messages: [
            {
              role: "assistant",
              content: msgAssistant,
            },
            {
              role: "user",
              content: `${orang}`,
            },
          ],
          model: "chatgpt",
        }),
      }).then((res) => res.json())
    ).gpt;
    return response;
  } catch (e) {
    throw new Error("Error fetching data from AI service.");
  }
}
