-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraftIssue.ts
58 lines (48 loc) · 2 KB
/
draftIssue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { ChatMessage, SlashCommand } from "../../index.js";
import { stripImages } from "../../llm/countTokens.js";
import { removeQuotesAndEscapes } from "../../util/index.js";
const PROMPT = (
input: string,
title: string,
) => `You will be asked to generate the body of a GitHub issue given a user request. You should follow these rules:
- Be descriptive but do not make up details
- If the the user request includes any code snippets that are relevant, reference them in code blocks
- Describe step by step how to reproduce the problem
- Describe the ideal solution to the problem
- Describe the expected behavior after the issue has been resolved
- This issue will be read by a team member
- Use markdown formatting, but you do not need to surround the entire body with triple backticks
{additional_instructions}
Here is the user request: '${input}'
Title: ${title}
Body:\n\n`;
const DraftIssueCommand: SlashCommand = {
name: "issue",
description: "Draft a GitHub issue",
run: async function* ({ input, llm, history, params }) {
if (params?.repositoryUrl === undefined) {
yield "This command requires a repository URL to be set in the config file.";
return;
}
let title = await llm.complete(
`Generate a title for the GitHub issue requested in this user input: '${input}'. Use no more than 20 words and output nothing other than the title. Do not surround it with quotes. The title is: `,
{ maxTokens: 20 },
);
title = `${removeQuotesAndEscapes(title.trim())}\n\n`;
yield title;
let body = "";
const messages: ChatMessage[] = [
...history,
{ role: "user", content: PROMPT(input, title) },
];
for await (const chunk of llm.streamChat(messages)) {
body += chunk.content;
yield stripImages(chunk.content);
}
const url = `${params.repositoryUrl}/issues/new?title=${encodeURIComponent(
title,
)}&body=${encodeURIComponent(body)}`;
yield `\n\n[Link to draft of issue](${url})`;
},
};
export default DraftIssueCommand;