Skip to content

[doc] add tutorial to root readme. #13

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

Merged
merged 1 commit into from
Dec 6, 2023
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ CodeFuse-Query为CodeFuse代码大模型提供了以下数据清洗能力:
- [Gödel查询语言介绍](./doc/4_godelscript_language.md)
- [VSCode开发插件](./doc/5_toolchain.md)

## 教程 (tutorial)
- [在线教程](./tutorial/README.md)

## 目录结构说明
- `cli`:命令行工具的入口,提供统一的命令行接口,调用其他模块完成具体功能
- `language`:各语言的数据化核心(extractor)和数据建模(lib)。关于开放度的问题,请参见《关于开源范围的一些说明》章节
Expand Down
47 changes: 22 additions & 25 deletions tutorial/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
## CodeFuse-Query使用教程

### 使用Github Codespaces 来体验CodeFuse-Query分析能力
我们编写了Jupyter Notebook形式的教程,你可以在 CodeFuse-Query 预置好的 Github Codespace 中打开,在阅读的同时执行代码,观察执行结果,也可以修改代码观察反馈,亲手体验 CodeFuse-Query 强大的自定义分析能力。

### Jupyter kernel for CodeFuse-query 介绍
#### 扩展阅读
- [Github Codespaces](https://github.com/features/codespaces)
- [Jupyter Notebook](https://jupyter.org/)

Jupyter kernel for CodeFuse-query 是 Jupyter 的一个特定内核,它为 Jupyter 环境提供了与 CodeFuse-query 相关的交互式功能。该内核允许用户在 Jupyter Notebook 中编写和执行 Godel 脚本,用于抽取、查询代码数据。此外,它还支持编写 Python 代码,以便对查询到的数据进行更深入的数据可视化和数据后处理操作。这里我们使用这个内核编写 Jupyter Notebook,用来进行 CodeFuse-Query 教程的学习和实践。
#### 体验步骤
1. 创建 Codespaces。依次点击项目首页的 Code -> Codespaces,在当前分支创建一个 Codespaces。
2. 创建后,打开该 Codespaces,加载完成后,切换至项目 tutorial/notebook 目录下。
3. 选择示例下的 Jupyter Notebook 分析教程,即ipynb文件。
4. 在右上角的 "选择内核" 弹出框中,依次选择 "Jupyter Kernel..." -> "Godel Kernel"。
5. 开始体验。

#### 步骤
### Jupyter kernel for CodeFuse-Query 介绍
Jupyter kernel for CodeFuse-Query(以下称 Godel Kernel) 是 Jupyter 的一个特定内核,它为 Jupyter 环境提供了与 CodeFuse-Query 相关的交互式功能。该内核提供以下能力:
- 支持在 Jupyter Notebook 中编写和执行 Godel 脚本。
- 支持 `%%python` 命令编写并执行 Python 代码,以便对查询到的数据进行更深入的数据可视化和数据后处理操作。
- 支持自定义COREF db路径。
- 转储Jupyter cell的输出结果到特定文件。

- 创建 Codespaces,依次点击 Code -> Codespaces,在当前分支创建一个 Codespaces
- 创建后,打开该 Codespaces,加载完成后,切换至项目 tutorial/notebook 目录下
- 选择示例下的 Jupyter Notebook 分析教程,即可开始体验
关于这些功能的详细介绍请看下一章节《Godel Kernel 用法介绍》。

#### 注意

在打开 Jupyter 页面之后,如果是第一次加载容器,你还需要配置教程所使用的 `Jupyter kernel for CodeFuse-query`。在右上角的 "选择内核" 弹出框中,依次选择 "Jupyter Kernel..." -> "Godel Kernel"。

#### Kernel 用法
#### Godel Kernel 用法介绍
##### 设置要查询的 COREF database

使用 `%db /path/to/db` 魔法命令来设置COREF db路径,内核会读取这个值来进行query查询,比如:
使用 `%db /path/to/db` 魔法命令来设置COREF db路径,内核会读取这个值来进行查询,比如:

```bash
%db ./db
```

> tips: 还可以用`!`来运行一些有用的bash命令,比如查看Sparrow CLI是否存在
> tips: 还可以用`!`来运行一些有用的bash命令,比如查看 CodeFuse-Query CLI(sparrow)是否存在

```rust
!which sparrow
```

##### Godel 查询
##### 运行 Godel 查询

设置好db路径后可以直接写Godel脚本,Jupyter kernel会创建临时文件来保存当前运行的Godel脚本并调用`sparrow query run`命令来进行查询,结果返回以HTML格式显示:
设置好db路径后可以直接写Godel脚本,Godel kernel会创建临时文件来保存当前运行的Godel脚本并调用`sparrow query run`命令来进行查询,结果返回以HTML格式显示:


```rust
Expand All @@ -54,16 +61,6 @@ Jupyter kernel for CodeFuse-query 是 Jupyter 的一个特定内核,它为 Jup

可以通过 `%%save_to` cell魔法命令保存**上一次运行成功**的 query 结果到一个JSON文件,具体用法:
```bash
%%save_to PATH - save the query result to a JSON file.

This cell magic will save the Sparrow query result to a file.

Example:
%%save_to /path/to/file.json
```

比如:
```bash
%%save_to ./query.json
```

Expand Down