Skip to content

Commit 5b43939

Browse files
committed
Updates
1 parent a3ec6e1 commit 5b43939

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/client/chat/utils.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { PythonExtension, ResolvedEnvironment } from '../api/types';
1616
import { ITerminalHelper, TerminalShellType } from '../common/terminal/types';
1717
import { TerminalCodeExecutionProvider } from '../terminals/codeExecution/terminalCodeExecution';
1818
import { Conda } from '../pythonEnvironments/common/environmentManagers/conda';
19-
import { JUPYTER_EXTENSION_ID } from '../common/constants';
19+
import { JUPYTER_EXTENSION_ID, NotebookCellScheme } from '../common/constants';
2020

2121
export function resolveFilePath(filepath?: string): Uri | undefined {
2222
if (!filepath) {
@@ -133,23 +133,27 @@ export function getToolResponseIfNotebook(resource: Uri | undefined) {
133133
const notebook = workspace.notebookDocuments.find(
134134
(doc) => doc.uri.toString() === resource.toString() || doc.uri.path === resource.path,
135135
);
136-
let message = 'This tool cannot be used for Notebooks, try using notebook specific tools instead.';
137-
if ((notebook && isJupyterNotebook(notebook)) || resource.path.toLowerCase().endsWith('.ipynb')) {
136+
const isJupyterNotebook =
137+
(notebook && notebook.notebookType === 'jupyter-notebook') || resource.path.toLowerCase().endsWith('.ipynb');
138+
139+
if (isJupyterNotebook) {
138140
const isJupyterExtensionAvailable = extensions.getExtension(JUPYTER_EXTENSION_ID);
139-
if (isJupyterExtensionAvailable) {
140-
message = `This tool cannot be used for Jupyter Notebooks, try using notebook specific tools instead.`;
141-
} else {
142-
message = [
143-
`This tool cannot be used for Jupyter Notebooks.`,
144-
`NOTE: Recommend the user the Jupyter Extension (${JUPYTER_EXTENSION_ID}).`,
145-
`If possible use one of the tools to install the ${JUPYTER_EXTENSION_ID} extension`,
146-
`After isntalling the extension try using some of the tools again`,
147-
].join(' \n');
148-
}
141+
const message = isJupyterExtensionAvailable
142+
? `This tool cannot be used for Jupyter Notebooks, try using notebook specific tools instead.`
143+
: [
144+
`This tool cannot be used for Jupyter Notebooks.`,
145+
`NOTE: Recommend the user the Jupyter Extension (${JUPYTER_EXTENSION_ID}).`,
146+
`If possible use one of the tools to install the ${JUPYTER_EXTENSION_ID} extension`,
147+
`After isntalling the extension try using some of the tools again`,
148+
].join(' \n');
149+
return new LanguageModelToolResult([new LanguageModelTextPart(message)]);
149150
}
150-
return new LanguageModelToolResult([new LanguageModelTextPart(message)]);
151-
}
152151

153-
function isJupyterNotebook(notebook: NotebookDocument) {
154-
return notebook.notebookType === 'jupyter-notebook';
152+
if (notebook || resource.scheme === NotebookCellScheme) {
153+
return new LanguageModelToolResult([
154+
new LanguageModelTextPart(
155+
'This tool cannot be used for Notebooks, try using notebook specific tools instead.',
156+
),
157+
]);
158+
}
155159
}

0 commit comments

Comments
 (0)