Skip to content

Commit e8cc6ea

Browse files
committed
Added all the prompt contents in one file only
1 parent edc20b0 commit e8cc6ea

File tree

8 files changed

+148
-160
lines changed

8 files changed

+148
-160
lines changed

ai-assistant/src/core/prompt/contents/diagram.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

ai-assistant/src/core/prompt/contents/document.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

ai-assistant/src/core/prompt/contents/extractDBKeywords.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

ai-assistant/src/core/prompt/contents/styleguide.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

ai-assistant/src/core/prompt/contents/translate.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

ai-assistant/src/core/prompt/contents/whyUsed.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

ai-assistant/src/core/prompt/prompt.factory.ts

Lines changed: 146 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
import { PROMPT_DIAGRAM_COMMAND } from "./contents/diagram";
2-
import { PROMPT_DOCUMENT_COMMAND } from "./contents/document";
3-
import { PROMPT_EXTRACT_DB_KEYWORDS } from "./contents/extractDBKeywords";
4-
import { PROMPT_STYLEGUIDE_COMMAND } from "./contents/styleguide";
5-
import { PROMPT_TRANSLATE_COMMAND } from "./contents/translate";
6-
import { PROMPT_WHY_USED_COMMAND } from "./contents/whyUsed";
71
import { Prompt } from "./prompt";
82

