Skip to content

Commit b890f41

Browse files
committed
Rename tools
1 parent 9a0129d commit b890f41

File tree

7 files changed

+22
-134
lines changed

7 files changed

+22
-134
lines changed

package.json

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,14 +1465,12 @@
14651465
],
14661466
"languageModelTools": [
14671467
{
1468-
"name": "get_python_environment_info",
1468+
"name": "get_python_environment_details",
14691469
"displayName": "Get Python Environment Info",
1470-
"userDescription": "%python.languageModelTools.get_python_environment_info.userDescription%",
1470+
"userDescription": "%python.languageModelTools.get_python_environment_details.userDescription%",
14711471
"modelDescription": "This tool will retrieve the details of the Python Environment for the specified file or workspace. The details returned include the 1. Type of Environment (conda, venv, etec), 2. Version of Python, 3. List of all installed packages with their versions. ",
14721472
"toolReferenceName": "pythonGetEnvironmentInfo",
1473-
"tags": [
1474-
"ms-python.python"
1475-
],
1473+
"tags": [],
14761474
"icon": "$(files)",
14771475
"canBeReferencedInPrompt": true,
14781476
"inputSchema": {
@@ -1484,18 +1482,17 @@
14841482
},
14851483
"description": "The path to the Python file or workspace to get the environment information for.",
14861484
"required": []
1487-
}
1485+
},
1486+
"when": "!pythonEnvExtensionInstalled"
14881487
},
14891488
{
1490-
"name": "get_python_executable",
1489+
"name": "get_python_executable_details",
14911490
"displayName": "Get Python Executable",
1492-
"userDescription": "%python.languageModelTools.get_python_executable.userDescription%",
1491+
"userDescription": "%python.languageModelTools.get_python_executable_details.userDescription%",
14931492
"modelDescription": "This tool will retrieve the details of the Python Environment for the specified file or workspace. ALWAYS use this tool before executing any Python command in the terminal. This tool returns the details of how to construct the fully qualified path and or command including details such as arguments required to run Python in a terminal. Note: Instead of executing `python --version` or `python -c 'import sys; print(sys.executable)'`, use this tool to get the Python executable path to replace the `python` command. E.g. instead of using `python -c 'import sys; print(sys.executable)'`, use this tool to build the command `conda run -n <env_name> -c 'import sys; print(sys.executable)'`.",
14941493
"toolReferenceName": "pythonExecutableCommand",
1495-
"tags": [
1496-
"ms-python.python"
1497-
],
1498-
"icon": "$(files)",
1494+
"tags": [],
1495+
"icon": "$(snake)",
14991496
"canBeReferencedInPrompt": true,
15001497
"inputSchema": {
15011498
"type": "object",
@@ -1506,40 +1503,16 @@
15061503
},
15071504
"description": "The path to the Python file or workspace to get the executable information for. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace.",
15081505
"required": []
1509-
}
1510-
},
1511-
{
1512-
"name": "list_python_packages",
1513-
"displayName": "List Python Packages",
1514-
"userDescription": "%python.languageModelTools.list_python_packages.userDescription%",
1515-
"modelDescription": "This tool will retrieve the list of all installed packages installed in a Python Environment for the specified file or workspace. ALWAYS use this tool instead of executing Python command in the terminal to fetch the list of installed packages. WARNING: Packages installed can change over time, hence the list of packages returned by this tool may not be accurate. Use this tool to get the list of installed packages in a Python environment.",
1516-
"toolReferenceName": "listPythonPackages",
1517-
"tags": [
1518-
"ms-python.python"
1519-
],
1520-
"icon": "$(files)",
1521-
"canBeReferencedInPrompt": true,
1522-
"inputSchema": {
1523-
"type": "object",
1524-
"properties": {
1525-
"resourcePath": {
1526-
"type": "string"
1527-
}
1528-
},
1529-
"description": "The path to the Python file or workspace to list the packages. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace.",
1530-
"required": []
15311506
},
1532-
"when": "false"
1507+
"when": "!pythonEnvExtensionInstalled"
15331508
},
15341509
{
1535-
"name": "install_python_package",
1510+
"name": "install_python_packages",
15361511
"displayName": "Install Python Package",
1537-
"userDescription": "%python.languageModelTools.python_install_package.userDescription%",
1512+
"userDescription": "%python.languageModelTools.install_python_packages.userDescription%",
15381513
"modelDescription": "Installs Python packages in the given workspace. Use this tool to install packages in the user's chosen environment.",
15391514
"toolReferenceName": "pythonInstallPackage",
1540-
"tags": [
1541-
"ms-python.python"
1542-
],
1515+
"tags": [],
15431516
"icon": "$(package)",
15441517
"canBeReferencedInPrompt": true,
15451518
"inputSchema": {

package.nls.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"python.command.python.startTerminalREPL.title": "Start Terminal REPL",
3-
"python.languageModelTools.get_python_environment_info.userDescription": "Get information for a Python Environment, such as Type, Version, Packages, and more.",
4-
"python.languageModelTools.python_install_package.userDescription": "Installs Python packages in a Python Environment.",
5-
"python.languageModelTools.get_python_executable.userDescription": "Get executable info for a Python Environment",
6-
"python.languageModelTools.list_python_packages.userDescription": "Get a list of all installed packages in a Python Environment.",
3+
"python.languageModelTools.get_python_environment_details.userDescription": "Get information for a Python Environment, such as Type, Version, Packages, and more.",
4+
"python.languageModelTools.install_python_packages.userDescription": "Installs Python packages in a Python Environment.",
5+
"python.languageModelTools.get_python_executable_details.userDescription": "Get executable info for a Python Environment",
76
"python.command.python.startNativeREPL.title": "Start Native Python REPL",
87
"python.command.python.createEnvironment.title": "Create Environment...",
98
"python.command.python.createNewFile.title": "New Python File",

src/client/chat/getExecutableTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface IResourceReference {
2929
export class GetExecutableTool implements LanguageModelTool<IResourceReference> {
3030
private readonly terminalExecutionService: TerminalCodeExecutionProvider;
3131
private readonly terminalHelper: ITerminalHelper;
32-
public static readonly toolName = 'get_python_executable';
32+
public static readonly toolName = 'get_python_executable_details';
3333
constructor(
3434
private readonly api: PythonExtension['environments'],
3535
private readonly serviceContainer: IServiceContainer,

src/client/chat/getPythonEnvTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
3131
private readonly pythonExecFactory: IPythonExecutionFactory;
3232
private readonly processServiceFactory: IProcessServiceFactory;
3333
private readonly terminalHelper: ITerminalHelper;
34-
public static readonly toolName = 'get_python_environment_info';
34+
public static readonly toolName = 'get_python_environment_details';
3535
constructor(
3636
private readonly api: PythonExtension['environments'],
3737
private readonly serviceContainer: IServiceContainer,

src/client/chat/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { IExtensionContext } from '../common/types';
99
import { DisposableStore } from '../common/utils/resourceLifecycle';
1010
import { ENVS_EXTENSION_ID } from '../envExt/api.internal';
1111
import { IDiscoveryAPI } from '../pythonEnvironments/base/locator';
12-
import { ListPythonPackagesTool } from './listPackagesTool';
1312
import { GetExecutableTool } from './getExecutableTool';
1413
import { GetEnvironmentInfoTool } from './getPythonEnvTool';
1514

@@ -36,12 +35,6 @@ export function registerTools(
3635
new GetExecutableTool(environmentsApi, serviceContainer, discoverApi),
3736
),
3837
);
39-
ourTools.add(
40-
lm.registerTool(
41-
ListPythonPackagesTool.toolName,
42-
new ListPythonPackagesTool(environmentsApi, serviceContainer, discoverApi),
43-
),
44-
);
4538
ourTools.add(
4639
lm.registerTool(
4740
InstallPackagesTool.toolName,

src/client/chat/installPackagesTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface IInstallPackageArgs {
2626
}
2727

2828
export class InstallPackagesTool implements LanguageModelTool<IInstallPackageArgs> {
29-
public static readonly toolName = 'install_python_package';
29+
public static readonly toolName = 'install_python_packages';
3030
constructor(
3131
private readonly api: PythonExtension['environments'],
3232
private readonly serviceContainer: IServiceContainer,

src/client/chat/listPackagesTool.ts

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import {
5-
CancellationError,
6-
CancellationToken,
7-
l10n,
8-
LanguageModelTextPart,
9-
LanguageModelTool,
10-
LanguageModelToolInvocationOptions,
11-
LanguageModelToolInvocationPrepareOptions,
12-
LanguageModelToolResult,
13-
PreparedToolInvocation,
14-
Uri,
15-
} from 'vscode';
16-
import { PythonExtension, ResolvedEnvironment } from '../api/types';
17-
import { IServiceContainer } from '../ioc/types';
4+
import { CancellationToken, Uri } from 'vscode';
5+
import { ResolvedEnvironment } from '../api/types';
186
import { IProcessService, IProcessServiceFactory, IPythonExecutionFactory } from '../common/process/types';
19-
import { getEnvDisplayName, isCondaEnv, raceCancellationError } from './utils';
20-
import { resolveFilePath } from './utils';
7+
import { isCondaEnv, raceCancellationError } from './utils';
218
import { parsePipList } from './pipListUtils';
229
import { Conda } from '../pythonEnvironments/common/environmentManagers/conda';
2310
import { traceError } from '../logging';
24-
import { IDiscoveryAPI } from '../pythonEnvironments/base/locator';
25-
26-
export interface IResourceReference {
27-
resourcePath?: string;
28-
}
29-
30-
export class ListPythonPackagesTool implements LanguageModelTool<IResourceReference> {
31-
private readonly pythonExecFactory: IPythonExecutionFactory;
32-
private readonly processServiceFactory: IProcessServiceFactory;
33-
public static readonly toolName = 'list_python_packages';
34-
constructor(
35-
private readonly api: PythonExtension['environments'],
36-
private readonly serviceContainer: IServiceContainer,
37-
private readonly discovery: IDiscoveryAPI,
38-
) {
39-
this.pythonExecFactory = this.serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory);
40-
this.processServiceFactory = this.serviceContainer.get<IProcessServiceFactory>(IProcessServiceFactory);
41-
}
42-
43-
async invoke(
44-
options: LanguageModelToolInvocationOptions<IResourceReference>,
45-
token: CancellationToken,
46-
): Promise<LanguageModelToolResult> {
47-
const resourcePath = resolveFilePath(options.input.resourcePath);
48-
49-
try {
50-
// environment
51-
const envPath = this.api.getActiveEnvironmentPath(resourcePath);
52-
const environment = await raceCancellationError(this.api.resolveEnvironment(envPath), token);
53-
if (!environment) {
54-
throw new Error('No environment found for the provided resource path: ' + resourcePath?.fsPath);
55-
}
56-
57-
const message = await getPythonPackagesResponse(
58-
environment,
59-
this.pythonExecFactory,
60-
this.processServiceFactory,
61-
resourcePath,
62-
token,
63-
);
64-
return new LanguageModelToolResult([new LanguageModelTextPart(message)]);
65-
} catch (error) {
66-
if (error instanceof CancellationError) {
67-
throw error;
68-
}
69-
return new LanguageModelToolResult([
70-
new LanguageModelTextPart(`An error occurred while fetching environment information: ${error}`),
71-
]);
72-
}
73-
}
74-
75-
async prepareInvocation?(
76-
options: LanguageModelToolInvocationPrepareOptions<IResourceReference>,
77-
token: CancellationToken,
78-
): Promise<PreparedToolInvocation> {
79-
const resourcePath = resolveFilePath(options.input.resourcePath);
80-
const envName = await raceCancellationError(getEnvDisplayName(this.discovery, resourcePath, this.api), token);
81-
return {
82-
invocationMessage: envName
83-
? l10n.t('Listing packages in {0}', envName)
84-
: l10n.t('Fetching Python environment information'),
85-
};
86-
}
87-
}
8811

8912
export async function getPythonPackagesResponse(
9013
environment: ResolvedEnvironment,

0 commit comments

Comments
 (0)