Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Jupyter Coder

This plugin is still in development. To test it, clone this repository first.
Currently it only supports OPENAI code completion.
Currently it supports the native jupyter mode of starcoder and Open AI completion API.

## Installation
```bash
git clone this_repo
git clone https://github.com/bigcode-project/jupytercoder.git
```

Open chrome://extensions/ in your browser and enable developer mode. Then click on "Load unpacked" and select the folder where you cloned this repository.
Then click on the extension icon to enable it, you will need to enter the bigcode model endpoint url.
Open chrome://extensions/ in your browser and enable developer mode.
![devmode](https://user-images.githubusercontent.com/6381544/236060575-1fbb4024-165d-491f-8ae6-450c50b7a66d.png)

Then click on "Load unpacked" and select the folder where you cloned this repository.
![unpack](https://user-images.githubusercontent.com/6381544/236060695-c432a612-bfeb-4708-909a-f1bb8a64f732.png)

Then click on the extension icon to enable it, you will need to enter the bigcode model endpoint url https://api-inference.huggingface.co/models/bigcode/starcoder/ and your hf readonlys api key. Click save to activate this mode.
![image](https://user-images.githubusercontent.com/6381544/236060887-5c7fd3b1-d5f7-4b86-8282-8925ed867825.png)

## Demo
```bash
Expand Down
23 changes: 16 additions & 7 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function sendToOtherService(code) {
}

const prompt = code.replace(/\u200B/g, '')
console.log(JSON.stringify(prompt));
const response = await fetch(url, {
method: "POST",
headers: {
Expand All @@ -99,17 +100,17 @@ async function sendToOtherService(code) {
inputs: prompt,
stream: false,
parameters: {
return_full_text: false
return_full_text: false,
stop: ["<jupyter_output>"]
}
})
})
const data = await response.json();

if (/^\n/.test(data)) {
data = data.replace(/^\n/, '');
}
// 格式处理成可以输出到notebook的字符串
return data[0].generated_text;
const suggestion = data[0].generated_text;

// remove end token <jupyter_output> if exists
return removeJupyterOutput(suggestion)
}


Expand Down Expand Up @@ -225,7 +226,7 @@ function getCellContentTextRequiredForOpenAI(activeCell) {
}

// Iterate through the last 3 cells before the active cell
const startIndex = activeCellIndex - 3 < 0 ? 0 : activeCellIndex - 3;
const startIndex = 0;
for (let i = startIndex; i <= activeCellIndex; i++) {
if(i == activeCellIndex){
codeContent += leftContext
Expand Down Expand Up @@ -308,7 +309,15 @@ function extractTextFromCell(cell) {
return content_str;
}

function removeJupyterOutput(str) {
const jupyterOutput = '<jupyter_output>';

if (str.endsWith(jupyterOutput)) {
return str.slice(0, -jupyterOutput.length);
}

return str;
}

// 开始等待动画,有30s等待时间,如果等待时间过了,出现“error”字体,返回两个值如下,接收:"const [animationInterval, animationElement] = startWaitingAnimation(activeCall)"
// 1. animationInterval(interval, 动画计时器),可使用clearInterval(animationInterval)消除动画, 每次请求完毕必须要关掉
Expand Down
1,014 changes: 1,014 additions & 0 deletions examples/denoisingwav_2_wavelet_2d.ipynb

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions examples/starcoder_gpu_usage.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "3aa18388",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "50ed5565",
"metadata": {},
"source": [
"read the csv usage_df.csv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0997b28d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "25867be0",
"metadata": {},
"source": [
"plot the daily usage of month 2022-03"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7fed4a1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9dd0a765",
"metadata": {},
"source": [
"Calculate the average monthly usage and plot the data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0e304b0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7e4b2e2",
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}