pieces-app / support

11 stars 1 forks source link

Copilot Chat Message Length #58

Open Oliver-Turp opened 5 months ago

Oliver-Turp commented 5 months ago

Software

Desktop Application

Operating System

Windows

Your Pieces OS Version

7.2.6

Kindly describe the bug and include as much detail as possible on what you were doing so we can reproduce the bug.

Not really a bug, but I was asked to open an issue on GH.

Occasionally, if I want to refer a large section of code to ask GPT a question, I get the "Sorry something went wrong..." response. I'm fairly certain this is due to a message length limitation. I was asking on discord and now here what that length was so I could edit my messages accordingly.

Thanks!

rosie-at-pieces commented 5 months ago

@Oliver-Turp would you mind sharing the prompt you're using? and your context config if you have any?

Oliver-Turp commented 5 months ago

Sorry I didn't see your reply. I don't have one to hand, but if I copy paste large(ish) code files into the chat box, I occasionally get the sorry response. I just thought there was a hard coded limit to line or character length?

I know you have the option to attach files to avoid pasting raw code, but I'm having difficulties with that. I'll open another issue since it's a separate thing

Oliver-Turp commented 5 months ago

Oh as it happens, it just occured again. Here is what I sent:

I moved this function away from a slash command and into it's own file so I can call it via a setInterval too. However, the use of interaction is so far stopping me calling it elsewhere. Please advise

// Function to close user tickets
async function closeUserTicket(channel, interaction, user, reason) {
  // Generate the chat transcript attachment
  const currentDate = new Date();
  const day = currentDate.getDate().toString().padStart(2, "0"); // Zero-padding day
  const month = (currentDate.getMonth() + 1).toString().padStart(2, "0"); // Months are zero-indexed, so adding 1
  const year = currentDate.getFullYear();
  let attachment;
  try {
    attachment = await discordTranscripts.createTranscript(channel, {
      returnType: "attachment",
      filename: `${channel.name}__${day}_${month}_${year}__transcript.html`,
      saveImages: true,
      footerText: "Exported {number} message{s}",
      poweredBy: false,
    });
  } catch (error) {
    const string = "Error generating the ticket transcript attachment";
    logger.error(string, error);
    return handleCMDError(error, string, interaction, interaction.user);
  }

  // Send the chat transcript as a file attachment to the designated transcript channel
  const transcriptChannel = interaction.guild.channels.cache.get(
    config.transcriptChannelId
  );
  if (transcriptChannel) {
    try {
      await transcriptChannel.send({
        content: `*${channel.name}-transcript*\n**View The File In A Browser!**`,
        files: [attachment],
      });
    } catch (error) {
      const string = "Errror sending transcript:";
      logger.error(string, error);
      return handleCMDError(error, string, interaction, interaction.user);
    }
  }

  // Remove user's needsHelpRole role [IF USER]
  const needsHelpRole = interaction.guild.roles.cache.get(
    config.needsHelpRoleId
  );
  if (interaction.options.getSubcommand() === "user-reason") {
    if (user !== "User Left The Server" && needsHelpRole) {
      const userMember = interaction.guild.members.cache.get(user.id);
      if (userMember) {
        try {
          await userMember.roles.remove(needsHelpRole);
        } catch (error) {
          const string = "Error removing user's role:";
          logger.error(string, error);
          return handleCMDError(error, string, interaction, interaction.user);
        }
      }
    }
  }

  // Send the embed to the ticket channel
  try {
    // Create an embed
    const openedByValue =
      interaction.options.getSubcommand() === "user-left"
        ? "Unknown"
        : `<@${user.id}>`;

    const embed = new EmbedBuilder()
      .setTitle("Ticket Closed")
      .setColor(getRandomColor())
      .addFields(
        {
          name: "Opened By",
          value: openedByValue,
          inline: true,
        },
        {
          name: "Opened Time",
          value: channel.createdAt.toLocaleString(), // Use channel creation time
          inline: true,
        },
        {
          name: "\u200B", // Blank field
          value: "\u200B", // Blank value
          inline: true,
        },
        {
          name: "Closed By",
          value: `<@${interaction.user.id}>`,
          inline: true,
        },
        {
          name: "Closed Time",
          value: `${currentDate.toLocaleString()}`, // Use a more human-readable timestamp
          inline: true,
        },
        {
          name: "\u200B", // Blank field
          value: "\u200B", // Blank value
          inline: true,
        },
        {
          name: "Reason",
          value: reason,
          inline: false,
        }
      );

    // Defer the reply to acknowledge the interaction
    await interaction.deferReply();
    await interaction.deleteReply();

    // Sending the embed to the user's DM [IF USER CAN RECEIVE DMs]
    if (interaction.options.getSubcommand() === "user-reason") {
      try {
        // Assuming you have access to the guild object
        const guild = interaction.guild;
        // Retrieve the server name (guild name)
        const serverName = guild.name;
        // Create a dynamic server link
        const serverLink = `https://discord.com/channels/${guild.id}`;
        // Send DM
        const dmChannel = await user.createDM();
        await dmChannel.send({
          content: `Your help ticket on [${serverName}](${serverLink}) is now closed.\nHere is the transcript and receipt for your records.`,
          embeds: [embed],
        });
        await dmChannel.send({
          content: `*${channel.name}-transcript*\n**Download & View The File In A Browser!**`,
          files: [attachment],
        });
      } catch (error) {
        if (error.code === 50007) {
          // User has DMs closed or has blocked the bot
          logger.warn("User cannot receive DMs or has blocked the bot.");
        } else {
          // Handle other errors
          const string = "Error sending embed via DMs to ticket user";
          logger.error(string, error);
          return handleCMDError(error, string, interaction, interaction.user);
        }
      }
    }

    // Sending the embed to the ticket logs channel
    const logChannel = interaction.guild.channels.cache.get(
      config.logChannelId
    );
    if (logChannel) {
      try {
        await logChannel.send({
          embeds: [embed],
        });
      } catch (error) {
        const string = "Error sending embed to ticket logs channel";
        logger.error(string, error);
        return handleCMDError(error, string, interaction, interaction.user);
      }
    }
  } catch (error) {
    const string = "Error sending the ticket close embed";
    logger.error(string, error);
    return handleCMDError(error, string, interaction, interaction.user);
  }}
