mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
chore: Update CopilotActionsBase.ts, RefactorCode.ts, ImproveReadme.ts, ImproveVariableNames.ts, FixGrammarAndSpelling.ts, and WriteUnitTests.ts
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.
This commit is contained in:
@@ -15,9 +15,19 @@ export interface CopilotActionRunResult {
|
||||
files: Dictionary<CodeRepositoryFile>;
|
||||
}
|
||||
|
||||
export enum PromptRole {
|
||||
System = "system",
|
||||
User = "user",
|
||||
Assistant = "assistant",
|
||||
}
|
||||
|
||||
export interface Prompt {
|
||||
content: string;
|
||||
role: PromptRole;
|
||||
}
|
||||
|
||||
export interface CopilotActionPrompt {
|
||||
prompt: string;
|
||||
systemPrompt: string;
|
||||
messages: Array<Prompt>;
|
||||
}
|
||||
|
||||
export interface CopilotActionVars {
|
||||
|
||||
@@ -2,6 +2,7 @@ import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
||||
import CopilotActionBase, {
|
||||
CopilotActionPrompt,
|
||||
CopilotProcess,
|
||||
PromptRole,
|
||||
} from "./CopilotActionsBase";
|
||||
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
||||
|
||||
@@ -34,8 +35,16 @@ export default class FixGrammarAndSpelling extends CopilotActionBase {
|
||||
- You will not change the code unnecessarily. For example you will not change the code structure, logic, quotes around strings, or functionality.`;
|
||||
|
||||
return {
|
||||
prompt: prompt,
|
||||
systemPrompt: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
||||
import CopilotActionBase, {
|
||||
CopilotActionPrompt,
|
||||
CopilotProcess,
|
||||
PromptRole,
|
||||
} from "./CopilotActionsBase";
|
||||
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
||||
import ServiceLanguage from "Common/Types/ServiceCatalog/ServiceLanguage";
|
||||
@@ -97,8 +98,7 @@ export default class ImproveComments extends CopilotActionBase {
|
||||
const oldCode: string = data.oldCode;
|
||||
const newCode: string = data.newCode;
|
||||
|
||||
const prompt: CopilotActionPrompt = {
|
||||
prompt: `
|
||||
const prompt: string = `
|
||||
I've asked to improve comments in the code.
|
||||
|
||||
This is the old code:
|
||||
@@ -115,11 +115,22 @@ export default class ImproveComments extends CopilotActionBase {
|
||||
|
||||
If the code was NOT changed EXCEPT comments, please reply with the following text:
|
||||
--no--
|
||||
`,
|
||||
systemPrompt: await this.getSystemPrompt(),
|
||||
};
|
||||
`;
|
||||
|
||||
return prompt;
|
||||
const systemPrompt: string = await this.getSystemPrompt();
|
||||
|
||||
return {
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
public override async getPrompt(
|
||||
@@ -144,8 +155,16 @@ export default class ImproveComments extends CopilotActionBase {
|
||||
const systemPrompt: string = await this.getSystemPrompt();
|
||||
|
||||
return {
|
||||
prompt: prompt,
|
||||
systemPrompt: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
||||
import CopilotActionBase, {
|
||||
CopilotActionPrompt,
|
||||
CopilotProcess,
|
||||
PromptRole,
|
||||
} from "./CopilotActionsBase";
|
||||
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
||||
|
||||
@@ -31,8 +32,16 @@ export default class ImproveVariableNames extends CopilotActionBase {
|
||||
- You will not change the code unnecessarily. For example you will not change the code structure, logic, quotes around strings, or functionality.`;
|
||||
|
||||
return {
|
||||
prompt: prompt,
|
||||
systemPrompt: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
||||
import CopilotActionBase, {
|
||||
CopilotActionPrompt,
|
||||
CopilotProcess,
|
||||
PromptRole,
|
||||
} from "./CopilotActionsBase";
|
||||
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
||||
|
||||
@@ -31,8 +32,16 @@ export default class ImproveReadme extends CopilotActionBase {
|
||||
- You will not change the code unnecessarily. For example you will not change the code structure, logic, quotes around strings, or functionality.`;
|
||||
|
||||
return {
|
||||
prompt: prompt,
|
||||
systemPrompt: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
||||
import CopilotActionBase, {
|
||||
CopilotActionPrompt,
|
||||
CopilotProcess,
|
||||
PromptRole,
|
||||
} from "./CopilotActionsBase";
|
||||
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
||||
|
||||
@@ -31,8 +32,16 @@ export default class RefactorCode extends CopilotActionBase {
|
||||
- You will not change the code unnecessarily. For example you will not change the logic, quotes around strings, or functionality.`;
|
||||
|
||||
return {
|
||||
prompt: prompt,
|
||||
systemPrompt: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import CopilotActionType from "Common/Types/Copilot/CopilotActionType";
|
||||
import CopilotActionBase, { CopilotActionPrompt } from "./CopilotActionsBase";
|
||||
import CopilotActionBase, {
|
||||
CopilotActionPrompt,
|
||||
PromptRole,
|
||||
} from "./CopilotActionsBase";
|
||||
import CodeRepositoryUtil from "../../Utils/CodeRepository";
|
||||
|
||||
export default class WriteUnitTests extends CopilotActionBase {
|
||||
@@ -23,8 +26,16 @@ export default class WriteUnitTests extends CopilotActionBase {
|
||||
- You will not change the code unnecessarily. For example you will not change the logic, quotes around strings, or functionality.`;
|
||||
|
||||
return {
|
||||
prompt: prompt,
|
||||
systemPrompt: systemPrompt,
|
||||
messages: [
|
||||
{
|
||||
content: systemPrompt,
|
||||
role: PromptRole.System,
|
||||
},
|
||||
{
|
||||
content: prompt,
|
||||
role: PromptRole.User,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { JSONArray, JSONObject } from "Common/Types/JSON";
|
||||
import BadRequestException from "Common/Types/Exception/BadRequestException";
|
||||
import Sleep from "Common/Types/Sleep";
|
||||
import logger from "CommonServer/Utils/Logger";
|
||||
import { CopilotActionPrompt } from "../CopilotActions/CopilotActionsBase";
|
||||
import { CopilotActionPrompt, Prompt } from "../CopilotActions/CopilotActionsBase";
|
||||
import ErrorGettingResponseFromLLM from "../../Exceptions/ErrorGettingResponseFromLLM";
|
||||
|
||||
enum LlamaPromptStatus {
|
||||
@@ -27,10 +27,12 @@ export default class Llama extends LlmBase {
|
||||
await API.post(
|
||||
URL.fromString(serverUrl.toString()).addRoute("/prompt/"),
|
||||
{
|
||||
messages: [
|
||||
{ role: "system", content: data.systemPrompt },
|
||||
{ role: "user", content: data.prompt },
|
||||
],
|
||||
messages: data.messages.map((message: Prompt) => {
|
||||
return {
|
||||
content: message.content,
|
||||
role: message.role,
|
||||
};
|
||||
}),
|
||||
secretkey: GetRepositorySecretKey(),
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user