Skip to content

Commit

Permalink
add bing chat button
Browse files Browse the repository at this point in the history
  • Loading branch information
teticio committed Aug 29, 2023
1 parent 68dad03 commit 6f82f5e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Jupyter Stack Trace

[![Github Actions Status](https://github.com/teticio/jupyter-stack-trace/workflows/Build/badge.svg)](https://github.com/teticio/jupyter-stack-trace/actions/workflows/build.yml)
A JupyterLab extension to jump to the line in the file of the stack trace.
A JupyterLab extension to jump to the line in the file of the stack trace, search Google for the error in Stack Overflow, or ask Bing Chat for help.

(Migrated from https://github.com/teticio/nbextension-gotoerror to JupyterLab and Jupyter Notebook 7.)

One of the disadvantages of working with Jupyter Notebooks is that they can be very difficult to debug when something goes wrong deep down in a stack trace. This extension allows you to click on any of the items in the stack trace and opens up the relevant file at the line where the error occured. A button is also added which searches Google for the error in Stack Overflow.
One of the disadvantages of working with Jupyter Notebooks is that they can be very difficult to debug when something goes wrong deep down in a stack trace. This extension allows you to click on any of the items in the stack trace and opens up the relevant file at the line where the error occurred. Buttons are also added which search Google for the error in Stack Overflow, or ask Bing Chat for help (for this to work, you must be logged into Bing).

## Requirements

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyter-stack-trace",
"version": "0.1.1",
"version": "0.1.2",
"description": "A JupyterLab extension to jump to the line in the file of the stack trace.",
"keywords": [
"jupyter",
Expand Down
36 changes: 27 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,40 @@ const plugin: JupyterFrontEndPlugin<void> = {
outputs.forEach((output: IOutput) => {
if (output.output_type === 'error') {
const stackTrace: string[] = (output.traceback as string[]) ?? [];
const searchText = escape(
// eslint-disable-next-line no-control-regex
stackTrace[stackTrace.length - 1].replace(/\x1b\[(.*?)([@-~])/g, '')
const escapedStackTraces = stackTrace.map(item =>
escape(
// eslint-disable-next-line no-control-regex
item.replace(/\x1b\[(.*?)([@-~])/g, '')
)
);
const url =

const stackOverflowUrl =
'https://google.com/search?q=' +
searchText +
escapedStackTraces[escapedStackTraces.length - 1] +
'+site:stackoverflow.com';
const stackOverflowButton =
'<button class="stack-trace-btn" onclick="window.open(\'' +
stackOverflowUrl +
"', '_blank');\">Search Stack Overflow</button>";
const bingChatUrl =
'https://www.bing.com/search?iscopilotedu=1&sendquery=1&q=' +
escape('Please help me with the following error:\n') +
escapedStackTraces.join('%0A');
const bingButton =
'<button class="stack-trace-btn" onclick="window.open(\'' +
bingChatUrl +
"', '_blank');\">Ask Bing Chat</button>";
const html =
'<table width="100%"><tr><td style="text-align:left;">' +
stackOverflowButton +
'</td><td style="text-align:right;">' +
bingButton +
'</td></tr></table>';

cell.model.outputs.add({
output_type: 'display_data',
data: {
'text/html':
'<br><button class="stack-trace-stack-overflow-btn" onclick="window.open(\'' +
url +
"', '_blank');\">Search Stack Overflow</button>"
'text/html': html
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ span.ansi-green-fg {
cursor: pointer;
}

.stack-trace-stack-overflow-btn {
.stack-trace-btn {
border: 0;
font-size: 11px;
margin: 0 4px;
Expand All @@ -19,6 +19,6 @@ span.ansi-green-fg {
user-select: none;
}

.stack-trace-stack-overflow-btn:hover {
.stack-trace-btn:hover {
background-color: #e0e0e0;
}

0 comments on commit 6f82f5e

Please sign in to comment.