mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Refactor CopilotActionsBase.ts, RefactorCode.ts, ImproveReadme.ts, ImproveVariableNames.ts, FixGrammarAndSpelling.ts, and WriteUnitTests.ts to use an array of messages instead of a single prompt. Each message in the array contains the content and role of the prompt. This change improves the flexibility and readability of the code.
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
|
import CopilotActionBase, {
|
|
CopilotActionPrompt,
|
|
CopilotProcess,
|
|
PromptRole,
|
|
} from "./CopilotActionsBase";
|
|
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
|
|
|
export default class RefactorCode extends CopilotActionBase {
|
|
public constructor() {
|
|
super();
|
|
this.copilotActionType = CopilotActionType.REFACTOR_CODE;
|
|
this.acceptFileExtentions = CodeRepositoryUtil.getCodeFileExtentions();
|
|
}
|
|
|
|
public override async getPrompt(
|
|
_data: CopilotProcess,
|
|
): Promise<CopilotActionPrompt> {
|
|
const prompt: string = `Please refactor this code into smaller functions/methods if its not refactored properly.
|
|
|
|
If you think the code is refactored already, please reply with the following text:
|
|
--all-good--
|
|
|
|
Here is the code. This is in {{fileLanguage}}:
|
|
|
|
{{code}}
|
|
`;
|
|
|
|
const systemPrompt: string = `You are an expert programmer. Here are your instructions:
|
|
- You will follow the instructions given by the user strictly.
|
|
- You will not deviate from the instructions given by the user.
|
|
- You will not change the code unnecessarily. For example you will not change the logic, quotes around strings, or functionality.`;
|
|
|
|
return {
|
|
messages: [
|
|
{
|
|
content: systemPrompt,
|
|
role: PromptRole.System,
|
|
},
|
|
{
|
|
content: prompt,
|
|
role: PromptRole.User,
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|