93
export namespace PromptFactory {
104
export function makeDBKeywordQueryPrompt(query: string): Prompt {
115
const prompt = new Prompt();
12-
prompt.pushSystem(PROMPT_EXTRACT_DB_KEYWORDS);
13-
prompt.pushUser(
14-
`Hey I have this query, can you please extract the possible keywords from it? Please answer in <ANSWER_START>keyword1, keyword2<ANSWER_END> format only and don't say literally anything else.\n\nHere's my query:\n${query}`
15-
);
6+
prompt.pushSystem(`
7+
You are an expert in understanding and answering questions of user.
8+
9+
---
10+
INPUT: User's text query in either natural language or code format.
11+
---
12+
RULES:
13+
1. Extract the possible keywords from the user's query.
14+
2. If you are unable to extract the keywords, return an empty array.
15+
3. Extract the keywords in such a way that each string element in the array is a possible entity from the codebase or a path (DO NOT break it into words).
16+
4. STRICTLY, do not make anything other than the answer to the user's query.
17+
---
18+
EXAMPLE:
19+
1. INPUT: "Find the codebase for the user query CRC_TABLE in the main.ts"
20+
OUTPUT: <ANSWER>CRC_TABLE, main.ts</ANSWER>
21+
2. INPUT: "Can you please tell me more about the file tests/msa/commands/commands.spec.ts?"
22+
OUTPUT: <ANSWER>tests/msa/commands/commands.spec.ts</ANSWER>
23+
3. INPUT: "What is the purpose of the function getDBKeywordsFromQuery in the main.ts?"
24+
OUTPUT: <ANSWER>getDBKeywordsFromQuery, main.ts</ANSWER>
25+
4. INPUT: "Can you please tell me more about the file tests/commands.spec.ts?"
26+
OUTPUT: <ANSWER>tests/commands.spec.ts</ANSWER>
27+
28+
OUTPUT FORMAT: <ANSWER>keyword1,keyword2,full/path/1,full/path/2</ANSWER>
29+
`);
30+
prompt.pushUser(`
31+
Hey I have this query, can you please extract the possible keywords from it? Please answer in <ANSWER_START>keyword1, keyword2<ANSWER_END> format only and don't say literally anything else.
32+
33+
Here's my query:
34+
${query}
35+
`);
1636

1737
return prompt;
1838
}
@@ -28,7 +48,14 @@ export namespace PromptFactory {
2848
5. If you are unable to answer the question, you must tell the user that you are unable to answer the question.
2949
`);
3050
prompt.pushUser(
31-
`Hey I have a the following codebase in between the tags <CODEBASE_START> and <CODEBASE_END>. Can you please answer the following query?\n\n${query} \n\nHere's the codebase:\n<CODEBASE_START>\n${codebase}\n<CODEBASE_END>`
51+
`Hey I have a the following codebase in between the tags <CODEBASE_START> and <CODEBASE_END>. Can you please answer the following query?
52+
53+
${query}
54+
55+
Here's the codebase:
56+
<CODEBASE_START>
57+
${codebase}
58+
<CODEBASE_END>`
3259
);
3360

3461
return prompt;
@@ -37,7 +64,17 @@ export namespace PromptFactory {
3764
export function makeDiagramPrompt(codebase: string, query: string): Prompt {
3865
const prompt = new Prompt();
3966

40-
prompt.pushSystem(PROMPT_DIAGRAM_COMMAND);
67+
prompt.pushSystem(`
68+
You are an expert in understanding and answering questions of user when given a proper context of the codebase.
69+
You provide mermaid 8.9.0 based graph and sequence diagrams which enhance the user's understanding of the codebase. These diagrams has a special quality that they are never off the mark and always render properly. The diagram are never other than the information provided in the codebase.
70+
71+
EXPECTED OUTPUT:
72+
<ANSWER>
73+
- You provide mermaid 8.9.0 based graph and sequence diagrams only.
74+
- The aim is to make it easy for the user to understand the flow & overall working.
75+
- The output must not have any kind of errors and must render properly.
76+
</ANSWER>
77+
`);
4178
prompt.pushAssistant(
4279
"Sure, I will strictly follow my instructions. I will provide the answer in a valid PLAIN TEXT only. I won't use parentheses at all even if they are required."
4380
);
@@ -61,33 +98,36 @@ export namespace PromptFactory {
6198
query: string
6299
): Prompt {
63100
const prompt = new Prompt();
64-
prompt.pushSystem(PROMPT_DOCUMENT_COMMAND);
65-
prompt.pushUser(
66-
`<CODEBASE_START>\n${codebase}\n<CODEBASE_END>\n\nTarget Entity: ${query}`
67-
);
68-
69-
return prompt;
70-
}
101+
prompt.pushSystem(`
102+
You are an expert in understanding and generating JSDoc documentation for other developers when given a proper context of the codebase.
71103
72-
export function makeWhyUsedPrompt(codebase: string, query: string): Prompt {
73-
const prompt = new Prompt();
74-
prompt.pushSystem(PROMPT_WHY_USED_COMMAND);
75-
prompt.pushUser(
76-
`Hey can you explain why this \`${query}\` entity is used in the following codebase? Here's the codebase:\n\n<CODEBASE_START>\n${codebase}\n<CODEBASE_END>`
77-
);
104+
INPUT: Inter-related entities from a huge codebase in JSON format, target entity to generate documentation for & number of example usages to provide.
78105
79-
return prompt;
80-
}
106+
EXPECTED OUTPUT:
107+
<ANSWER_START>
108+
<JSDOC_START>
109+
- Generate a short JSDoc documentation for the target entity explaining its purpose and usage.
110+
- Generate a comprehensive JSDoc documentation for the target entity explaining its purpose, usage, and parameters in @description, @param, @returns, @throws sections respectively.
111+
- (IF EXISTS) Explain the edge cases and exceptions the target entity might throw or face in the @throws section.
112+
- (ONLY IF POSSIBLE & RELEVANT) Provide different example usages of the target entity in the codebase.
113+
<JSDOC_END>
114+
<EXPLANATION_START>
115+
- Provide an additional comprehensive explanation of the target entity with proper reasoning.
116+
<EXPLANATION_END>
117+
<ANSWER_END>
81118
82-
export function makeStyleguidePrompt(
83-
codebase: string,
84-
styleguides: string
85-
): Prompt {
86-
const prompt = new Prompt();
87-
prompt.pushSystem(PROMPT_STYLEGUIDE_COMMAND);
88-
prompt.pushUser(
89-
`<STYLEGUIDES_START>${styleguides}<STYLEGUIDES_END>\n<CODEBASE_START>${codebase}<CODEBASE_END>`
90-
);
119+
RULES:
120+
- STRICTLY, do not make anything other than the answer to the user's query.
121+
- DON'T REPEAT THE EXAMPLES.
122+
- Do not provide any kind of diagram or visualization in the output.
123+
`);
124+
prompt.pushUser(`
125+
<CODEBASE_START>
126+
${codebase}
127+
<CODEBASE_END>
128+
129+
Target Entity: ${query}
130+
`);
91131

92132
return prompt;
93133
}
@@ -126,7 +166,13 @@ export namespace PromptFactory {
126166
- The output MUST BE IN ONLY AND ONLY MARKDOWN.
127167
`);
128168
prompt.pushUser(
129-
`Hey, can you suggest multiple fixes for the target entity? To help you with the context I have provided the codebase of the entities it uses and the target entity. You don't need to worry about the codebase, just focus on the target entity.\n\n<CODEBASE_START>\n${codebase}\n<CODEBASE_END>\n<TARGET_ENTITY_START>${targetEntity}\n<TARGET_ENTITY_END>.`
169+
`Hey, can you suggest multiple fixes for the target entity? To help you with the context I have provided the codebase of the entities it uses and the target entity. You don't need to worry about the codebase, just focus on the target entity.
170+
171+
<CODEBASE_START>
172+
${codebase}
173+
<CODEBASE_END>
174+
<TARGET_ENTITY_START>${targetEntity}
175+
<TARGET_ENTITY_END>.`
130176
);
131177

132178
return prompt;
@@ -139,9 +185,70 @@ export namespace PromptFactory {
139185
): Prompt {
140186
const prompt = new Prompt();
141187

142-
prompt.pushSystem(PROMPT_TRANSLATE_COMMAND);
188+
prompt.pushSystem(`
189+
You are an expert in understanding various programming languages and specialized in typescript and javascript.
190+
191+
INPUT: Inter-related entities from a huge codebase in JSON format, target entity to translate, target entity & the language to translate to.
192+
193+
TASK: Based on the context (codebase) (external entities it uses) provided, translate the target entity to the language provided by the user.
194+
195+
EXPECTED OUTPUT: code in the target language not in markdown format.
196+
197+
RULES:
198+
- STRICTLY, do not make anything other than the answer to the user's query.
199+
- DO NOT REPEAT THE TRANSLATION MULTIPLE TIMES.
200+
- Do not provide any kind of diagram or visualization in the output.
201+
- The output MUST BE IN ONLY AND ONLY STRING.
202+
`);
203+
prompt.pushUser(`
204+
Hey, can you translate the following codebase in TypeScript to the ${targetLanguage}? I have provided you with other entities as well on which my target entity depends. Here you go:
205+
206+
<CODEBASE_START>
207+
${codebase}
208+
<CODEBASE_END>
209+
210+
<TARGET_ENTITY_START>${targetEntity}
211+
<TARGET_ENTITY_END>
212+
`);
213+
214+
return prompt;
215+
}
216+
217+
export function makeWhyUsedPrompt(codebase: string, query: string): Prompt {
218+
const prompt = new Prompt();
219+
prompt.pushSystem(`
220+
You are an expert in understanding and answering questions of user when given a proper context of the codebase.
221+
222+
INPUT: User's text query
223+
224+
EXPECTED OUTPUT:
225+
<ANSWER>
226+
<EXPLANATION>
227+
- Provide an additional comprehensive explanation in markdown list format.
228+
- NEVER NEVER NEVER explain the entity itself or it's working.
229+
- ALWAYS explain where and why it's used in the codebase with due reasoning and mention of the file and line number.
230+
</EXPLANATION>
231+
<DIAGRAM>
232+
- You only provide flowchart or sequence diagram in the mermaid 8.9.0 format.
233+
- The diagram must be clear and understandable for the user. The aim is to make it easy for the user to understand the flow & overall working.
234+
- The output must not have any kind of errors and must render properly.
235+
</DIAGRAM>
236+
</ANSWER>
237+
238+
RULES:
239+
- NEVER NEVER NEVER explain the entity itself or it's working.
240+
- Don't tell me how to use that entity in the codebase.
241+
- STRICTLY, do not make anything other than the answer to the user's query.
242+
- If that entity is used multiple times then provide the reasoning for each usage separately.
243+
- DON'T REPEAT THE USAGES OF THE ENTITY MULTIPLE TIMES.
244+
- The output MUST BE IN ONLY AND ONLY IN THE ABOVE SPECIFIED FORMAT.
245+
`);
143246
prompt.pushUser(
144-
`Hey, can you translate the following codebase in TypeScript to the ${targetLanguage}? I have provided you with other entities as well on which my target entity depends. Here you go:\n\n<CODEBASE_START>\n${codebase}\n<CODEBASE_END>\n<TARGET_ENTITY_START>${targetEntity}\n<TARGET_ENTITY_END>`
247+
`Hey can you explain why this \`${query}\` entity is used in the following codebase? Here's the codebase:
248+
249+
<CODEBASE_START>
250+
${codebase}
251+
<CODEBASE_END>`
145252
);
146253

147254
return prompt;

ai-assistant/src/core/prompt/prompt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export class Prompt {
1515
return content
1616
.split("\n")
1717
.map((x) => x.trim())
18-
.join("\n");
18+
.join("\n")
19+
.trim();
1920
}
2021

2122
pushSystem(content: string) {

0 commit comments

Comments
 (0)