forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
More specific llm tools #25072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
More specific llm tools #25072
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0b08580
More specific llm tools
DonJayamanne 2ee1e03
Updates
DonJayamanne 8ceea71
updates
DonJayamanne f2777c5
Updates
DonJayamanne 6a42167
Updates
DonJayamanne bd14f1a
Updates
DonJayamanne 596245b
Updates
DonJayamanne 93ba097
Merge branch 'main' into don/diplomatic-mink
DonJayamanne f88d704
Fix test failures
DonJayamanne abfb605
Updates
DonJayamanne a653a6e
updates
DonJayamanne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
CancellationError, | ||
CancellationToken, | ||
l10n, | ||
LanguageModelTextPart, | ||
LanguageModelTool, | ||
LanguageModelToolInvocationOptions, | ||
LanguageModelToolInvocationPrepareOptions, | ||
LanguageModelToolResult, | ||
PreparedToolInvocation, | ||
} from 'vscode'; | ||
import { PythonExtension } from '../api/types'; | ||
import { IServiceContainer } from '../ioc/types'; | ||
import { ICodeExecutionService } from '../terminals/types'; | ||
import { TerminalCodeExecutionProvider } from '../terminals/codeExecution/terminalCodeExecution'; | ||
import { getEnvDisplayName, getEnvironmentDetails, raceCancellationError } from './utils'; | ||
import { resolveFilePath } from './utils'; | ||
import { traceError } from '../logging'; | ||
import { ITerminalHelper } from '../common/terminal/types'; | ||
import { IDiscoveryAPI } from '../pythonEnvironments/base/locator'; | ||
|
||
export interface IResourceReference { | ||
resourcePath?: string; | ||
} | ||
|
||
export class GetExecutableTool implements LanguageModelTool<IResourceReference> { | ||
private readonly terminalExecutionService: TerminalCodeExecutionProvider; | ||
private readonly terminalHelper: ITerminalHelper; | ||
public static readonly toolName = 'get_python_executable'; | ||
constructor( | ||
private readonly api: PythonExtension['environments'], | ||
private readonly serviceContainer: IServiceContainer, | ||
private readonly discovery: IDiscoveryAPI, | ||
) { | ||
this.terminalExecutionService = this.serviceContainer.get<TerminalCodeExecutionProvider>( | ||
ICodeExecutionService, | ||
'standard', | ||
); | ||
this.terminalHelper = this.serviceContainer.get<ITerminalHelper>(ITerminalHelper); | ||
} | ||
async invoke( | ||
options: LanguageModelToolInvocationOptions<IResourceReference>, | ||
token: CancellationToken, | ||
): Promise<LanguageModelToolResult> { | ||
const resourcePath = resolveFilePath(options.input.resourcePath); | ||
|
||
try { | ||
const message = await getEnvironmentDetails( | ||
resourcePath, | ||
this.api, | ||
this.terminalExecutionService, | ||
this.terminalHelper, | ||
undefined, | ||
token, | ||
); | ||
return new LanguageModelToolResult([new LanguageModelTextPart(message)]); | ||
} catch (error) { | ||
if (error instanceof CancellationError) { | ||
throw error; | ||
} | ||
traceError('Error while getting environment information', error); | ||
const errorMessage: string = `An error occurred while fetching environment information: ${error}`; | ||
return new LanguageModelToolResult([new LanguageModelTextPart(errorMessage)]); | ||
} | ||
} | ||
|
||
async prepareInvocation?( | ||
options: LanguageModelToolInvocationPrepareOptions<IResourceReference>, | ||
token: CancellationToken, | ||
): Promise<PreparedToolInvocation> { | ||
const resourcePath = resolveFilePath(options.input.resourcePath); | ||
const envName = await raceCancellationError(getEnvDisplayName(this.discovery, resourcePath, this.api), token); | ||
return { | ||
invocationMessage: envName | ||
? l10n.t('Fetching Python executable information for {0}', envName) | ||
: l10n.t('Fetching Python executable information'), | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will disable listPythonPackages for now