Skip to content

Commit

Permalink
AAP-32429: VS Code Extension: Remove custom_prompt fields from Settin…
Browse files Browse the repository at this point in the history
…gs page (#1558)
  • Loading branch information
manstis authored Oct 2, 2024
1 parent 225e0d6 commit 4dff89c
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 251 deletions.
16 changes: 0 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,22 +644,6 @@
"type": "string",
"markdownDescription": "Model ID to override your organization's default model. This setting is only applicable to commercial users with an Ansible Lightspeed seat assignment.",
"order": 4
},
"ansible.lightspeed.playbookGenerationCustomPrompt": {
"scope": "resource",
"type": "string",
"markdownDescription": "Custom Prompt for Playbook generation.",
"pattern": "^$|^.*{goal}.*{outline}.*|.*{outline}.*{goal}.*$",
"patternErrorMessage": "The prompt must contain placeholders for both '{goal}' and '{outline}'.",
"order": 5
},
"ansible.lightspeed.playbookExplanationCustomPrompt": {
"scope": "resource",
"type": "string",
"markdownDescription": "Custom Prompt for Playbook explanation.",
"pattern": "^$|^.*{playbook}.*$",
"patternErrorMessage": "The prompt must contain a placeholder for '{playbook}'.",
"order": 6
}
}
},
Expand Down
13 changes: 0 additions & 13 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,6 @@ export class LightSpeedAPI {
return {} as ExplanationResponseParams;
}
try {
const customPrompt =
lightSpeedManager.settingsManager.settings.lightSpeedService
.playbookExplanationCustomPrompt;
if (customPrompt && customPrompt.length > 0) {
inputData.customPrompt = customPrompt;
}
const requestData = {
...inputData,
metadata: { ansibleExtensionVersion: this._extensionVersion },
Expand Down Expand Up @@ -342,13 +336,6 @@ export class LightSpeedAPI {
return {} as GenerationResponseParams;
}
try {
const customPrompt =
lightSpeedManager.settingsManager.settings.lightSpeedService
.playbookGenerationCustomPrompt;
if (customPrompt && customPrompt.length > 0) {
inputData.customPrompt = customPrompt;
}

const requestData = {
...inputData,
metadata: { ansibleExtensionVersion: this._extensionVersion },
Expand Down
7 changes: 0 additions & 7 deletions src/features/lightspeed/playbookExplanation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ export const playbookExplanation = async (extensionUri: vscode.Uri) => {
markdown = response.content;
if (markdown.length === 0) {
markdown = "### No explanation provided.";
const customPrompt =
lightSpeedManager.settingsManager.settings.lightSpeedService
.playbookExplanationCustomPrompt ?? "";
if (customPrompt.length > 0) {
markdown +=
"\n\nYou may want to consider amending your custom prompt.";
}
}
const html_snippet = marked.parse(markdown) as string;
currentPanel.setContent(html_snippet, true);
Expand Down
2 changes: 0 additions & 2 deletions src/interfaces/lightspeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export interface ISuggestionDetails {

export interface GenerationRequestParams {
text: string;
customPrompt?: string;
outline?: string;
generationId: string;
createOutline: boolean;
Expand All @@ -157,7 +156,6 @@ export interface GenerationResponseParams {

export interface ExplanationRequestParams {
content: string;
customPrompt?: string;
explanationId: string;
}

Expand Down
17 changes: 1 addition & 16 deletions test/mockLightspeedServer/explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function explanations(
res: any,
) {
const playbook = req.body.content;
const customPrompt = req.body.customPrompt;
const explanationId = req.body.explanationId
? req.body.explanationId
: uuidv4();
Expand Down Expand Up @@ -39,18 +38,8 @@ export function explanations(
});
}

// Special case to replicate a broken custom prompt
if (customPrompt && customPrompt === "custom prompt broken") {
logger.info("Returning 400. Custom prompt is invalid");
return res.status(400).send({
code: "validation",
message: "invalid",
detail: { customPrompt: "custom prompt is invalid" },
});
}

// cSpell: disable
let content = `
const content = `
## Playbook Overview and Structure
This playbook creates an Azure Virtual Network (VNET) with the name "VNET_1"
Expand Down Expand Up @@ -94,10 +83,6 @@ the following parameters:
`;
// cSpell: enable

if (customPrompt) {
content += "\nCustom prompt explanation.";
}

return res.send({
content,
format,
Expand Down
15 changes: 0 additions & 15 deletions test/mockLightspeedServer/generations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export function generations(
res: any,
) {
const text = req.body.text;
const customPrompt = req.body.customPrompt;
const createOutline = req.body.createOutline;
const generationId = req.body.generationId ? req.body.generationId : uuidv4();
const wizardId = req.body.wizardId;
Expand Down Expand Up @@ -47,16 +46,6 @@ export function generations(
});
}

// Special case to replicate a broken custom prompt
if (customPrompt && customPrompt === "custom prompt broken") {
logger.info("Returning 400. Custom prompt is invalid");
return res.status(400).send({
code: "validation",
message: "invalid",
detail: { customPrompt: "custom prompt is invalid" },
});
}

// cSpell: disable
let outline: string | undefined = `1. Create VNET named VNET_1
2. Create VNET named VNET_2
Expand Down Expand Up @@ -109,10 +98,6 @@ export function generations(
outline += "\n4. Some extra step.";
}

if (customPrompt) {
outline += "\n5. Custom prompt step.";
}

return res.send({
playbook,
outline,
Expand Down
182 changes: 0 additions & 182 deletions test/ui-test/lightspeedUiTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ export function lightspeedUIAssetsTest(): void {
.undefined;
let text = await outlineList.getText();
expect(text.includes("Create virtual network peering")).to.be.true;
expect(text.includes("Custom prompt step")).not.to.be.true;

// Verify the prompt is displayed as a static text
const prompt = await webView.findWebElement(
Expand Down Expand Up @@ -630,70 +629,6 @@ export function lightspeedUIAssetsTest(): void {
}
});

it("Playbook generation webview works as expected (fast path, custom prompt)", async function () {
// Execute only when TEST_LIGHTSPEED_URL environment variable is defined.
if (process.env.TEST_LIGHTSPEED_URL) {
// Set Playbook generation custom prompt
settingsEditor = await workbench.openSettings();
await updateSettings(
settingsEditor,
"ansible.lightspeed.playbookGenerationCustomPrompt",
"custom prompt {goal}, {outline}",
);
await workbench.executeCommand("View: Close All Editor Groups");

// Open playbook generation webview.
await workbench.executeCommand(
"Ansible Lightspeed: Playbook generation",
);
await sleep(2000);
const webView = await new WebView();
expect(webView, "webView should not be undefined").not.to.be.undefined;
await webView.switchToFrame(5000);
expect(
webView,
"webView should not be undefined after switching to its frame",
).not.to.be.undefined;

// Set input text and invoke summaries API
const textArea = await webView.findWebElement(
By.xpath("//vscode-text-area"),
);
expect(textArea, "textArea should not be undefined").not.to.be
.undefined;
const submitButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='submit-button']"),
);
expect(submitButton, "submitButton should not be undefined").not.to.be
.undefined;
//
// Note: Following line should succeed, but fails for some unknown reasons.
//
// expect((await submitButton.isEnabled()), "submit button should be disabled by default").is.false;
await textArea.sendKeys("Create an azure network.");
expect(
await submitButton.isEnabled(),
"submit button should be enabled now",
).to.be.true;
await submitButton.click();
await sleep(1000);

// Verify outline output and text edit
const outlineList = await webView.findWebElement(
By.xpath("//ol[@id='outline-list']"),
);
expect(outlineList, "An ordered list should exist.").to.be.not
.undefined;
const text = await outlineList.getText();
expect(text.includes("Custom prompt step")).to.be.true;

await webView.switchBack();
await workbench.executeCommand("View: Close All Editor Groups");
} else {
this.skip();
}
});

it("Playbook explanation webview works as expected", async function () {
if (process.env.TEST_LIGHTSPEED_URL) {
const folder = "lightspeed";
Expand Down Expand Up @@ -728,7 +663,6 @@ export function lightspeedUIAssetsTest(): void {
expect(mainDiv, "mainDiv should not be undefined").not.to.be.undefined;
const text = await mainDiv.getText();
expect(text.includes("Playbook Overview and Structure")).to.be.true;
expect(text.includes("Custom prompt explanation")).not.to.be.true;

await webView.switchBack();
await workbench.executeCommand("View: Close All Editor Groups");
Expand Down Expand Up @@ -854,112 +788,6 @@ export function lightspeedUIAssetsTest(): void {
}
});

it("Playbook explanation webview works as expected, no explanation, custom prompt", async function () {
if (process.env.TEST_LIGHTSPEED_URL) {
const folder = "lightspeed";
const file = "playbook_explanation_none.yml";
const filePath = getFixturePath(folder, file);

// Set Playbook generation custom prompt
settingsEditor = await workbench.openSettings();
await updateSettings(
settingsEditor,
"ansible.lightspeed.playbookExplanationCustomPrompt",
"custom prompt {playbook}",
);
await workbench.executeCommand("View: Close All Editor Groups");

// Open file in the editor
await VSBrowser.instance.openResources(filePath);

// Open playbook explanation webview.
await workbench.executeCommand(
"Explain the playbook with Ansible Lightspeed",
);
await sleep(2000);

// Locate the playbook explanation webview
const webView = (await new EditorView().openEditor(
"Explanation",
1,
)) as WebView;
expect(webView, "webView should not be undefined").not.to.be.undefined;
await webView.switchToFrame(5000);
expect(
webView,
"webView should not be undefined after switching to its frame",
).not.to.be.undefined;

// Find the main div element of the webview and verify the expected text is found.
const mainDiv = await webView.findWebElement(
By.xpath("//div[contains(@class, 'playbookGeneration') ]"),
);
expect(mainDiv, "mainDiv should not be undefined").not.to.be.undefined;
const text = await mainDiv.getText();
expect(text.includes("No explanation provided")).to.be.true;
expect(
text.includes("You may want to consider amending your custom prompt"),
).to.be.true;

await webView.switchBack();
await workbench.executeCommand("View: Close All Editor Groups");
} else {
this.skip();
}
});

it("Playbook explanation webview works as expected, custom prompt", async function () {
if (process.env.TEST_LIGHTSPEED_URL) {
const folder = "lightspeed";
const file = "playbook_4.yml";
const filePath = getFixturePath(folder, file);

// Set Playbook generation custom prompt
settingsEditor = await workbench.openSettings();
await updateSettings(
settingsEditor,
"ansible.lightspeed.playbookExplanationCustomPrompt",
"custom prompt {playbook}",
);
await workbench.executeCommand("View: Close All Editor Groups");

// Open file in the editor
await VSBrowser.instance.openResources(filePath);

// Open playbook explanation webview.
await workbench.executeCommand(
"Explain the playbook with Ansible Lightspeed",
);
await sleep(2000);

// Locate the playbook explanation webview
const webView = (await new EditorView().openEditor(
"Explanation",
1,
)) as WebView;
expect(webView, "webView should not be undefined").not.to.be.undefined;
await webView.switchToFrame(5000);
expect(
webView,
"webView should not be undefined after switching to its frame",
).not.to.be.undefined;

// Find the main div element of the webview and verify the expected text is found.
const mainDiv = await webView.findWebElement(
By.xpath("//div[contains(@class, 'playbookGeneration') ]"),
);
expect(mainDiv, "mainDiv should not be undefined").not.to.be.undefined;
const text = await mainDiv.getText();
expect(text.includes("Playbook Overview and Structure")).to.be.true;
expect(text.includes("Custom prompt explanation")).to.be.true;

await webView.switchBack();
await workbench.executeCommand("View: Close All Editor Groups");
} else {
this.skip();
}
});

after(async function () {
if (process.env.TEST_LIGHTSPEED_URL) {
settingsEditor = await workbench.openSettings();
Expand All @@ -973,16 +801,6 @@ export function lightspeedUIAssetsTest(): void {
"ansible.lightspeed.URL",
"https://c.ai.ansible.redhat.com",
);
await updateSettings(
settingsEditor,
"ansible.lightspeed.playbookGenerationCustomPrompt",
"",
);
await updateSettings(
settingsEditor,
"ansible.lightspeed.playbookExplanationCustomPrompt",
"",
);
}
});
});
Expand Down

0 comments on commit 4dff89c

Please sign in to comment.