Skip to content

Commit

Permalink
Revert "chore: improve github autoresponder (#3568)" (#3588)
Browse files Browse the repository at this point in the history
This reverts commit 2059b17.
  • Loading branch information
SiTaggart authored Nov 1, 2023
1 parent 28db966 commit 4c634a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
10 changes: 5 additions & 5 deletions packages/paste-website/src/pages/api/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ export default async function handler(req: NextRequest): Promise<void | Response

const prompt = codeBlock`
${oneLine`
Your name is PasteBot. You are a very enthusiastic Paste design system
representative who loves to help people! Given the following sections
from the Paste documentation, answer the question using only that
information, outputted in markdown format. If you are unsure and the
answer is not explicitly written in the documentation, say
You are a very enthusiastic Paste design system representative who loves
to help people! Given the following sections from the Paste
documentation, answer the question using only that information,
outputted in markdown format. If you are unsure and the answer
is not explicitly written in the documentation, say
"Sorry, I don't know how to help with that."
`}
Expand Down
47 changes: 10 additions & 37 deletions tools/github/autoresponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ const getSimilarDiscussions = async (secret: string, question: string): Promise<
});
const responseJson = JSON.parse(await response.text());

const dateFormatter = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "2-digit",
day: "2-digit",
});

return (
// Get the top 3 results at most
responseJson.data
Expand All @@ -55,9 +49,9 @@ const getSimilarDiscussions = async (secret: string, question: string): Promise<
// Convert to markdown
.map(
(item: Discussion) =>
`- [${item.heading}](${item.path}) (updated: ${dateFormatter.format(
new Date(item.meta.updatedA as string),
)}, similarity score: ${Math.round(item.similarity * 100)}%)`,
`- [${item.heading}](${item.path}) (updated: ${
item.meta.updatedAt
}, similarity score: ${item.similarity.toFixed(2)})`,
)
// Convert to string
.join("\n")
Expand Down Expand Up @@ -112,8 +106,12 @@ const writeAnswerToDiscussion = async (discussionId: string, body: string): Prom
}
};

const commentSeparator = "\n\n---\n\n";
const commentHeader = `**Disclaimer:** This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary.`;
const commentHeader = `
**Disclaimer:** This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary.
---
`;
// @ts-expect-error deno
const similarDiscussions = await getSimilarDiscussions(API_SECRET, DISCUSSION_BODY);
console.log("similar discussions:", similarDiscussions);
Expand All @@ -122,32 +120,7 @@ console.log("similar discussions:", similarDiscussions);
const answerFromAi = await getAnswerFromAi(API_SECRET, DISCUSSION_BODY);
console.log("response from AI:", answerFromAi.trim().slice(0, 300));

const hasAnswerFromAi = !answerFromAi.includes("Sorry, I don't know how to help with that.");
const hasSimilarDiscussions = similarDiscussions.length > 0 && similarDiscussions !== "No similar discussions found.";

// if you don't have an answer from AI AND you don't have similar discussions, don't bother commenting
if (!hasSimilarDiscussions && !hasAnswerFromAi) {
// @ts-expect-error deno
Deno.exit(0);
}

let fullBody = `${commentHeader}`;

// answer and similar discussions
if (hasAnswerFromAi && hasSimilarDiscussions) {
const similarDiscussionPrefix =
"\n\nI also did a search, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:\n\n";

fullBody = `${fullBody}${commentSeparator}${answerFromAi}${similarDiscussionPrefix}${similarDiscussions}`;
}

// No answer, but similar discussions.
if (!hasAnswerFromAi && hasSimilarDiscussions) {
const similarDiscussionPrefix =
"\n\nI did do a search though, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:\n\n";

fullBody = `${fullBody}${commentSeparator}${answerFromAi}${similarDiscussionPrefix}${similarDiscussions}`;
}
const fullBody = `${commentHeader}${answerFromAi}\n\n---\n\nHere are some similar discussions:\n\n${similarDiscussions}`;

// @ts-expect-error deno
const commentId = await writeAnswerToDiscussion(DISCUSSION_NODE_ID, fullBody);
Expand Down

0 comments on commit 4c634a7

Please sign in to comment.