Skip to content

Commit

Permalink
✨ Add configuration for getSolution params
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 committed Dec 11, 2024
1 parent fb9f899 commit 7f72e18
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 11 deletions.
3 changes: 3 additions & 0 deletions vscode/media/walkthroughs/configure-get-Solution-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Configure Get Solution Params

The Konveyor extension allows users to configure the parameters for the Get Solution command. Max_depth, max_priority, and max_iterations are the parameters that can be configured. The Get Solution command is used to get the solution for the given project based on the analysis results.
39 changes: 33 additions & 6 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@
"icon": "$(arrow-left)",
"category": "diffEditor",
"title": "Apply Selection"
},
{
"command": "konveyor.configureGetSolutionParams",
"title": "Configure getSolution Parameters",
"category": "Konveyor",
"icon": "$(gear)"
}
],
"submenus": [
Expand Down Expand Up @@ -504,12 +510,7 @@
},
"konveyor.kai.providerArgs": {
"type": "object",
"default": {
"model_id": "meta-llama/llama-3-1-70b-instruct",
"parameters": {
"max_new_tokens": 2048
}
},
"default": {},
"description": "Kai provider arguments",
"scope": "window"
},
Expand All @@ -518,6 +519,21 @@
"default": "",
"description": "Generative AI Key",
"scope": "window"
},
"konveyor.kai.getSolutionMaxPriority": {
"type": "number",
"default": 0,
"description": "Maximum priority for the getSolution request"
},
"konveyor.kai.getSolutionMaxDepth": {
"type": "number",
"default": 0,
"description": "Max depth for the getSolution request"
},
"konveyor.kai.getSolutionMaxIterations": {
"type": "number",
"default": 1,
"description": "Max iterations for the getSolution request"
}
}
},
Expand Down Expand Up @@ -570,6 +586,17 @@
"markdown": "media/walkthroughs/gen-ai.md"
}
},
{
"id": "configure-get-solution",
"title": "Configure Get Solution Parameters",
"description": "Set up getSolution parameters\n[Configure Get Solution Parameters](command:konveyor.configureGetSolutionParams)",
"completionEvents": [
"onCommand:konveyor.configureGetSolutionParams"
],
"media": {
"markdown": "media/walkthroughs/get-solution-params.md"
}
},
{
"id": "start-server",
"title": "Start Server",
Expand Down
23 changes: 18 additions & 5 deletions vscode/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
getConfigKaiRpcServerPath,
getConfigAnalyzerPath,
getGenAiKey,
getConfigMaxDepth,
getConfigMaxIterations,
getConfigMaxPriority,
} from "../utilities";

export class AnalyzerClient {
Expand Down Expand Up @@ -344,19 +347,28 @@ export class AnalyzerClient {

const enhancedIncident = {
...incident,
ruleset_name: violation.category || "default_ruleset", // You may adjust the default value as necessary
violation_name: violation.description || "default_violation", // You may adjust the default value as necessary
ruleset_name: violation.category || "default_ruleset",
violation_name: violation.description || "default_violation",
};

const maxPriority = getConfigMaxPriority();
const maxDepth = getConfigMaxDepth();
const maxIterations = getConfigMaxIterations();

try {
this.outputChannel.appendLine(`Sending 'getCodeplanAgentSolution' with:
max_priority: ${maxPriority},
max_depth: ${maxDepth},
max_iterations: ${maxIterations}`);

const response: SolutionResponse = await this.rpcConnection!.sendRequest(
"getCodeplanAgentSolution",
{
file_path: "",
incidents: [enhancedIncident],
max_priority: 0,
max_depth: 0,
max_iterations: 1,
max_priority: maxPriority,
max_depth: maxDepth,
max_iterations: maxIterations,
},
);

Expand All @@ -368,6 +380,7 @@ export class AnalyzerClient {
this.outputChannel.appendLine(`Error during getSolution: ${err.message}`);
vscode.window.showErrorMessage("Get solution failed. See the output channel for details.");
}

this.fireSolutionStateChange(false);
}

Expand Down
54 changes: 54 additions & 0 deletions vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
getConfigLabelSelector,
updateLabelSelector,
updateGenAiKey,
updateGetSolutionMaxDepth,
updateGetSolutionMaxIterations,
updateGetSolutionMaxPriority,
} from "./utilities/configuration";
import { runPartialAnalysis } from "./analysis";
import { IncidentTypeItem } from "./issueView";
Expand Down Expand Up @@ -403,6 +406,57 @@ const commandsMap: (state: ExtensionState) => {
"konveyor.diffView.applySelection": applyBlock,
"konveyor.diffView.applySelectionInline": applyBlock,
"konveyor.partialAnalysis": async (filePaths: string[]) => runPartialAnalysis(state, filePaths),
"konveyor.configureGetSolutionParams": async () => {
const maxPriorityInput = await window.showInputBox({
prompt: "Enter max_priority for getSolution",
placeHolder: "0",
validateInput: (value) => {
return isNaN(Number(value)) ? "Please enter a valid number" : null;
},
});

if (maxPriorityInput === undefined) {
return;
}

const maxPriority = Number(maxPriorityInput);

const maxDepthInput = await window.showInputBox({
prompt: "Enter max_depth for getSolution",
placeHolder: "0",
validateInput: (value) => {
return isNaN(Number(value)) ? "Please enter a valid number" : null;
},
});

if (maxDepthInput === undefined) {
return;
}

const maxDepth = Number(maxDepthInput);

const maxIterationsInput = await window.showInputBox({
prompt: "Enter max_iterations for getSolution",
placeHolder: "1",
validateInput: (value) => {
return isNaN(Number(value)) ? "Please enter a valid number" : null;
},
});

if (maxIterationsInput === undefined) {
return;
}

const maxIterations = Number(maxIterationsInput);

await updateGetSolutionMaxPriority(maxPriority);
await updateGetSolutionMaxDepth(maxDepth);
await updateGetSolutionMaxIterations(maxIterations);

window.showInformationMessage(
`getSolution parameters updated: max_priority=${maxPriority}, max_depth=${maxDepth}, max_iterations=${maxIterations}`,
);
},
};
};

Expand Down
32 changes: 32 additions & 0 deletions vscode/src/utilities/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,35 @@ export async function updateGenAiKey(
vscode.window.showInformationMessage("Key removed.");
}
}

export function getConfigMaxPriority(): number {
return getConfigValue<number>("kai.getSolutionMaxPriority") || 0;
}

export function getConfigMaxDepth(): number {
return getConfigValue<number>("kai.getSolutionMaxDepth") || 0;
}

export function getConfigMaxIterations(): number {
return getConfigValue<number>("kai.getSolutionMaxIterations") || 1;
}

export async function updateGetSolutionMaxPriority(value: number): Promise<void> {
await updateConfigValue(
"kai.getSolutionMaxPriority",
value,
vscode.ConfigurationTarget.Workspace,
);
}

export async function updateGetSolutionMaxDepth(value: number): Promise<void> {
await updateConfigValue("kai.getSolutionMaxDepth", value, vscode.ConfigurationTarget.Workspace);
}

export async function updateGetSolutionMaxIterations(value: number): Promise<void> {
await updateConfigValue(
"kai.getSolutionMaxIterations",
value,
vscode.ConfigurationTarget.Workspace,
);
}

0 comments on commit 7f72e18

Please sign in to comment.