Skip to content

Commit

Permalink
🐛 Replace all default args if any provider args set (#153)
Browse files Browse the repository at this point in the history
- Prevent default args passed to incompatible models when user is
setting a custom provider

---------

Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 authored Dec 12, 2024
1 parent f766dc1 commit 29af6b5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
18 changes: 14 additions & 4 deletions vscode/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ export class AnalyzerClient {
: !Extension.getInstance(this.extContext).isProductionMode;
}

protected buildModelProviderConfig() {
const config = vscode.workspace.getConfiguration("konveyor.kai");
const userProviderArgs = getConfigKaiProviderArgs();
const providerArgs = userProviderArgs || config.get<object>("providerArgs");

const modelProviderSection = {
provider: getConfigKaiProviderName(),
args: providerArgs,
};
return modelProviderSection;
}

public async initialize(): Promise<void> {
if (!this.rpcConnection) {
vscode.window.showErrorMessage("RPC connection is not established.");
Expand All @@ -184,10 +196,8 @@ export class AnalyzerClient {
root_path: vscode.workspace.workspaceFolders![0].uri.fsPath,
log_level: getConfigLogLevel(),
log_dir_path: this.kaiDir,
model_provider: {
provider: getConfigKaiProviderName(),
args: getConfigKaiProviderArgs(),
},
model_provider: this.buildModelProviderConfig(),

file_log_level: getConfigLogLevel(),
demo_mode: this.isDemoMode(),
cache_dir: "",
Expand Down
33 changes: 31 additions & 2 deletions vscode/src/utilities/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,37 @@ export function getConfigKaiProviderName(): string {
return getConfigValue<string>("kai.providerName") || "ChatIBMGenAI";
}

export function getConfigKaiProviderArgs(): object {
return getConfigValue<object>("kai.providerArgs") || {};
export function getConfigKaiProviderArgs(): object | undefined {
const config = vscode.workspace.getConfiguration("konveyor.kai");
const providerArgsConfig = config.inspect<object>("providerArgs");

if (!providerArgsConfig) {
console.log("No configuration found for providerArgs.");
return undefined;
}

const userDefinedValue =
providerArgsConfig.globalValue !== undefined ||
providerArgsConfig.workspaceValue !== undefined ||
providerArgsConfig.workspaceFolderValue !== undefined;

if (userDefinedValue) {
if (providerArgsConfig.workspaceFolderValue) {
console.log("Using workspaceFolder providerArgs:", providerArgsConfig.workspaceFolderValue);
return providerArgsConfig.workspaceFolderValue;
}
if (providerArgsConfig.workspaceValue) {
console.log("Using workspace providerArgs:", providerArgsConfig.workspaceValue);
return providerArgsConfig.workspaceValue;
}
if (providerArgsConfig.globalValue) {
console.log("Using global providerArgs:", providerArgsConfig.globalValue);
return providerArgsConfig.globalValue;
}
}

console.log("No user overrides for providerArgs. Using defaults from package.json.");
return undefined;
}

export function getConfigKaiDemoMode(): boolean {
Expand Down

0 comments on commit 29af6b5

Please sign in to comment.