Skip to content

Commit c6d4aeb

Browse files
committed
Renamed /rcc-suggest to /rcc-improve
1 parent fdbfe0e commit c6d4aeb

File tree

6 files changed

+90
-92
lines changed

6 files changed

+90
-92
lines changed

ai-assistant/src/RocketChatterApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import { DocumentCommand } from "./commands/DocumentCommand";
2222
import { FindSimilarCommand } from "./commands/FindSimilar";
2323
import { HelpCommand } from "./commands/HelpCommand";
2424
import { ImportanceCommand } from "./commands/ImportanceCommand";
25+
import { ImproveCommand } from "./commands/ImproveCommand";
2526
import { StyleguideCommand } from "./commands/Styleguide";
26-
import { SuggestCommand } from "./commands/SuggestCommand";
2727
import { TranslateCommand } from "./commands/TranslateCommand";
2828
import { WhyUsedCommand } from "./commands/WhyUsedCommand";
2929
import { EstablishRelationsEndpoint } from "./endpoints/establishRelations";
@@ -63,7 +63,7 @@ export class RocketChatterApp extends App {
6363
configuration.slashCommands.provideSlashCommand(
6464
new StyleguideCommand()
6565
);
66-
configuration.slashCommands.provideSlashCommand(new SuggestCommand());
66+
configuration.slashCommands.provideSlashCommand(new ImproveCommand());
6767
configuration.slashCommands.provideSlashCommand(new TranslateCommand());
6868
configuration.slashCommands.provideSlashCommand(new WhyUsedCommand());
6969

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import {
2-
IHttp,
3-
IModify,
4-
IPersistence,
5-
IRead,
6-
} from "@rocket.chat/apps-engine/definition/accessors";
7-
import {
8-
ISlashCommand,
9-
SlashCommandContext,
10-
} from "@rocket.chat/apps-engine/definition/slashcommands";
11-
import { suggestModal } from "../modals/suggestModal";
12-
import { persistUIData } from "../utils/persistenceHandlers";
13-
14-
export class SuggestCommand implements ISlashCommand {
15-
public command = "rcc-suggest";
16-
public i18nParamsExample = "";
17-
public i18nDescription = "";
18-
public providesPreview = false;
19-
20-
public async executor(
21-
context: SlashCommandContext,
22-
read: IRead,
23-
modify: IModify,
24-
http: IHttp,
25-
persistence: IPersistence
26-
): Promise<void> {
27-
const userID = context.getSender().id;
28-
await persistUIData(persistence, userID, context);
29-
30-
const triggerId = context.getTriggerId();
31-
if (!triggerId) {
32-
throw new Error("No trigger ID provided");
33-
}
34-
35-
await modify
36-
.getUiController()
37-
.openSurfaceView(
38-
await suggestModal(),
39-
{ triggerId },
40-
context.getSender()
41-
);
42-
}
43-
}
1+
import {
2+
IHttp,
3+
IModify,
4+
IPersistence,
5+
IRead,
6+
} from "@rocket.chat/apps-engine/definition/accessors";
7+
import {
8+
ISlashCommand,
9+
SlashCommandContext,
10+
} from "@rocket.chat/apps-engine/definition/slashcommands";
11+
import { improveModal } from "../modals/improveModal";
12+
import { persistUIData } from "../utils/persistenceHandlers";
13+
14+
export class ImproveCommand implements ISlashCommand {
15+
public command = "rcc-improve";
16+
public i18nParamsExample = "";
17+
public i18nDescription = "";
18+
public providesPreview = false;
19+
20+
public async executor(
21+
context: SlashCommandContext,
22+
read: IRead,
23+
modify: IModify,
24+
http: IHttp,
25+
persistence: IPersistence
26+
): Promise<void> {
27+
const userID = context.getSender().id;
28+
await persistUIData(persistence, userID, context);
29+
30+
const triggerId = context.getTriggerId();
31+
if (!triggerId) {
32+
throw new Error("No trigger ID provided");
33+
}
34+
35+
await modify
36+
.getUiController()
37+
.openSurfaceView(
38+
await improveModal(),
39+
{ triggerId },
40+
context.getSender()
41+
);
42+
}
43+
}

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

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

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { PROMPT_DIAGRAM_COMMAND } from "./contents/diagram";
22
import { PROMPT_DOCUMENT_COMMAND } from "./contents/document";
33
import { PROMPT_EXTRACT_DB_KEYWORDS } from "./contents/extractDBKeywords";
44
import { PROMPT_STYLEGUIDE_COMMAND } from "./contents/styleguide";
5-
import { PROMPT_SUGGEST_COMMAND } from "./contents/suggest";
65
import { PROMPT_TRANSLATE_COMMAND } from "./contents/translate";
76
import { PROMPT_WHY_USED_COMMAND } from "./contents/whyUsed";
87
import { Prompt } from "./prompt";
@@ -93,13 +92,39 @@ export namespace PromptFactory {
9392
return prompt;
9493
}
9594

96-
export function makeSuggestPrompt(
95+
export function makeImprovePrompt(
9796
codebase: string,
9897
targetEntity: string
9998
): Prompt {
10099
const prompt = new Prompt();
101100

102-
prompt.pushSystem(PROMPT_SUGGEST_COMMAND);
101+
prompt.pushSystem(`
102+
You are an expert in understanding typescript and javascript codebases and fixing it provided the context of the codebase.
103+
104+
INPUT: Other entities the target entity might be using. The target entity to refactor.
105+
106+
TASKS:
107+
- Refactoring might include:
108+
- Renaming
109+
- Extracting different parts into separate functions
110+
- Making code concise to make it more readable, maintainable
111+
- Removing dead code
112+
- Performance improvements
113+
- Better alternatives
114+
- Syntax improvements
115+
- Code style improvements
116+
- Best practices
117+
- Suggest multiple (only if relevant) fixes for the target entity.
118+
- If the target entity is already correct then tell that it is already correct.
119+
- If the provided codebase contains entities that are functionally similar to what's used in the target entity, suggest using entities from the codebase.
120+
121+
EXPECTED OUTPUT: Suggestions for the target entity in form of MARKDOWN and CODE SNIPPET with the fix and explanation.
122+
123+
RULES:
124+
- STRICTLY, do not make anything other than the answer to the user's query.
125+
- Do not provide any kind of diagram or visualization in the output.
126+
- The output MUST BE IN ONLY AND ONLY MARKDOWN.
127+
`);
103128
prompt.pushUser(
104129
`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>.`
105130
);
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ import { Query } from "../core/query";
1818
import { getButton, getInputBox } from "../utils/blockBuilders";
1919
import { handleCommandResponse } from "../utils/handleCommandResponse";
2020

21-
export const COMMAND = "rcc-suggest";
22-
export const SUGGEST_COMMAND_MODAL = "suggest-command";
21+
export const COMMAND = "rcc-improve";
22+
export const IMPROVE_COMMAND_MODAL = "improve-command";
2323

24-
export async function suggestModal(): Promise<IUIKitSurfaceViewParam> {
24+
export async function improveModal(): Promise<IUIKitSurfaceViewParam> {
2525
return {
26-
id: SUGGEST_COMMAND_MODAL,
26+
id: IMPROVE_COMMAND_MODAL,
2727
type: UIKitSurfaceType.MODAL,
2828
title: {
2929
type: "plain_text",
30-
text: "Get Suggestions",
30+
text: "Get Improvements",
3131
},
3232
close: await getButton("Close", "", ""),
3333
clearOnClose: true,
3434
submit: await getButton("Submit", "submit", "submit", "Submit"),
3535
blocks: [
3636
await getInputBox(
3737
"",
38-
"What code you want to get suggestions for?",
39-
"suggest",
40-
"suggest",
38+
"What code you want to get improvements for?",
39+
"improve",
40+
"improve",
4141
"",
4242
true
4343
),
@@ -79,7 +79,7 @@ async function process(http: IHttp, query: string): Promise<string | null> {
7979
* ---------------------------------------------------------------------------------------------
8080
*/
8181
const answer = await llm.ask(
82-
PromptFactory.makeSuggestPrompt(
82+
PromptFactory.makeImprovePrompt(
8383
codeNodes.map((x) => x.code).join("\n\n"),
8484
query
8585
)
@@ -89,7 +89,7 @@ async function process(http: IHttp, query: string): Promise<string | null> {
8989
return answer;
9090
}
9191

92-
export async function suggestModalSubmitHandler(
92+
export async function improveModalSubmitHandler(
9393
view: IUIKitSurface,
9494
sender: IUser,
9595
room: IRoom,
@@ -100,7 +100,7 @@ export async function suggestModalSubmitHandler(
100100
const state = view.state as Record<string, any> | undefined;
101101
if (!state) return;
102102

103-
const query = state.suggest.suggest;
103+
const query = state.improve.improve;
104104
const sendMessage = await handleCommandResponse(
105105
"\n```typescript\n" + query + "\n```",
106106
sender,
@@ -113,6 +113,6 @@ export async function suggestModalSubmitHandler(
113113
if (res) {
114114
await sendMessage(res as string);
115115
} else {
116-
await sendMessage("❌ Failed to get suggestions");
116+
await sendMessage("❌ Failed to get improvements");
117117
}
118118
}

ai-assistant/src/utils/handleModalViewSubmit.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import {
1010
FIND_SIMILAR_COMMAND_MODAL,
1111
findSimilarModalSubmitHandler,
1212
} from "../modals/findSimilarModal";
13+
import {
14+
IMPROVE_COMMAND_MODAL,
15+
improveModalSubmitHandler,
16+
} from "../modals/improveModal";
1317
import {
1418
STYLEGUIDE_COMMAND_MODAL,
1519
styleguideModalSubmitHandler,
1620
} from "../modals/styleguideModal";
17-
import {
18-
SUGGEST_COMMAND_MODAL,
19-
suggestModalSubmitHandler,
20-
} from "../modals/suggestModal";
2121
import { getUIData } from "./persistenceHandlers";
2222

2323
const MODALS: Record<string, any> = {
24-
[SUGGEST_COMMAND_MODAL]: suggestModalSubmitHandler,
24+
[IMPROVE_COMMAND_MODAL]: improveModalSubmitHandler,
2525
[FIND_SIMILAR_COMMAND_MODAL]: findSimilarModalSubmitHandler,
2626
[STYLEGUIDE_COMMAND_MODAL]: styleguideModalSubmitHandler,
2727
};

0 commit comments

Comments
 (0)