-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.ts
60 lines (52 loc) · 1.64 KB
/
messages.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
59
60
import {
InteropMessage,
MessageRole,
prompt,
} from "@copilot-extensions/preview-sdk";
import { getAllFilesRelativePaths } from "./utils.js";
import path from "node:path";
import { fileURLToPath } from 'url';
import { hints } from "./consts.js";
import fs from "node:fs";
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const docsPath = path.join(dirname, "../docs");
const list = getAllFilesRelativePaths(docsPath);
export default async function getPaths(
messages: InteropMessage<MessageRole>[],
apiKey: string,
userMessage: InteropMessage<MessageRole>
): Promise<string[] | null> {
const { message: paths } = await prompt({
token: apiKey,
messages: [
...messages,
{
role: "system",
content: `This Query is relating To next.js App router.
You just have to provide the file paths, that the user would need to read, to complete their request.
You can provide multiple file paths, seperated by a new line.
If the user is just casual and not asking for any help, just return null.
You don't need to solve the problem or do anything, just provide the file path among the list.`,
},
{
role: "system",
content: `Here are some additional keys & values to help you figure out file path based on keywords: ${JSON.stringify(
hints
)}`,
},
{
role: "system",
content: `The message is ${userMessage.content}`,
},
{
role: "system",
content: list.join("\n"),
},
],
});
if(paths.content === "null"){
return null;
}
return paths.content.split("\n")
}