mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-22 15:24:55 +00:00
7bf58d23bc
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.
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
|
import CopilotActionBase, {
|
|
CopilotActionPrompt,
|
|
CopilotProcess,
|
|
PromptRole,
|
|
} from "./CopilotActionsBase";
|
|
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
|
|
|
export default class FixGrammarAndSpelling extends CopilotActionBase {
|
|
public constructor() {
|
|
super();
|
|
this.copilotActionType = CopilotActionType.FIX_GRAMMAR_AND_SPELLING;
|
|
this.acceptFileExtentions = [
|
|
...CodeRepositoryUtil.getCodeFileExtentions(),
|
|
...CodeRepositoryUtil.getReadmeFileExtentions(),
|
|
];
|
|
}
|
|
|
|
public override async getPrompt(
|
|
_data: CopilotProcess,
|
|
): Promise<CopilotActionPrompt> {
|
|
const prompt: string = `Please fix grammar and spelling in this file.
|
|
|
|
If you think the file is good and has no grammar or spelling mistakes, please reply with the following text:
|
|
--all-good--
|
|
|
|
Here is the file content. 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 code structure, logic, quotes around strings, or functionality.`;
|
|
|
|
return {
|
|
messages: [
|
|
{
|
|
content: systemPrompt,
|
|
role: PromptRole.System,
|
|
},
|
|
{
|
|
content: prompt,
|
|
role: PromptRole.User,
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|