Skip to content

Commit 0675565

Browse files
committed
updates based on karthik feedback
1 parent 27d3ac5 commit 0675565

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/features/copilotTools.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,35 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
5757
}
5858
const resourcePath: Uri = Uri.file(parameters.resourcePath);
5959

60-
try {
61-
// environment info set to default values
62-
const envInfo: EnvironmentInfo = {
63-
type: 'no type found',
64-
version: 'no version found',
65-
packages: 'no packages found',
66-
runCommand: 'no run command found',
67-
};
60+
// environment info set to default values
61+
const envInfo: EnvironmentInfo = {
62+
type: 'no type found',
63+
version: 'no version found',
64+
packages: 'no packages found',
65+
runCommand: 'no run command found',
66+
};
6867

68+
try {
6969
// environment
7070
const environment: PythonEnvironment | undefined = await this.api.getEnvironment(resourcePath);
7171
if (!environment) {
72-
// Check if the file is a notebook or a notebook cell to throw specific error messages.
73-
if (resourcePath.fsPath.endsWith('.ipynb') || resourcePath.fsPath.includes('.ipynb#')) {
74-
throw new Error('Unable to access Jupyter kernels for notebook cells');
75-
}
7672
throw new Error('No environment found for the provided resource path: ' + resourcePath.fsPath);
7773
}
7874

7975
const execInfo: PythonEnvironmentExecutionInfo = environment.execInfo;
8076
const run: PythonCommandRunConfiguration = execInfo.run;
8177
envInfo.runCommand = run.executable + (run.args && run.args.length > 0 ? ` ${run.args.join(' ')}` : '');
82-
// TODO: check if this is the right way to get type
83-
envInfo.type = environment.envId.managerId.split(':')[1];
8478
envInfo.version = environment.version;
8579

86-
// does this need to be refreshed prior to returning to get any new packages?
80+
// get the environment type or manager if type is not available
81+
try {
82+
envInfo.type =
83+
environment.envId.managerId?.split(':')[1] || environment.envId.managerId || 'cannot be determined';
84+
} catch {
85+
envInfo.type = environment.envId.managerId || 'cannot be determined';
86+
}
87+
88+
// refresh and get packages
8789
await this.api.refreshPackages(environment);
8890
const installedPackages = await this.api.getPackages(environment);
8991
if (!installedPackages || installedPackages.length === 0) {
@@ -99,7 +101,9 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
99101
deferredReturn.resolve({ content: [textPart] });
100102
} catch (error) {
101103
const errorMessage: string = `An error occurred while fetching environment information: ${error}`;
102-
deferredReturn.resolve({ content: [new LanguageModelTextPart(errorMessage)] } as LanguageModelToolResult);
104+
const partialContent = BuildEnvironmentInfoContent(envInfo);
105+
const combinedContent = new LanguageModelTextPart(`${errorMessage}\n\n${partialContent.value}`);
106+
deferredReturn.resolve({ content: [combinedContent] } as LanguageModelToolResult);
103107
}
104108
return deferredReturn.promise;
105109
}
@@ -127,7 +131,7 @@ function BuildEnvironmentInfoContent(envInfo: EnvironmentInfo): LanguageModelTex
127131
"environmentType": ${JSON.stringify(envInfo.type)},
128132
// python version of the environment
129133
"pythonVersion": ${JSON.stringify(envInfo.version)},
130-
// command to run python in this environment, will include command with active environment if applicable
134+
// command to run python in this environment, will include command with active environment if applicable. Opt to use this command to run python in this environment.
131135
"runCommand": ${JSON.stringify(envInfo.runCommand)},
132136
// installed python packages and their versions if know in the format <name> (<version>), empty array is returned if no packages are installed.
133137
"packages": ${JSON.stringify(Array.isArray(envInfo.packages) ? envInfo.packages : envInfo.packages, null, 2)}

0 commit comments

Comments
 (0)