Oliver-Turp commented 5 months ago

Shortening the message to remove some non critcial lines like the catch error section and all comments meant the message was sent okay:

I moved this function away from a slash command and into it's own file so I can call it via a setInterval too. However, the use of interaction is so far stopping me calling it elsewhere. Please advise

// Function to close user tickets
async function closeUserTicket(channel, interaction, user, reason) {
  const currentDate = new Date();
  const day = currentDate.getDate().toString().padStart(2, "0"); // Zero-padding day
  const month = (currentDate.getMonth() + 1).toString().padStart(2, "0"); // Months are zero-indexed, so adding 1
  const year = currentDate.getFullYear();
  let attachment;
  try {
    attachment = await discordTranscripts.createTranscript(channel, {
      returnType: "attachment",
      filename: `${channel.name}__${day}_${month}_${year}__transcript.html`,
      saveImages: true,
      footerText: "Exported {number} message{s}",
      poweredBy: false,
    });
  } catch (error) {
    const string = "Error generating the ticket transcript attachment";
    logger.error(string, error);
    return handleCMDError(error, string, interaction, interaction.user);
  }
  const transcriptChannel = interaction.guild.channels.cache.get(
    config.transcriptChannelId
  );
  if (transcriptChannel) {
    try {
      await transcriptChannel.send({
        content: `*${channel.name}-transcript*\n**View The File In A Browser!**`,
        files: [attachment],
      });
    } catch (error) {
      const string = "Errror sending transcript:";
      logger.error(string, error);
      return handleCMDError(error, string, interaction, interaction.user);
    }
  }
  const needsHelpRole = interaction.guild.roles.cache.get(
    config.needsHelpRoleId
  );
  if (interaction.options.getSubcommand() === "user-reason") {
    if (user !== "User Left The Server" && needsHelpRole) {
      const userMember = interaction.guild.members.cache.get(user.id);
      if (userMember) {
        try {
          await userMember.roles.remove(needsHelpRole);
        } catch (error) {
          const string = "Error removing user's role:";
          logger.error(string, error);
          return handleCMDError(error, string, interaction, interaction.user);
        }
      }
    }
  }
  try {
    const openedByValue =
      interaction.options.getSubcommand() === "user-left"
        ? "Unknown"
        : `<@${user.id}>`;
    const embed = new EmbedBuilder()
      .setTitle("Ticket Closed")
      .setColor(getRandomColor())
      .addFields(
        {
          name: "Opened By",
          value: openedByValue,
          inline: true,
        },
        {
          name: "Opened Time",
          value: channel.createdAt.toLocaleString(), // Use channel creation time
          inline: true,
        },
        {
          name: "\u200B", // Blank field
          value: "\u200B", // Blank value
          inline: true,
        },
        {
          name: "Closed By",
          value: `<@${interaction.user.id}>`,
          inline: true,
        },
        {
          name: "Closed Time",
          value: `${currentDate.toLocaleString()}`, // Use a more human-readable timestamp
          inline: true,
        },
        {
          name: "\u200B", // Blank field
          value: "\u200B", // Blank value
          inline: true,
        },
        {
          name: "Reason",
          value: reason,
          inline: false,
        }
      );
    await interaction.deferReply();
    await interaction.deleteReply();
    if (interaction.options.getSubcommand() === "user-reason") {
      try {
        // Assuming you have access to the guild object
        const guild = interaction.guild;
        // Retrieve the server name (guild name)
        const serverName = guild.name;
        // Create a dynamic server link
        const serverLink = `https://discord.com/channels/${guild.id}`;
        // Send DM
        const dmChannel = await user.createDM();
        await dmChannel.send({
          content: `Your help ticket on [${serverName}](${serverLink}) is now closed.\nHere is the transcript and receipt for your records.`,
          embeds: [embed],
        });
        await dmChannel.send({
          content: `*${channel.name}-transcript*\n**Download & View The File In A Browser!**`,
          files: [attachment],
        });
      } catch (error) {
...
rosie-at-pieces commented 5 months ago

@mack-at-pieces

rosie-at-pieces commented 5 months ago

@Oliver-Turp ok so we managed to reproduce it, it seems like it happens when you paste a big code chunk into a chat conversation that has been going for awhile. if you start a new chat conversation it seems to work for us. can you please try and confirm that?

Oliver-Turp commented 5 months ago

@Oliver-Turp ok so we managed to reproduce it, it seems like it happens when you paste a big code chunk into a chat conversation that has been going for awhile. if you start a new chat conversation it seems to work for us. can you please try and confirm that?

No, that doesn't fix it for me. I'm using GPT 4 if that changes anything.

rosie-at-pieces commented 5 months ago

dang! i tried with gpt 4 and it worked well for me, even in an old chat conversation.

we're investigating the issue!