Add README.md for vscode-extension

pull/4/head
Qinkai 2 years ago
parent a04a890c49
commit d8f84994c1

@ -0,0 +1,98 @@
![codegeex_logo](https://lfs.aminer.cn/misc/wangshan/pretrain/codegeex/codegeex_logo.png)
🌐 <a href="https://github.com/THUDM/CodeGeeX/blob/main/vscode-extension/README_zh.md" target="_blank">中文</a>
We introduce CodeGeeX, a large-scale multilingual code generative model with 13 billion parameters, pretrained on a large code corpus of more than 20 programming languages. With CodeGeeX, we can generate codes by only providing natural language descriptions, complete any code snippet, or translate codes to other programming languages, etc. CodeGeeX also provides customizable features (**Prompt Mode**) to help you configure your own programming assistant. Happy coding!
For more information, please check out our [Homepage](https://models.aminer.cn/codegeex/) and [GitHub repo](https://github.com/THUDM/CodeGeeX).
Please kindly let us know if you encounter any problem or have any suggestion, via [codegeex@aminer.cn](mailto:codegeex@aminer.cn).
## Basic Usage
Install the extension and enable it globally. There are three modes of usage:
- **Stealth mode**: Keep CodeGeeX activated, it will start generating codes when you stop writing (the icon at the bottom of VSCode starts spinning). When the generated code is shown in gray, just press ``Tab`` to insert the generated codes.
- **Interactive mode**: Press ``Ctrl+Enter`` to activate the interactive mode, CodeGeeX will generate ``X`` candidates and show them in the right panel (``X`` can be modified in extension settings ``Candidate Num``). Then, select the best candidate by clicking on it.
- **Prompt mode**: Select codes to be used as input, then press ``Alt/Option+t`` to trigger the prompt mode. It will show a list of pre-defined prompt templates and choose one to generate codes with your input. This mode is fully customizable, you can add your own templates in the extension settings ``Prompt Templates``.
## Privacy
We highly respect the privacy of your code. The code is only used as the input of CodeGeeX to assist your programming. At the first time of usage, we will ask if you agree to share the generated code only for research purpose (**disabled** by default).
## Guidance
Please see the details and examples for how to use the three modes in CodeGeeX:
### Stealth mode
In this mode, CodeGeeX will start generating codes when you stop writing (the icon at the bottom of VSCode starts spinning). When the generated code is shown in gray, just press ``Tab`` to insert the generated codes. You can also press ``Alt/Option+[`` or ``]`` to change between candidates. Change the number of candidates in the extension settings ``Candidate Num`` (more candidates will slow down the generation speed). **Note**: The generation always starts at the current position of your cursor, thus if you modify the code before the generation is finished, it will probably cause bugs. We keep working on making the generation faster.
![image](stealth_mode.gif)
### Interactive mode
In this mode, press ``Ctrl+Enter`` to generate codes and visualize the candidates in another panel. Then, click on the best candidate to insert the generated codes to the current position of cursor.
![image](interactive_mode.gif)
### Prompt mode
In this mode, you can add extra prompts to the input and implement some cool features, like code explanation, summarization, generation with specific coding style, and more. The principle behind is the few-shot ability of CodeGeeX. When you provide a few examples as extra prompts in the input, CodeGeeX will imitate what are done by these examples and generate codes accordingly. For example, you can give an example that explains each line of code. Select the code you want to explain, then press ``Alt/Option+t`` to trigger the prompt mode. It will show a list of pre-defined prompt templates and choose the ``explanation`` to generate codes with your input. Magically, the codes will be explained line by line.
![image](prompt_mode.gif)
The template of the above example looks like the following, which contains ``[Example code]``, ``<INPUT>``, ``[Example code with explanation]`` and ``[Explanation head]``. ``<INPUT>`` is where the selected code will be inserted. ``<INPUT0:1>`` means the first line of your input (which is used here to ensure the same function will be explained). When you use the prompt mode, CodeGeeX will combine your input with the template and use them all as the input to generate codes.
```python
# language: Python
def sum_squares(lst):
sum = 0
for i in range(len(lst)):
if i % 3 == 0:
lst[i] = lst[i]**2
elif i % 4 == 0:
lst[i] = lst[i]**3
sum += lst[i]
return sum
<INPUT>
# Explain the code line by line
def sum_squares(lst):
# initialize sum
sum = 0
# loop through the list
for i in range(len(lst)):
# if the index is a multiple of 3
if i % 3 == 0:
# square the entry
lst[i] = lst[i]**2
# if the index is a multiple of 4
elif i % 4 == 0:
# cube the entry
lst[i] = lst[i]**3
# add the entry to the sum
sum += lst[i]
# return the sum
return sum
# Explain the code line by line
<INPUT:0,1>
```
And here is another example for python docstring generation
```python
def add_binary(a, b):
'''
Returns the sum of two decimal numbers in binary digits.
Parameters:
a (int): A decimal integer
b (int): Another decimal integer
Returns:
binary_sum (str): Binary string of the sum of a and b
'''
binary_sum = bin(a+b)[2:]
return binary_sum
<INPUT>
```
The templates are fully customizable, you can add your own templates in the extension settings ``Prompt Templates``. ``key`` is the name that you want to show in the list of templates, ``value`` is the path to the template file (``.txt``, ``.py``, ``.h``, etc). Try this feature and write your own templates, you can make the generated codes follow your coding style, generate with a specific function name, or add a specific comment, etc.

@ -0,0 +1,103 @@
![codegeex_logo](https://lfs.aminer.cn/misc/wangshan/pretrain/codegeex/codegeex_logo.png)
🌐 <a href="https://github.com/THUDM/CodeGeeX/blob/main/vscode-extension/README.md" target="_blank">English</a>
CodeGeeX是一个具有130亿参数的多编程语言代码生成预训练模型使用超过二十种编程语言训练得到。基于CodeGeeX开发的插件可以实现通过描述生成代码、补全代码、代码翻译等一系列功能。CodeGeeX同样提供可以定制的**提示模式Prompt Mode**构建专属的编程助手。Happy Coding
VS Code插件市场搜索"codegeex"即可免费使用更多关于CodeGeeX信息请见我们的[主页](https://models.aminer.cn/codegeex/) and [GitHub仓库](https://github.com/THUDM/CodeGeeX)。
如使用过程中遇到问题或有任何改进意见,欢迎发送邮件到[codegeex@aminer.cn](mailto:codegeex@aminer.cn)反馈!
## 基本用法
安装插件并全局激活CodeGeeX有以下三种使用模式
- **隐匿模式**: 保持CodeGeeX处于激活状态当您停止输入时会从当前光标处开始生成右下角CodeGeeX图标转圈表示正在生成。 生成完毕之后会以灰色显示,按``Tab``即可插入生成结果。
- **交互模式**: 按``Ctrl+Enter``激活交互模式CodeGeeX将生成``X``个候选,并显示在右侧窗口中(``X`` 数量可以在设置的``Candidate Num``中修改)。 点击候选代码上方的``use code``即可插入。
- **提示模式**: 选择需要作为输入的代码,按``Alt/Option+t``触发提示模式,会显示预定义模板列表,选择其中一个模板,即可将代码插入到模板中进行生成。 这个模式高度自定义,可以在设置中 ``Prompt Templates``修改或添加模板内容,为模型加入额外的提示。
## 隐私声明
我们高度尊重用户代码的隐私代码仅用来辅助编程。在您第一次使用时我们会询问您是否同意将生成的代码用于研究用途帮助CodeGeeX变得更好该选项默认**关闭**)。
## 使用指南
以下是CodeGeeX几种模式的详细用法
###隐匿模式
在该模式中CodeGeeX将在您停止输入时从光标处开始生成右下角CodeGeeX图标转圈表示正在生成。生成完毕之后会以灰色显示按``Tab``即可插入生成结果。 在生成多个候选的情况下,可以使用``Alt/Option+[`` 或 ``]``在几个候选间进行切换。可以在设置中改变``Candidate Num``(增加个数会导致生成速度相对变慢)。**注意**生成总是从当前光标位置开始如果您在生成结束前移动光标位置可能会导致一些bugs。我们正在努力使生成速度变得更快以提升用户体验。
![image](stealth_mode.gif)
### 交互模式
在该模式中,按``Ctrl+Enter``激活交互模式CodeGeeX将生成``X``个候选,并显示在右侧窗口中(``X`` 数量可以在设置的``Candidate Num``中修改)。 点击候选代码上方的``use code``即可插入结果到为当前光标位置。
![image](interactive_mode.gif)
### 提示模式
在该模式中您可以在输入中添加额外的提示来实现一些有趣的功能包括并不限于代码解释、概括、以特定风格生成等。该模式的原理是利用了CodeGeeX强大的少样本生成能力。当您在输入中提供一些例子时CodeGeeX会模仿这些例子并实现相应的功能。比如您可以自定义模板中提供一段逐行解释代码的例子。选择您想要解释的代码按``Alt/Option+t``触发提示模式,选择您写好的模板(如``explanation``CodeGeeX就会解释您输入的代码。以下我们会详细介绍如何制作模板。
![image](prompt_mode.gif)
上述例子中的模板如下图所示,由``[示例代码]``, ``<INPUT>``, ``[带解释的示例代码]`` and ``[输出函数头]`` 。``<INPUT>``表示您选中的代码将会插入的位置。 ``<INPUT:0,1>`` 这一句用来保证模型解释的是同一个函数。当使用提示模式时CodeGeeX会将您选择的代码插入到<INPUT>部分)和模板代码相结合,一起作为模型的输入。
```python
# language: Python
def sum_squares(lst):
sum = 0
for i in range(len(lst)):
if i % 3 == 0:
lst[i] = lst[i]**2
elif i % 4 == 0:
lst[i] = lst[i]**3
sum += lst[i]
return sum
<INPUT>
# Explain the code line by line
def sum_squares(lst):
# initialize sum
sum = 0
# loop through the list
for i in range(len(lst)):
# if the index is a multiple of 3
if i % 3 == 0:
# square the entry
lst[i] = lst[i]**2
# if the index is a multiple of 4
elif i % 4 == 0:
# cube the entry
lst[i] = lst[i]**3
# add the entry to the sum
sum += lst[i]
# return the sum
return sum
# Explain the code line by line
<INPUT:0,1>
```
以下是另一个Python文档字符串生成的例子CodeGeeX在您写新函数时会模仿该注释的格式
```python
def add_binary(a, b):
'''
Returns the sum of two decimal numbers in binary digits.
Parameters:
a (int): A decimal integer
b (int): Another decimal integer
Returns:
binary_sum (str): Binary string of the sum of a and b
'''
binary_sum = bin(a+b)[2:]
return binary_sum
<INPUT>
```
模板文件是高度自定义化的,您可以将自定义模板添加到插件设置中的``Prompt Templates``中。 ``key``表示模板的名字, ``value``是模板文件的路径(可以是您电脑上的任一路径,``.txt``, ``.py``, ``.h``, 等格式文件均可。通过该功能您可以让CodeGeeX生成具有特定风格或功能的代码快尝试定义自己的专属模板吧

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 572 KiB

Loading…
Cancel
Save