Skip to content
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

Code completion for jupyter lab/notebook using StarCoder #378

Closed
wants to merge 78 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
e8a0f4f
add bigcode readme.md
Wzixiao Aug 17, 2023
7132c25
fix readmd image bug
Wzixiao Aug 17, 2023
4e7763f
Improve method in readme
Wzixiao Aug 17, 2023
25251cd
Improve method in readme
Wzixiao Aug 17, 2023
d6e5038
add merge plan
Wzixiao Aug 17, 2023
f85b05c
Continue to improve readme.md
Wzixiao Aug 17, 2023
d9e630c
add changed code color to readme
Wzixiao Aug 18, 2023
10165e9
add save data to laocl plan
Wzixiao Aug 18, 2023
b97fc85
move md Images to local ./mdImages
Wzixiao Aug 18, 2023
7691d2b
fix logic bug in readme
Wzixiao Aug 18, 2023
78730d3
fix logic bug in readme
Wzixiao Aug 19, 2023
9d25bf6
refactor readme
Wzixiao Aug 23, 2023
c0899c4
Complete the preliminary structure
Wzixiao Aug 23, 2023
db8980b
Add dependencies on readme
Wzixiao Aug 23, 2023
7c2d49e
A simple version that completes the continuation
Wzixiao Aug 23, 2023
d7ca78f
Merge pull request #3 from Wzixiao/request
Wzixiao Aug 23, 2023
de3f65e
perfect readme
Wzixiao Aug 23, 2023
b3f5c88
Merge pull request #4 from Wzixiao/request
Wzixiao Aug 23, 2023
ae8087b
perfect readme
Wzixiao Aug 23, 2023
2e7b074
Merge pull request #5 from Wzixiao/request
Wzixiao Aug 23, 2023
0e43347
Added functionality to animate on request
Wzixiao Aug 23, 2023
1502810
add animation to bigcode-zh.md
Wzixiao Aug 23, 2023
84da159
Merge pull request #6 from Wzixiao/animation
Wzixiao Aug 23, 2023
3c5a6f5
fix request loading animation bug
chenJuZ Aug 23, 2023
22aa6a1
remove irrelevant code
Wzixiao Aug 24, 2023
2414664
Merge pull request #7 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
9d9412d
format code
Wzixiao Aug 24, 2023
2c6b302
Merge pull request #8 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
eca890a
fix get cell error
Wzixiao Aug 24, 2023
7c7fe46
Merge pull request #9 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
f6654ae
Fixed issue where no code would appear after pressing enter
Wzixiao Aug 24, 2023
3341761
Merge pull request #10 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
61ba755
Fixed issue where no code would appear after pressing enter
Wzixiao Aug 24, 2023
18b1841
Merge pull request #11 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
01cc1fa
Change use other shortcut keys to determine the way to enter the method
Wzixiao Aug 24, 2023
6959e00
Merge pull request #12 from Wzixiao/shortcut-keys
Wzixiao Aug 24, 2023
b682dbc
Fix bug when formatting prompt
Wzixiao Aug 24, 2023
a7fbdab
Merge pull request #13 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
c3eed45
Fixed that when the code is displayed and the current cell is empty, …
Wzixiao Aug 24, 2023
00a8c1a
Merge pull request #14 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
7e9a22f
When reloading the animation, the original animation dom should be re…
Wzixiao Aug 24, 2023
6107997
Merge pull request #15 from Wzixiao/fix-bug
Wzixiao Aug 24, 2023
938047d
add debug log
Wzixiao Aug 25, 2023
5e11485
add hot key on request
Wzixiao Aug 25, 2023
aa1e3d3
Merge pull request #16 from Wzixiao/debug-log
Wzixiao Aug 25, 2023
916510b
Merge pull request #17 from Wzixiao/hotkey
Wzixiao Aug 25, 2023
80021b0
Improve the hotkey context, including log, readme, etc.
Wzixiao Aug 25, 2023
ec6919f
Merge pull request #18 from Wzixiao/hotkey
Wzixiao Aug 25, 2023
cbcee9f
add examples
Wzixiao Aug 25, 2023
c4ce981
[200~Fixed a hint error~
Wzixiao Aug 25, 2023
ddbe16f
Merge pull request #19 from Wzixiao/examples
Wzixiao Aug 25, 2023
95942cf
Replace 'continue writing' with 'code complement'
Wzixiao Aug 27, 2023
0440066
Replace 'Add a part function docstring
Wzixiao Aug 27, 2023
77e46e3
add docstring
Wzixiao Aug 28, 2023
247b187
Merge pull request #20 from Wzixiao/file_name
Wzixiao Aug 28, 2023
771c52a
update bigcode icon
Wzixiao Aug 28, 2023
390fad5
Merge pull request #21 from Wzixiao/icon
Wzixiao Aug 28, 2023
2e8c611
add 'Enable code completion' function
Wzixiao Sep 3, 2023
9e007a5
Merge pull request #22 from Wzixiao/select-monitor
Wzixiao Sep 3, 2023
d17070f
Improve some docstring
Wzixiao Sep 3, 2023
758d14b
Merge pull request #23 from Wzixiao/docstring
Wzixiao Sep 3, 2023
1db503c
add token limit
Wzixiao Sep 3, 2023
106cbd3
Merge pull request #24 from Wzixiao/token-limit
Wzixiao Sep 3, 2023
fa1bc6e
Fix the bug of adding new cells
Wzixiao Sep 3, 2023
b156446
remove garbage output
Wzixiao Sep 3, 2023
21ea03d
Merge pull request #25 from Wzixiao/fix-bug
Wzixiao Sep 3, 2023
a99ebc3
Merge pull request #2 from Wzixiao/code-continue-writing
Wzixiao Sep 3, 2023
b2c17f9
Merge remote-tracking branch 'upstream/main'
Wzixiao Sep 3, 2023
054fc10
Improve readme for code completion
Wzixiao Sep 3, 2023
701d798
Add code completion examples to the readme.md
Wzixiao Sep 3, 2023
4b46ea5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2023
63f719e
change css asking price style
Wzixiao Sep 3, 2023
d38323e
merge remote branch
Wzixiao Sep 3, 2023
90342de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 3, 2023
1bcc70c
change css asking price style
Wzixiao Sep 3, 2023
951a94a
Merge branch 'main' of github.com:Wzixiao/jupyter-ai-bigcode-code-com…
Wzixiao Sep 3, 2023
1f2ad83
Delete incorrectly uploaded files
Wzixiao Sep 9, 2023
d290932
Merge branch 'main' of https://github.com/jupyterlab/jupyter-ai
Wzixiao Sep 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add examples
Wzixiao committed Aug 25, 2023
commit cbcee9f26a72536f9c38d8ebb099a9c8fa0d5936
83 changes: 83 additions & 0 deletions examples/sklearn_digits.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"id": "dcbb2940-4d47-45ac-923a-f80eed1d26f5",
"metadata": {},
"outputs": [],
"source": [
"# load Digits Dataset from sklearn\n"
]
},
{
"cell_type": "markdown",
"id": "f3a60c45-244b-49f2-8527-519c5a2557a6",
"metadata": {},
"source": [
"Print to show there are 1797 images (8 by 8 images for a dimensionality of 64)"
]
},
{
"cell_type": "markdown",
"id": "0c159867-a499-4181-9713-d2558f1a258d",
"metadata": {},
"source": [
"Print to show there are 1797 labels (integers from 0–9)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e216707c-1ea7-446a-ac69-cd013e76b5f2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "fe688a3e-29cb-464d-9eef-7e17ce4b9dee",
"metadata": {},
"source": [
"Showing the Images and the Labels (Digits Dataset)"
]
},
{
"cell_type": "markdown",
"id": "f2f5505f-32b1-4e22-8878-39f20e71335d",
"metadata": {},
"source": [
"This section is really just to show what the images and labels look like. It usually helps to visualize your data to see what you are working with."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4328fb40-b40c-4fde-8ef4-6a5b38c5dd10",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 2 additions & 2 deletions packages/jupyter-ai/src/bigcode/bigcode-continue-writing.ts
Original file line number Diff line number Diff line change
@@ -93,8 +93,8 @@ export const continueWriting = (
console.debug('continueWriting() => state is success, result: ', result);
requestSuccess(app, view, result);
})
.catch(err => {
console.error(err);
.catch(async err => {
console.error(await err);
requestFailed(view);
});

29 changes: 22 additions & 7 deletions packages/jupyter-ai/src/keydown-handler.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import {
} from './bigcode/bigcode-continue-writing';
import { parseKeyboardEventToShortcut } from './utils/keyboard';
import GlobalStore from './contexts/continue-writing-context';
import { CodeEditor } from '@jupyterlab/codeeditor';

// 创建一个软引用集合存放 editor
const mountedEditors = new WeakSet<CodeMirrorEditor>();
@@ -29,6 +30,11 @@ const mountExtension = (
return;
}

// editor 还没有正常的完成初始化
if (!('editor' in editor)) {
return;
}

const view = editor.editor as EditorView;
const tr = view.state.update({
effects: StateEffect.appendConfig.of(extension)
@@ -38,6 +44,20 @@ const mountExtension = (
mountedEditors.add(editor);
};

// 在新增单元格时,editor 可能没有被实例化,所以我们需将挂载事件放在异步队列最低端,以用来保证 editor 实例化完成
const mountEditorWithDelay = (
editor: CodeEditor.IEditor | null,
extension: Extension
) => {
if (editor && editor instanceof CodeMirrorEditor) {
const waitCellInitTimer = setTimeout(() => {
const codeMirrorEditor = editor as CodeMirrorEditor;
mountExtension(codeMirrorEditor, extension);
clearTimeout(waitCellInitTimer);
}, 0);
}
};

const generateKeyDownExtension = (app: JupyterFrontEnd): Extension => {
return Prec.highest(
keymap.of([
@@ -87,7 +107,7 @@ const init = (app: JupyterFrontEnd) => {
const firstCell = content.activeCell;
if (firstCell) {
const firstCellEditor = firstCell.editor as CodeMirrorEditor;
mountExtension(firstCellEditor, extension);
mountEditorWithDelay(firstCellEditor, extension);
}

// 监听选中的 cell 发生变化时
@@ -96,12 +116,7 @@ const init = (app: JupyterFrontEnd) => {
return;
}

// 在新增单元格时,editor 可能没有被实例化,所以我们需将挂载事件放在异步队列最低端,以用来保证 editor 实例化完成
const waitCellInitTimer = setTimeout(() => {
const editor = cell.editor as CodeMirrorEditor;
mountExtension(editor, extension);
clearTimeout(waitCellInitTimer);
}, 0);
mountEditorWithDelay(cell.editor, extension);
});
}
});
11 changes: 9 additions & 2 deletions packages/jupyter-ai/src/utils/bigcode-request.ts
Original file line number Diff line number Diff line change
@@ -64,8 +64,15 @@ export const sendToBigCode = async (
body: JSON.stringify(bodyData)
});

const data = (await response).json();
return data;
const responseResult = await response;
// Check if response status code is in the range 200-299
if (!responseResult.ok) {
return new Promise((resolve, reject) => {
reject(responseResult.json());
});
}

return responseResult.json();
};

export const processCompletionResult = (