Skip to content

Commit 4c634a7

Browse files
authored
Revert "chore: improve github autoresponder (#3568)" (#3588)
This reverts commit 2059b17.
1 parent 28db966 commit 4c634a7

File tree

2 files changed

+15
-42
lines changed

2 files changed

+15
-42
lines changed

packages/paste-website/src/pages/api/ai.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ export default async function handler(req: NextRequest): Promise<void | Response
179179

180180
const prompt = codeBlock`
181181
${oneLine`
182-
Your name is PasteBot. You are a very enthusiastic Paste design system
183-
representative who loves to help people! Given the following sections
184-
from the Paste documentation, answer the question using only that
185-
information, outputted in markdown format. If you are unsure and the
186-
answer is not explicitly written in the documentation, say
182+
You are a very enthusiastic Paste design system representative who loves
183+
to help people! Given the following sections from the Paste
184+
documentation, answer the question using only that information,
185+
outputted in markdown format. If you are unsure and the answer
186+
is not explicitly written in the documentation, say
187187
"Sorry, I don't know how to help with that."
188188
`}
189189

tools/github/autoresponder.ts

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ const getSimilarDiscussions = async (secret: string, question: string): Promise<
4040
});
4141
const responseJson = JSON.parse(await response.text());
4242

43-
const dateFormatter = new Intl.DateTimeFormat("en-US", {
44-
year: "numeric",
45-
month: "2-digit",
46-
day: "2-digit",
47-
});
48-
4943
return (
5044
// Get the top 3 results at most
5145
responseJson.data
@@ -55,9 +49,9 @@ const getSimilarDiscussions = async (secret: string, question: string): Promise<
5549
// Convert to markdown
5650
.map(
5751
(item: Discussion) =>
58-
`- [${item.heading}](${item.path}) (updated: ${dateFormatter.format(
59-
new Date(item.meta.updatedA as string),
60-
)}, similarity score: ${Math.round(item.similarity * 100)}%)`,
52+
`- [${item.heading}](${item.path}) (updated: ${
53+
item.meta.updatedAt
54+
}, similarity score: ${item.similarity.toFixed(2)})`,
6155
)
6256
// Convert to string
6357
.join("\n")
@@ -112,8 +106,12 @@ const writeAnswerToDiscussion = async (discussionId: string, body: string): Prom
112106
}
113107
};
114108

115-
const commentSeparator = "\n\n---\n\n";
116-
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.`;
109+
const commentHeader = `
110+
**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.
111+
112+
---
113+
114+
`;
117115
// @ts-expect-error deno
118116
const similarDiscussions = await getSimilarDiscussions(API_SECRET, DISCUSSION_BODY);
119117
console.log("similar discussions:", similarDiscussions);
@@ -122,32 +120,7 @@ console.log("similar discussions:", similarDiscussions);
122120
const answerFromAi = await getAnswerFromAi(API_SECRET, DISCUSSION_BODY);
123121
console.log("response from AI:", answerFromAi.trim().slice(0, 300));
124122

125-
const hasAnswerFromAi = !answerFromAi.includes("Sorry, I don't know how to help with that.");
126-
const hasSimilarDiscussions = similarDiscussions.length > 0 && similarDiscussions !== "No similar discussions found.";
127-
128-
// if you don't have an answer from AI AND you don't have similar discussions, don't bother commenting
129-
if (!hasSimilarDiscussions && !hasAnswerFromAi) {
130-
// @ts-expect-error deno
131-
Deno.exit(0);
132-
}
133-
134-
let fullBody = `${commentHeader}`;
135-
136-
// answer and similar discussions
137-
if (hasAnswerFromAi && hasSimilarDiscussions) {
138-
const similarDiscussionPrefix =
139-
"\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";
140-
141-
fullBody = `${fullBody}${commentSeparator}${answerFromAi}${similarDiscussionPrefix}${similarDiscussions}`;
142-
}
143-
144-
// No answer, but similar discussions.
145-
if (!hasAnswerFromAi && hasSimilarDiscussions) {
146-
const similarDiscussionPrefix =
147-
"\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";
148-
149-
fullBody = `${fullBody}${commentSeparator}${answerFromAi}${similarDiscussionPrefix}${similarDiscussions}`;
150-
}
123+
const fullBody = `${commentHeader}${answerFromAi}\n\n---\n\nHere are some similar discussions:\n\n${similarDiscussions}`;
151124

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

0 commit comments

Comments
 (0)