Skip to content

Commit b1bf868

Browse files
committed
updates based on feedback
1 parent 0675565 commit b1bf868

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@
493493
{
494494
"name": "python_environment_tool",
495495
"displayName": "Get Python Environment Information",
496-
"modelDescription": "Returns the information about the Python environment for the given file or workspace. Information includes environment type, python version, run command and installed packages with versions.",
496+
"modelDescription": "Provides details about the Python environment for a specified file or workspace, including environment type, Python version, run command, and installed packages with their versions.",
497497
"toolReferenceName": "pythonGetEnvironmentInfo",
498498
"tags": [],
499499
"icon": "$(files)",
@@ -514,7 +514,7 @@
514514
{
515515
"name": "python_install_package_tool",
516516
"displayName": "Install Python Package",
517-
"modelDescription": "Installs Python packages in a workspace. You should call this when you want to install packages in the user's environment.",
517+
"modelDescription": "Installs Python packages in the given workspace. Use this tool to install packages in the user's chosen environment.",
518518
"toolReferenceName": "pythonInstallPackage",
519519
"tags": [],
520520
"icon": "$(package)",
@@ -531,7 +531,7 @@
531531
},
532532
"workspacePath": {
533533
"type": "string",
534-
"description": "The path to the Python workspace to identify which environment to install packages in."
534+
"description": "Path to Python workspace that determines the environment for package installation."
535535
}
536536
},
537537
"required": [

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
107107

108108
context.subscriptions.push(
109109
registerCompletionProvider(envManagers),
110-
registerTools('python_environment_tool', new GetEnvironmentInfoTool(api)),
110+
registerTools('python_environment_tool', new GetEnvironmentInfoTool(api, envManagers)),
111111
registerTools('python_install_package_tool', new InstallPackageTool(api)),
112112
commands.registerCommand('python-envs.viewLogs', () => outputChannel.show()),
113113
commands.registerCommand('python-envs.refreshManager', async (item) => {

src/features/copilotTools.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ import {
99
Uri,
1010
} from 'vscode';
1111
import {
12+
EnvironmentManager,
1213
PythonCommandRunConfiguration,
1314
PythonEnvironment,
1415
PythonEnvironmentExecutionInfo,
16+
PythonEnvironmentManagementApi,
1517
PythonPackageGetterApi,
1618
PythonPackageManagementApi,
1719
PythonProjectEnvironmentApi,
1820
} from '../api';
1921
import { createDeferred } from '../common/utils/deferred';
22+
import { EnvironmentManagers } from '../internal.api';
2023

2124
export interface IResourceReference {
2225
resourcePath?: string;
@@ -33,7 +36,10 @@ interface EnvironmentInfo {
3336
* A tool to get the information about the Python environment.
3437
*/
3538
export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceReference> {
36-
constructor(private readonly api: PythonProjectEnvironmentApi & PythonPackageGetterApi) {}
39+
constructor(
40+
private readonly api: PythonProjectEnvironmentApi & PythonPackageGetterApi,
41+
private readonly envManagers: EnvironmentManagers,
42+
) {}
3743
/**
3844
* Invokes the tool to get the information about the Python environment.
3945
* @param options - The invocation options containing the file path.
@@ -79,13 +85,14 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
7985

8086
// get the environment type or manager if type is not available
8187
try {
82-
envInfo.type =
83-
environment.envId.managerId?.split(':')[1] || environment.envId.managerId || 'cannot be determined';
88+
const managerId = environment.envId.managerId;
89+
const manager = this.envManagers.getEnvironmentManager(managerId);
90+
envInfo.type = manager?.name || 'cannot be determined';
8491
} catch {
8592
envInfo.type = environment.envId.managerId || 'cannot be determined';
8693
}
8794

88-
// refresh and get packages
95+
// TODO: remove refreshPackages here eventually once terminal isn't being used as a fallback
8996
await this.api.refreshPackages(environment);
9097
const installedPackages = await this.api.getPackages(environment);
9198
if (!installedPackages || installedPackages.length === 0) {
@@ -126,12 +133,17 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
126133

127134
function BuildEnvironmentInfoContent(envInfo: EnvironmentInfo): LanguageModelTextPart {
128135
// Create a formatted string that looks like JSON but preserves comments
136+
let envTypeStr: string = `This environment is managed by ${envInfo.type} environment manager. Use the install tool to install packages into this environment.`;
137+
138+
if (envInfo.type === 'system') {
139+
envTypeStr =
140+
'System pythons are pythons that ship with the OS or are installed globally. These python installs may be used by the OS for running services and core functionality. Confirm with the user before installing packages into this environment, as it can lead to issues with any services on the OS';
141+
}
129142
const content = `{
130-
// type of python environment; sys means it is the system python
131-
"environmentType": ${JSON.stringify(envInfo.type)},
143+
"environmentType": ${JSON.stringify(envTypeStr)},
132144
// python version of the environment
133145
"pythonVersion": ${JSON.stringify(envInfo.version)},
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.
146+
// Use this command to run python script or code in the terminal.
135147
"runCommand": ${JSON.stringify(envInfo.runCommand)},
136148
// installed python packages and their versions if know in the format <name> (<version>), empty array is returned if no packages are installed.
137149
"packages": ${JSON.stringify(Array.isArray(envInfo.packages) ? envInfo.packages : envInfo.packages, null, 2)}
@@ -198,9 +210,7 @@ export class InstallPackageTool implements LanguageModelTool<IInstallPackageInpu
198210
await this.api.installPackages(environment, parameters.packageList);
199211
const resultMessage = `Successfully installed ${packagePlurality}: ${parameters.packageList.join(', ')}`;
200212

201-
// Refresh packages after installation to update the package view
202-
//TODO: do I want the await?
203-
await this.api.refreshPackages(environment);
213+
204214

205215
deferredReturn.resolve({
206216
content: [new LanguageModelTextPart(resultMessage)],

0 commit comments

Comments
 (0)