From 450a29b9c6b06a74d2a82376936efa6fdac2299a Mon Sep 17 00:00:00 2001 From: sunshinesmilelk Date: Tue, 26 Nov 2024 15:28:11 +0800 Subject: [PATCH] feat(lab): support guide book --- examples/libro_guide_book.ipynb | 311 +++--------------- examples/libro_guide_book_zh.ipynb | 311 ++++++++++++++++++ .../src/lang/bundle.l10n.en-US.json | 1 + .../src/lang/bundle.l10n.zh-CN.json | 1 + .../src/guide/content-contribution.ts | 50 +++ packages/libro-lab/src/guide/guide-view.tsx | 77 +++++ packages/libro-lab/src/guide/index.less | 8 + packages/libro-lab/src/guide/index.ts | 2 + .../libro-lab/src/guide/libro_guide_book.json | 303 +++++++++++++++++ .../src/guide/libro_guide_book_zh.json | 301 +++++++++++++++++ packages/libro-lab/src/module.tsx | 13 + packages/libro-lab/tsconfig.json | 3 +- 12 files changed, 1118 insertions(+), 263 deletions(-) create mode 100644 examples/libro_guide_book_zh.ipynb create mode 100644 packages/libro-lab/src/guide/content-contribution.ts create mode 100644 packages/libro-lab/src/guide/guide-view.tsx create mode 100644 packages/libro-lab/src/guide/index.less create mode 100644 packages/libro-lab/src/guide/index.ts create mode 100644 packages/libro-lab/src/guide/libro_guide_book.json create mode 100644 packages/libro-lab/src/guide/libro_guide_book_zh.json diff --git a/examples/libro_guide_book.ipynb b/examples/libro_guide_book.ipynb index 6f3c7584..914eac52 100644 --- a/examples/libro_guide_book.ipynb +++ b/examples/libro_guide_book.ipynb @@ -8,9 +8,9 @@ "libroFormatter": "formatter-string" }, "source": [ - "#
✨A Quick Guide to libro✨\n", - "##
🎉🧙🔮 欢迎使用 libro\n", - "**
libro,不只是 notebook,更是一个灵感加速器!**" + "#
✨A Quick Guide to libro✨ \n", + "##
🎉🧙🔮 Welcome to libro \n", + "**
libro, more than just a notebook, it’s an inspiration accelerator!**" ] }, { @@ -20,7 +20,7 @@ "libroFormatter": "formatter-string" }, "source": [ - "**libro 是支持生成式 AI 能力的可定制 notebook 产品方案。提供商业级 notebook 产品的体验,深度集成 AI 能力,可以轻松集成到您的研发环境中,为您构建一流的 AI、数据科学研发方案。让我们用一种有趣的方式带您快速上手,解锁基于 libro 的全新工作体验!**" + "**libro is a customizable notebook solution that supports generative AI capabilities. It offers a commercial-grade notebook experience with deep integration of AI features, allowing for easy integration into your development environment to build top-tier AI and data science solutions. Let us guide you through a fun and engaging way to quickly get started and unlock a whole new work experience with libro!**" ] }, { @@ -30,7 +30,7 @@ "libroFormatter": "formatter-string" }, "source": [ - "### Step 1:开启 Notebook 之门 🔑" + "### Step 1: Unlock the Door to the Notebook 🔑" ] }, { @@ -40,7 +40,7 @@ "libroFormatter": "formatter-string" }, "source": [ - "在终端中运行 `libro generate config ` 生成 ` ~/.libro/libro_config.yaml` 文件,按照如下内容,对 libro 中大模型和数据库相关的配置,并且启用 libro_sql、libro_ai 扩展。赶快试试吧~\n", + "Run `libro generate config` in the terminal to generate the `~/.libro/libro_config.yaml` file. Then, configure the settings for large models and databases in libro, and enable the `libro_sql` and `libro_ai` extensions. Give it a try now! \n", "\n", "```yaml\n", "llm:\n", @@ -54,7 +54,7 @@ " password: \"12345678\"\n", " host: \"127.0.0.1\"\n", " port: 3306\n", - " database: sql_demo\n", + " database: sql_demo.db\n", "\n", "ipython_extensions:\n", " libro_ai: True\n", @@ -69,119 +69,29 @@ "libroFormatter": "formatter-string" }, "source": [ - "### Step 2:SQL Cell,数据界的魔法棒 🪄\n", + "### Step 2: SQL Cell, the Magic Wand of Data 🪄\n", "\n", - "libro 支持使用 SQL Cell 来简化数据库交互,它就像一个对话框,直接对接您的数据库,不需要任何额外工具,数据分析轻松搞定!\n", + "libro supports using SQL Cells to simplify database interactions. It acts like a dialog box that directly connects to your database, without the need for any additional tools—making data analysis a breeze!\n", "\n", - "通过在 libro 中结合 SQL 和 Python,您可以:\n", + "By combining SQL and Python in libro, you can:\n", "\n", - "- 直接查询数据库,快速获取数据,支持把结果保存为 dataframe。\n", - "- 使用 Python 对查询结果进行进一步的处理和可视化。\n", - "- 将 SQL 的强大查询能力与 Notebook 的动态性结合,提升开发效率。\n", + "- Query your database directly to quickly retrieve data and save the results as a dataframe.\n", + "- Use Python to further process and visualize the query results.\n", + "- Leverage the powerful query capabilities of SQL alongside the dynamism of the Notebook to boost development efficiency.\n", "\n", - "赶快试试吧~" + "Give it a try now!" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "12b0e2fa-a4a4-4e17-affb-2dd10ad3cabe", "metadata": { - "execution": { - "shell.execute_reply.end": "2024-11-21T17:06:50.333591Z", - "shell.execute_reply.started": "2024-11-21T17:06:50.308065Z", - "to_execute": "2024-11-21T17:06:50.301Z" - }, + "execution": {}, "libroCellType": "sql", "libroFormatter": "formatter-sql-magic" }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
idnamepricequantitycreated_at
01Laptop999.99102024-11-21 17:06:45
12Smartphone499.99252024-11-21 17:06:45
23Tablet299.99152024-11-21 17:06:45
34Headphones79.99502024-11-21 17:06:45
45Smartwatch199.99202024-11-21 17:06:45
\n", - "
" - ], - "text/plain": [ - " id name price quantity created_at\n", - "0 1 Laptop 999.99 10 2024-11-21 17:06:45\n", - "1 2 Smartphone 499.99 25 2024-11-21 17:06:45\n", - "2 3 Tablet 299.99 15 2024-11-21 17:06:45\n", - "3 4 Headphones 79.99 50 2024-11-21 17:06:45\n", - "4 5 Smartwatch 199.99 20 2024-11-21 17:06:45" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%%sql \n", "{\"result_variable\":\"df_1\",\"db_id\":\"sqlite: sql_demo\",\"sql_script\":\"select * from products\"}" @@ -189,104 +99,13 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "83edeb90-a116-4ed2-b80e-c0a534e365c0", "metadata": { - "execution": { - "shell.execute_reply.end": "2024-11-21T17:07:02.840207Z", - "shell.execute_reply.started": "2024-11-21T17:07:02.820197Z", - "to_execute": "2024-11-21T17:07:02.843Z" - }, + "execution": {}, "libroFormatter": "formatter-string" }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
idnamepricequantitycreated_at
01Laptop999.99102024-11-21 17:06:45
12Smartphone499.99252024-11-21 17:06:45
23Tablet299.99152024-11-21 17:06:45
34Headphones79.99502024-11-21 17:06:45
45Smartwatch199.99202024-11-21 17:06:45
\n", - "
" - ], - "text/plain": [ - " id name price quantity created_at\n", - "0 1 Laptop 999.99 10 2024-11-21 17:06:45\n", - "1 2 Smartphone 499.99 25 2024-11-21 17:06:45\n", - "2 3 Tablet 299.99 15 2024-11-21 17:06:45\n", - "3 4 Headphones 79.99 50 2024-11-21 17:06:45\n", - "4 5 Smartwatch 199.99 20 2024-11-21 17:06:45" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "df_1" ] @@ -298,7 +117,7 @@ "libroFormatter": "formatter-string" }, "source": [ - "### Step 3:AI 助手,开发者的好搭档 🤖" + "### Step 3: AI Assistant, the Perfect Partner for Developers 🤖" ] }, { @@ -308,9 +127,9 @@ "libroFormatter": "formatter-string" }, "source": [ - "#### 错误修复\n", + "#### Error Fixing\n", "\n", - "当 Cell 执行出现报错时,只需一键点击 “Fix with AI” 按钮,助手会自动分析错误并给出修复建议,帮助您快速解决问题,恢复顺利的编程体验。赶快试试修复下面的执行报错吧~\n" + "When a Cell execution encounters an error, simply click the \"Fix with AI\" button, and the assistant will automatically analyze the error and provide repair suggestions to help you quickly resolve the issue and get back to smooth coding. Try fixing the execution error below now!" ] }, { @@ -319,9 +138,9 @@ "id": "549fbd17-9e22-4844-8cb5-dcf006e88338", "metadata": { "execution": { - "shell.execute_reply.end": "2024-11-19T13:04:12.701217Z", - "shell.execute_reply.started": "2024-11-19T13:04:12.452644Z", - "to_execute": "2024-11-19T13:04:12.515Z" + "shell.execute_reply.end": "2024-11-26T06:08:42.651560Z", + "shell.execute_reply.started": "2024-11-26T06:08:42.406610Z", + "to_execute": "2024-11-26T06:08:42.429Z" }, "libroFormatter": "formatter-string" }, @@ -349,9 +168,9 @@ "libroFormatter": "formatter-string" }, "source": [ - "#### AI 对话\n", + "#### AI Chat\n", "\n", - "您可以点击会话按钮 [ 顶部右侧工具栏 / Cell 右侧工具栏 ] 直接与 AI 进行互动,获得与当前代码相关的深入解答和优化建议,提升编程效率。赶快试试与 libro 的 AI 对话吧~" + "You can click the conversation button [ in the top-right toolbar / the right toolbar of the Cell ] to interact directly with the AI, receiving in-depth answers and optimization suggestions related to your current code, enhancing your coding efficiency. Try chatting with libro’s AI now!" ] }, { @@ -361,8 +180,9 @@ "libroFormatter": "formatter-string" }, "source": [ - "#### 代码解释\n", - "您可以点击魔法按钮 [ Cell 右侧工具栏 ] ,libro 帮您理解 Cell 中代码的功能和逻辑,让编程学习变得更加轻松。赶快试试解释下面这段代码吧~" + "#### Code Explanation\n", + "\n", + "You can click the magic button [in the right toolbar of the Cell], and libro will help you understand the functionality and logic of the code in the Cell, making learning to code easier. Try explaining the code below now!" ] }, { @@ -393,8 +213,9 @@ "libroFormatter": "formatter-string" }, "source": [ - "#### 代码优化\n", - "您可以点击魔法按钮 [ Cell 右侧工具栏 ] ,libro 能够分析 Cell 中的代码,并提供优化建议,让您的代码更加高效、可读,提升整体编程体验。赶快试着优化下面的这一段代码吧~" + "#### Code Optimization\n", + "\n", + "You can click the magic button [ in the right toolbar of the Cell ], and libro will analyze the code in the Cell and provide optimization suggestions to make your code more efficient and readable, enhancing your overall programming experience. Try optimizing the code below now!" ] }, { @@ -421,21 +242,17 @@ "libroFormatter": "formatter-string" }, "source": [ - "### Step 4:AI 工作流开发利器💡\n", + "### Step 4: AI Workflow Development Tool 💡\n", "\n", - "Prompt Cell 是一种特殊的 notebook cell,通过这个 cell,用户只需要输入自然语言指令,就可以调用大模型进行推理,得到所需的输出结果。它的出现减少了编写复杂代码的需求,并且可以灵活地融入现有的工作流中。赶快试试下面的例子吧~" + "The Prompt Cell is a special type of notebook cell. With this cell, users only need to input natural language commands to call large models for inference and receive the desired output. It reduces the need for writing complex code and can be seamlessly integrated into existing workflows. Try the example below now!" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "758e3891-bec1-4017-9af6-247634d8ba1c", "metadata": { - "execution": { - "shell.execute_reply.end": "2024-11-21T03:39:24.234639Z", - "shell.execute_reply.started": "2024-11-21T03:39:24.232386Z", - "to_execute": "2024-11-21T03:39:24.277Z" - }, + "execution": {}, "libroFormatter": "formatter-string" }, "outputs": [], @@ -445,27 +262,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "310bf74e-295d-4a31-8a36-7109cac02982", "metadata": { - "execution": { - "shell.execute_reply.end": "2024-11-21T03:39:26.921932Z", - "shell.execute_reply.started": "2024-11-21T03:39:25.683932Z", - "to_execute": "2024-11-21T03:39:25.680Z" - }, - "interpreter": {}, - "libroCellType": "prompt", - "libroFormatter": "formatter-prompt-magic" + "libroCellType": "prompt" }, - "outputs": [ - { - "data": { - "application/vnd.libro.prompt+json": "Sure, I can help with that. Please provide the Chinese text you'd like translated to English." - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%%prompt \n", "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"You are a helpful assistant that translates Chinese to {output_language}.\",\"cell_id\":\"310bf74e-295d-4a31-8a36-7109cac02982\",\"record\":\"chat1\"}" @@ -473,27 +275,12 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "3281ba0d-ae5d-4510-b7a5-4968b2300e6f", "metadata": { - "execution": { - "shell.execute_reply.end": "2024-11-21T03:39:40.749006Z", - "shell.execute_reply.started": "2024-11-21T03:39:39.066601Z", - "to_execute": "2024-11-21T03:39:39.063Z" - }, - "interpreter": {}, - "libroCellType": "prompt", - "libroFormatter": "formatter-prompt-magic" + "libroCellType": "prompt" }, - "outputs": [ - { - "data": { - "application/vnd.libro.prompt+json": "The translation for \"今天天气真好\" is \"The weather is really good today.\"" - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%%prompt \n", "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"今天天气真好\",\"cell_id\":\"3281ba0d-ae5d-4510-b7a5-4968b2300e6f\",\"record\":\"chat1\"}" @@ -506,17 +293,17 @@ "libroFormatter": "formatter-string" }, "source": [ - "### 最后 🎢\n", + "### Finally 🎢\n", "\n", - "面向未来,libro 将继续发挥自身灵活定制、轻松集成的特点,为 notebook 类产品探索更多的使用场景,让 libro 成为体验最好的 notebook 产品。\n", + "Looking to the future, libro will continue to leverage its flexibility and ease of integration to explore more use cases for notebook-like products, aiming to become the best notebook experience.\n", "\n", - "同时,libro 将不断探索与大模型结合的应用场景,通过大模型让用户拥有更加智能的编程体验,让 libro 编程像写文档一样容易。\n", + "At the same time, libro will keep exploring applications that combine with large models, enabling users to have a more intelligent programming experience, making coding with libro as easy as writing documentation.\n", "\n", - "我们欢迎不同场景的开发者,跟我们一起建设 libro 项目,再次附上 libro 开源项目链接,如果你也喜欢这个项目,欢迎在 GitHub 上为我们点亮 🌟🌟🌟\n", + "We welcome developers from various fields to join us in building the libro project. Here is the link to the open-source libro project. If you like it, feel free to give us a star 🌟🌟🌟 on GitHub!\n", "\n", "https://github.com/difizen/libro\n", "\n", - "**libro,不只是笔记本,更是一个灵感加速器!**" + "**libro, more than just a notebook, it’s an inspiration accelerator!**" ] } ], diff --git a/examples/libro_guide_book_zh.ipynb b/examples/libro_guide_book_zh.ipynb new file mode 100644 index 00000000..1742477e --- /dev/null +++ b/examples/libro_guide_book_zh.ipynb @@ -0,0 +1,311 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d13d3515-05d9-4fb0-a9c4-e62445c9c8af", + "metadata": { + "libroCellType": "markdown", + "libroFormatter": "formatter-string" + }, + "source": [ + "#
✨A Quick Guide to libro✨\n", + "##
🎉🧙🔮 欢迎使用 libro\n", + "**
libro,不只是 notebook,更是一个灵感加速器!**" + ] + }, + { + "cell_type": "markdown", + "id": "92d339b1-45f9-42f0-ac2f-e95388d6c6b3", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "**libro 是支持生成式 AI 能力的可定制 notebook 产品方案。提供商业级 notebook 产品的体验,深度集成 AI 能力,可以轻松集成到您的研发环境中,为您构建一流的 AI、数据科学研发方案。让我们用一种有趣的方式带您快速上手,解锁基于 libro 的全新工作体验!**" + ] + }, + { + "cell_type": "markdown", + "id": "e3bc282a-b4c0-4554-8657-54078632b7fa", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 1:开启 Notebook 之门 🔑" + ] + }, + { + "cell_type": "markdown", + "id": "2675de53-c92c-4c76-a11b-e01f29d6e249", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "在终端中运行 `libro generate config ` 生成 ` ~/.libro/libro_config.yaml` 文件,按照如下内容,对 libro 中大模型和数据库相关的配置,并且启用 libro_sql、libro_ai 扩展。赶快试试吧~\n", + "\n", + "```yaml\n", + "llm:\n", + " DASHSCOPE_API_KEY: xxxxxxx\n", + " OPENAI_API_KEY: xxxxxxxx\n", + " default_model: chatgpt\n", + "\n", + "db:\n", + " - db_type: mysql\n", + " username: \"root\"\n", + " password: \"12345678\"\n", + " host: \"127.0.0.1\"\n", + " port: 3306\n", + " database: sql_demo\n", + "\n", + "ipython_extensions:\n", + " libro_ai: True\n", + " libro_sql: True\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "43fd242d-69c1-45b8-b606-c07ce5923fbb", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 2:SQL Cell,数据界的魔法棒 🪄\n", + "\n", + "libro 支持使用 SQL Cell 来简化数据库交互,它就像一个对话框,直接对接您的数据库,不需要任何额外工具,数据分析轻松搞定!\n", + "\n", + "通过在 libro 中结合 SQL 和 Python,您可以:\n", + "\n", + "- 直接查询数据库,快速获取数据,支持把结果保存为 dataframe。\n", + "- 使用 Python 对查询结果进行进一步的处理和可视化。\n", + "- 将 SQL 的强大查询能力与 Notebook 的动态性结合,提升开发效率。\n", + "\n", + "赶快试试吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12b0e2fa-a4a4-4e17-affb-2dd10ad3cabe", + "metadata": { + "execution": {}, + "libroCellType": "sql", + "libroFormatter": "formatter-sql-magic" + }, + "outputs": [], + "source": [ + "%%sql \n", + "{\"result_variable\":\"df_1\",\"db_id\":\"sqlite: sql_demo\",\"sql_script\":\"select * from products\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "83edeb90-a116-4ed2-b80e-c0a534e365c0", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "df_1" + ] + }, + { + "cell_type": "markdown", + "id": "2d09d97f-8c87-4f80-b865-62239ef4d846", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 3:AI 助手,开发者的好搭档 🤖" + ] + }, + { + "cell_type": "markdown", + "id": "cce8d104-8099-4d16-9dc7-96f6df99259b", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### 错误修复\n", + "\n", + "当 Cell 执行出现报错时,只需一键点击 “Fix with AI” 按钮,助手会自动分析错误并给出修复建议,帮助您快速解决问题,恢复顺利的编程体验。赶快试试修复下面的执行报错吧~\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "549fbd17-9e22-4844-8cb5-dcf006e88338", + "metadata": { + "execution": { + "shell.execute_reply.end": "2024-11-26T06:08:28.406750Z", + "shell.execute_reply.started": "2024-11-26T06:08:28.186003Z", + "to_execute": "2024-11-26T06:08:28.209Z" + }, + "libroFormatter": "formatter-string" + }, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'a' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43ma\u001b[49m\n", + "\u001b[0;31mNameError\u001b[0m: name 'a' is not defined" + ] + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "markdown", + "id": "bd071522-2e45-4d3c-b5fc-beb14147271c", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### AI 对话\n", + "\n", + "您可以点击会话按钮 [ 顶部右侧工具栏 / Cell 右侧工具栏 ] 直接与 AI 进行互动,获得与当前代码相关的深入解答和优化建议,提升编程效率。赶快试试与 libro 的 AI 对话吧~" + ] + }, + { + "cell_type": "markdown", + "id": "d248e413-1411-43cc-b23b-2a1b5626948a", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### 代码解释\n", + "您可以点击魔法按钮 [ Cell 右侧工具栏 ] ,libro 帮您理解 Cell 中代码的功能和逻辑,让编程学习变得更加轻松。赶快试试解释下面这段代码吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "300242af-2d63-4ea4-bb0c-e785d489fc6b", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "def quick_sort(arr):\n", + " if len(arr) <= 1: \n", + " return arr\n", + " \n", + " pivot = arr[len(arr) // 2] \n", + " left = [x for x in arr if x < pivot] \n", + " middle = [x for x in arr if x == pivot] \n", + " right = [x for x in arr if x > pivot] \n", + " return quick_sort(left) + middle + quick_sort(right)" + ] + }, + { + "cell_type": "markdown", + "id": "3d120c83-8655-4251-b97a-7177dba537f5", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### 代码优化\n", + "您可以点击魔法按钮 [ Cell 右侧工具栏 ] ,libro 能够分析 Cell 中的代码,并提供优化建议,让您的代码更加高效、可读,提升整体编程体验。赶快试着优化下面的这一段代码吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1413a361-a51b-4ece-b673-a8a12e75dfce", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "def calculate_sum(numbers):\n", + " total = 0\n", + " for i in range(len(numbers)):\n", + " total += numbers[i]\n", + " return total" + ] + }, + { + "cell_type": "markdown", + "id": "ed705e80-6970-4bc7-8617-a82c70840b9c", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 4:AI 工作流开发利器💡\n", + "\n", + "Prompt Cell 是一种特殊的 notebook cell,通过这个 cell,用户只需要输入自然语言指令,就可以调用大模型进行推理,得到所需的输出结果。它的出现减少了编写复杂代码的需求,并且可以灵活地融入现有的工作流中。赶快试试下面的例子吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "758e3891-bec1-4017-9af6-247634d8ba1c", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "output_language = \"English\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "310bf74e-295d-4a31-8a36-7109cac02982", + "metadata": { + "libroCellType": "prompt" + }, + "outputs": [], + "source": [ + "%%prompt \n", + "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"You are a helpful assistant that translates Chinese to {output_language}.\",\"cell_id\":\"310bf74e-295d-4a31-8a36-7109cac02982\",\"record\":\"chat1\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3281ba0d-ae5d-4510-b7a5-4968b2300e6f", + "metadata": { + "libroCellType": "prompt" + }, + "outputs": [], + "source": [ + "%%prompt \n", + "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"今天天气真好\",\"cell_id\":\"3281ba0d-ae5d-4510-b7a5-4968b2300e6f\",\"record\":\"chat1\"}" + ] + }, + { + "cell_type": "markdown", + "id": "840bbfa2-e89b-4b42-b73a-34ca90ef1736", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### 最后 🎢\n", + "\n", + "面向未来,libro 将继续发挥自身灵活定制、轻松集成的特点,为 notebook 类产品探索更多的使用场景,让 libro 成为体验最好的 notebook 产品。\n", + "\n", + "同时,libro 将不断探索与大模型结合的应用场景,通过大模型让用户拥有更加智能的编程体验,让 libro 编程像写文档一样容易。\n", + "\n", + "我们欢迎不同场景的开发者,跟我们一起建设 libro 项目,再次附上 libro 开源项目链接,如果你也喜欢这个项目,欢迎在 GitHub 上为我们点亮 🌟🌟🌟\n", + "\n", + "https://github.com/difizen/libro\n", + "\n", + "**libro,不只是笔记本,更是一个灵感加速器!**" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/packages/libro-l10n/src/lang/bundle.l10n.en-US.json b/packages/libro-l10n/src/lang/bundle.l10n.en-US.json index ccc4f70c..05e235f2 100644 --- a/packages/libro-l10n/src/lang/bundle.l10n.en-US.json +++ b/packages/libro-l10n/src/lang/bundle.l10n.en-US.json @@ -219,6 +219,7 @@ "运行选中 Cell": "Execute selected cells", "运行选中并向下插入一个 Cell": "Execute select and insert one cell down", "运行并选中下一个 Cell": "Execute and select the next cell", + "使用指南": "Guide book", "切换底部面板": "Toggle bottom panel", "文件": "File", "编辑": "Edit", diff --git a/packages/libro-l10n/src/lang/bundle.l10n.zh-CN.json b/packages/libro-l10n/src/lang/bundle.l10n.zh-CN.json index 3d79f0fd..7163ddb7 100644 --- a/packages/libro-l10n/src/lang/bundle.l10n.zh-CN.json +++ b/packages/libro-l10n/src/lang/bundle.l10n.zh-CN.json @@ -82,6 +82,7 @@ "向下拷贝当前所在行": "向下拷贝当前所在行", "删除光标至行首内容": "删除光标至行首内容", "删除光标至行尾内容": "删除光标至行尾内容", + "使用指南": "使用指南", "恢复": "恢复", "撤销选中": "撤销选中", "恢复选中": "恢复选中", diff --git a/packages/libro-lab/src/guide/content-contribution.ts b/packages/libro-lab/src/guide/content-contribution.ts new file mode 100644 index 00000000..6f7054f7 --- /dev/null +++ b/packages/libro-lab/src/guide/content-contribution.ts @@ -0,0 +1,50 @@ +import type { NotebookModel, NotebookOption } from '@difizen/libro-core'; +import { ContentContribution } from '@difizen/libro-core'; +import type { + IContentsModel, + INotebookContent, + LibroJupyterModel, +} from '@difizen/libro-jupyter'; +import { URI } from '@difizen/mana-app'; +import { singleton } from '@difizen/mana-app'; +import { l10n, L10nLang } from '@difizen/mana-l10n'; + +import contentJson from './libro_guide_book.json'; +import contentZhJson from './libro_guide_book_zh.json'; + +@singleton({ contrib: ContentContribution }) +export class LibroGuidebookContentContribution implements ContentContribution { + canHandle = (options: NotebookOption) => { + if (options['loadType'] === 'libro-guide-book') { + return 50; + } + return 1; + }; + async loadContent(options: NotebookOption, model: NotebookModel) { + const jupyterModel = model as LibroJupyterModel; + const fireUri = new URI(options['resource']); + const filePath = fireUri.path.toString(); + let notebookContent: INotebookContent = { + cells: [], + metadata: {}, + nbformat: 4, + nbformat_minor: 5, + }; + notebookContent = l10n.getLang() === L10nLang.zhCN ? contentZhJson : contentJson; + const currentFileContents: IContentsModel = { + name: 'Guide book', + path: filePath, + type: 'notebook', + writable: true, + created: 'libro', + last_modified: 'libro', + content: notebookContent, + }; + currentFileContents.content.nbformat_minor = 5; + jupyterModel.currentFileContents = currentFileContents; + jupyterModel.filePath = currentFileContents.path; + jupyterModel.lastModified = jupyterModel.currentFileContents.last_modified; + + return jupyterModel.currentFileContents.content; + } +} diff --git a/packages/libro-lab/src/guide/guide-view.tsx b/packages/libro-lab/src/guide/guide-view.tsx new file mode 100644 index 00000000..4b3aa83a --- /dev/null +++ b/packages/libro-lab/src/guide/guide-view.tsx @@ -0,0 +1,77 @@ +import type { LibroView } from '@difizen/libro-jupyter'; +import { LibroService } from '@difizen/libro-jupyter'; +import { + Deferred, + inject, + prop, + singleton, + useInject, + view, + ViewInstance, + ViewRender, +} from '@difizen/mana-app'; +import { BaseView } from '@difizen/mana-app'; +import { l10n, L10nLang } from '@difizen/mana-l10n'; +import { forwardRef } from 'react'; +import './index.less'; + +import { Logo } from '../common/icon.js'; + +export const GuideComponent = forwardRef(function WelcomeComponent() { + const instance = useInject(ViewInstance); + + if (!instance.libroView) { + return null; + } + return ; +}); + +@singleton() +@view('guide-view') +export class GuideView extends BaseView { + override view = GuideComponent; + + @prop() + libroView?: LibroView; + + @prop() filePath?: string; + + @inject(LibroService) protected libroService: LibroService; + + protected defer = new Deferred(); + + get ready() { + return this.defer.promise; + } + + constructor() { + super(); + this.title.icon = ; + this.title.label = () =>
{l10n.t('使用指南')}
; + this.title.closable = true; + this.filePath = + l10n.getLang() === L10nLang.zhCN + ? 'libro_guide_book_zh.json' + : 'libro_guide_book.json'; + } + + override async onViewMount(): Promise { + this.getOrCreateLibroView(); + } + + protected async getOrCreateLibroView() { + const libroView = await this.libroService.getOrCreateView({ + id: this.filePath, + resource: this.filePath, + loadType: 'libro-guide-book', + }); + if (!libroView) { + return; + } + this.libroView = libroView; + await this.libroView.initialized; + this.libroView.model.savable = false; + this.libroView.focus(); + this.defer.resolve(); + } +} diff --git a/packages/libro-lab/src/guide/index.less b/packages/libro-lab/src/guide/index.less new file mode 100644 index 00000000..51b9f227 --- /dev/null +++ b/packages/libro-lab/src/guide/index.less @@ -0,0 +1,8 @@ +.libro-lab-content-layout-main { + .mana-tab-icon { + svg { + display: inline-block; + width: 14px; + } + } +} diff --git a/packages/libro-lab/src/guide/index.ts b/packages/libro-lab/src/guide/index.ts new file mode 100644 index 00000000..c2d5e2aa --- /dev/null +++ b/packages/libro-lab/src/guide/index.ts @@ -0,0 +1,2 @@ +export * from './content-contribution.js'; +export * from './guide-view.js'; diff --git a/packages/libro-lab/src/guide/libro_guide_book.json b/packages/libro-lab/src/guide/libro_guide_book.json new file mode 100644 index 00000000..af2f504f --- /dev/null +++ b/packages/libro-lab/src/guide/libro_guide_book.json @@ -0,0 +1,303 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d13d3515-05d9-4fb0-a9c4-e62445c9c8af", + "metadata": { + "libroCellType": "markdown", + "libroFormatter": "formatter-string" + }, + "source": [ + "#
✨A Quick Guide to libro✨ \n", + "##
🎉🧙🔮 Welcome to libro \n", + "**
libro, more than just a notebook, it’s an inspiration accelerator!**" + ] + }, + { + "cell_type": "markdown", + "id": "92d339b1-45f9-42f0-ac2f-e95388d6c6b3", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "**libro is a customizable notebook solution that supports generative AI capabilities. It offers a commercial-grade notebook experience with deep integration of AI features, allowing for easy integration into your development environment to build top-tier AI and data science solutions. Let us guide you through a fun and engaging way to quickly get started and unlock a whole new work experience with libro!**" + ] + }, + { + "cell_type": "markdown", + "id": "e3bc282a-b4c0-4554-8657-54078632b7fa", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": ["### Step 1: Unlock the Door to the Notebook 🔑"] + }, + { + "cell_type": "markdown", + "id": "2675de53-c92c-4c76-a11b-e01f29d6e249", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "Run `libro generate config` in the terminal to generate the `~/.libro/libro_config.yaml` file. Then, configure the settings for large models and databases in libro, and enable the `libro_sql` and `libro_ai` extensions. Give it a try now! \n", + "\n", + "```yaml\n", + "llm:\n", + " DASHSCOPE_API_KEY: xxxxxxx\n", + " OPENAI_API_KEY: xxxxxxxx\n", + " default_model: chatgpt\n", + "\n", + "db:\n", + " - db_type: mysql\n", + " username: \"root\"\n", + " password: \"12345678\"\n", + " host: \"127.0.0.1\"\n", + " port: 3306\n", + " database: sql_demo.db\n", + "\n", + "ipython_extensions:\n", + " libro_ai: True\n", + " libro_sql: True\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "43fd242d-69c1-45b8-b606-c07ce5923fbb", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 2: SQL Cell, the Magic Wand of Data 🪄\n", + "\n", + "libro supports using SQL Cells to simplify database interactions. It acts like a dialog box that directly connects to your database, without the need for any additional tools—making data analysis a breeze!\n", + "\n", + "By combining SQL and Python in libro, you can:\n", + "\n", + "- Query your database directly to quickly retrieve data and save the results as a dataframe.\n", + "- Use Python to further process and visualize the query results.\n", + "- Leverage the powerful query capabilities of SQL alongside the dynamism of the Notebook to boost development efficiency.\n", + "\n", + "Give it a try now!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12b0e2fa-a4a4-4e17-affb-2dd10ad3cabe", + "metadata": { + "execution": {}, + "libroCellType": "sql", + "libroFormatter": "formatter-sql-magic" + }, + "outputs": [], + "source": [ + "%%sql \n", + "{\"result_variable\":\"df_1\",\"db_id\":\"sqlite: sql_demo\",\"sql_script\":\"select * from products\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "83edeb90-a116-4ed2-b80e-c0a534e365c0", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": ["df_1"] + }, + { + "cell_type": "markdown", + "id": "2d09d97f-8c87-4f80-b865-62239ef4d846", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": ["### Step 3: AI Assistant, the Perfect Partner for Developers 🤖"] + }, + { + "cell_type": "markdown", + "id": "cce8d104-8099-4d16-9dc7-96f6df99259b", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### Error Fixing\n", + "\n", + "When a Cell execution encounters an error, simply click the \"Fix with AI\" button, and the assistant will automatically analyze the error and provide repair suggestions to help you quickly resolve the issue and get back to smooth coding. Try fixing the execution error below now!" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "549fbd17-9e22-4844-8cb5-dcf006e88338", + "metadata": { + "execution": { + "shell.execute_reply.end": "2024-11-26T06:08:42.651560Z", + "shell.execute_reply.started": "2024-11-26T06:08:42.406610Z", + "to_execute": "2024-11-26T06:08:42.429Z" + }, + "libroFormatter": "formatter-string" + }, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'a' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43ma\u001b[49m\n", + "\u001b[0;31mNameError\u001b[0m: name 'a' is not defined" + ] + } + ], + "source": ["a"] + }, + { + "cell_type": "markdown", + "id": "bd071522-2e45-4d3c-b5fc-beb14147271c", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### AI Chat\n", + "\n", + "You can click the conversation button [ in the top-right toolbar / the right toolbar of the Cell ] to interact directly with the AI, receiving in-depth answers and optimization suggestions related to your current code, enhancing your coding efficiency. Try chatting with libro’s AI now!" + ] + }, + { + "cell_type": "markdown", + "id": "d248e413-1411-43cc-b23b-2a1b5626948a", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### Code Explanation\n", + "\n", + "You can click the magic button [in the right toolbar of the Cell], and libro will help you understand the functionality and logic of the code in the Cell, making learning to code easier. Try explaining the code below now!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "300242af-2d63-4ea4-bb0c-e785d489fc6b", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "def quick_sort(arr):\n", + " if len(arr) <= 1: \n", + " return arr\n", + " \n", + " pivot = arr[len(arr) // 2] \n", + " left = [x for x in arr if x < pivot] \n", + " middle = [x for x in arr if x == pivot] \n", + " right = [x for x in arr if x > pivot] \n", + " return quick_sort(left) + middle + quick_sort(right)" + ] + }, + { + "cell_type": "markdown", + "id": "3d120c83-8655-4251-b97a-7177dba537f5", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### Code Optimization\n", + "\n", + "You can click the magic button [ in the right toolbar of the Cell ], and libro will analyze the code in the Cell and provide optimization suggestions to make your code more efficient and readable, enhancing your overall programming experience. Try optimizing the code below now!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1413a361-a51b-4ece-b673-a8a12e75dfce", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "def calculate_sum(numbers):\n", + " total = 0\n", + " for i in range(len(numbers)):\n", + " total += numbers[i]\n", + " return total" + ] + }, + { + "cell_type": "markdown", + "id": "ed705e80-6970-4bc7-8617-a82c70840b9c", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 4: AI Workflow Development Tool 💡\n", + "\n", + "The Prompt Cell is a special type of notebook cell. With this cell, users only need to input natural language commands to call large models for inference and receive the desired output. It reduces the need for writing complex code and can be seamlessly integrated into existing workflows. Try the example below now!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "758e3891-bec1-4017-9af6-247634d8ba1c", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": ["output_language = \"English\""] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "310bf74e-295d-4a31-8a36-7109cac02982", + "metadata": { + "libroCellType": "prompt" + }, + "outputs": [], + "source": [ + "%%prompt \n", + "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"You are a helpful assistant that translates Chinese to {output_language}.\",\"cell_id\":\"310bf74e-295d-4a31-8a36-7109cac02982\",\"record\":\"chat1\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3281ba0d-ae5d-4510-b7a5-4968b2300e6f", + "metadata": { + "libroCellType": "prompt" + }, + "outputs": [], + "source": [ + "%%prompt \n", + "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"今天天气真好\",\"cell_id\":\"3281ba0d-ae5d-4510-b7a5-4968b2300e6f\",\"record\":\"chat1\"}" + ] + }, + { + "cell_type": "markdown", + "id": "840bbfa2-e89b-4b42-b73a-34ca90ef1736", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Finally 🎢\n", + "\n", + "Looking to the future, libro will continue to leverage its flexibility and ease of integration to explore more use cases for notebook-like products, aiming to become the best notebook experience.\n", + "\n", + "At the same time, libro will keep exploring applications that combine with large models, enabling users to have a more intelligent programming experience, making coding with libro as easy as writing documentation.\n", + "\n", + "We welcome developers from various fields to join us in building the libro project. Here is the link to the open-source libro project. If you like it, feel free to give us a star 🌟🌟🌟 on GitHub!\n", + "\n", + "https://github.com/difizen/libro\n", + "\n", + "**libro, more than just a notebook, it’s an inspiration accelerator!**" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/packages/libro-lab/src/guide/libro_guide_book_zh.json b/packages/libro-lab/src/guide/libro_guide_book_zh.json new file mode 100644 index 00000000..2119f7ca --- /dev/null +++ b/packages/libro-lab/src/guide/libro_guide_book_zh.json @@ -0,0 +1,301 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d13d3515-05d9-4fb0-a9c4-e62445c9c8af", + "metadata": { + "libroCellType": "markdown", + "libroFormatter": "formatter-string" + }, + "source": [ + "#
✨A Quick Guide to libro✨\n", + "##
🎉🧙🔮 欢迎使用 libro\n", + "**
libro,不只是 notebook,更是一个灵感加速器!**" + ] + }, + { + "cell_type": "markdown", + "id": "92d339b1-45f9-42f0-ac2f-e95388d6c6b3", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "**libro 是支持生成式 AI 能力的可定制 notebook 产品方案。提供商业级 notebook 产品的体验,深度集成 AI 能力,可以轻松集成到您的研发环境中,为您构建一流的 AI、数据科学研发方案。让我们用一种有趣的方式带您快速上手,解锁基于 libro 的全新工作体验!**" + ] + }, + { + "cell_type": "markdown", + "id": "e3bc282a-b4c0-4554-8657-54078632b7fa", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": ["### Step 1:开启 Notebook 之门 🔑"] + }, + { + "cell_type": "markdown", + "id": "2675de53-c92c-4c76-a11b-e01f29d6e249", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "在终端中运行 `libro generate config ` 生成 ` ~/.libro/libro_config.yaml` 文件,按照如下内容,对 libro 中大模型和数据库相关的配置,并且启用 libro_sql、libro_ai 扩展。赶快试试吧~\n", + "\n", + "```yaml\n", + "llm:\n", + " DASHSCOPE_API_KEY: xxxxxxx\n", + " OPENAI_API_KEY: xxxxxxxx\n", + " default_model: chatgpt\n", + "\n", + "db:\n", + " - db_type: mysql\n", + " username: \"root\"\n", + " password: \"12345678\"\n", + " host: \"127.0.0.1\"\n", + " port: 3306\n", + " database: sql_demo\n", + "\n", + "ipython_extensions:\n", + " libro_ai: True\n", + " libro_sql: True\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "43fd242d-69c1-45b8-b606-c07ce5923fbb", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 2:SQL Cell,数据界的魔法棒 🪄\n", + "\n", + "libro 支持使用 SQL Cell 来简化数据库交互,它就像一个对话框,直接对接您的数据库,不需要任何额外工具,数据分析轻松搞定!\n", + "\n", + "通过在 libro 中结合 SQL 和 Python,您可以:\n", + "\n", + "- 直接查询数据库,快速获取数据,支持把结果保存为 dataframe。\n", + "- 使用 Python 对查询结果进行进一步的处理和可视化。\n", + "- 将 SQL 的强大查询能力与 Notebook 的动态性结合,提升开发效率。\n", + "\n", + "赶快试试吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12b0e2fa-a4a4-4e17-affb-2dd10ad3cabe", + "metadata": { + "execution": {}, + "libroCellType": "sql", + "libroFormatter": "formatter-sql-magic" + }, + "outputs": [], + "source": [ + "%%sql \n", + "{\"result_variable\":\"df_1\",\"db_id\":\"sqlite: sql_demo\",\"sql_script\":\"select * from products\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "83edeb90-a116-4ed2-b80e-c0a534e365c0", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": ["df_1"] + }, + { + "cell_type": "markdown", + "id": "2d09d97f-8c87-4f80-b865-62239ef4d846", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": ["### Step 3:AI 助手,开发者的好搭档 🤖"] + }, + { + "cell_type": "markdown", + "id": "cce8d104-8099-4d16-9dc7-96f6df99259b", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### 错误修复\n", + "\n", + "当 Cell 执行出现报错时,只需一键点击 “Fix with AI” 按钮,助手会自动分析错误并给出修复建议,帮助您快速解决问题,恢复顺利的编程体验。赶快试试修复下面的执行报错吧~\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "549fbd17-9e22-4844-8cb5-dcf006e88338", + "metadata": { + "execution": { + "shell.execute_reply.end": "2024-11-26T06:08:28.406750Z", + "shell.execute_reply.started": "2024-11-26T06:08:28.186003Z", + "to_execute": "2024-11-26T06:08:28.209Z" + }, + "libroFormatter": "formatter-string" + }, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'a' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43ma\u001b[49m\n", + "\u001b[0;31mNameError\u001b[0m: name 'a' is not defined" + ] + } + ], + "source": ["a"] + }, + { + "cell_type": "markdown", + "id": "bd071522-2e45-4d3c-b5fc-beb14147271c", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### AI 对话\n", + "\n", + "您可以点击会话按钮 [ 顶部右侧工具栏 / Cell 右侧工具栏 ] 直接与 AI 进行互动,获得与当前代码相关的深入解答和优化建议,提升编程效率。赶快试试与 libro 的 AI 对话吧~" + ] + }, + { + "cell_type": "markdown", + "id": "d248e413-1411-43cc-b23b-2a1b5626948a", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### 代码解释\n", + "您可以点击魔法按钮 [ Cell 右侧工具栏 ] ,libro 帮您理解 Cell 中代码的功能和逻辑,让编程学习变得更加轻松。赶快试试解释下面这段代码吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "300242af-2d63-4ea4-bb0c-e785d489fc6b", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "def quick_sort(arr):\n", + " if len(arr) <= 1: \n", + " return arr\n", + " \n", + " pivot = arr[len(arr) // 2] \n", + " left = [x for x in arr if x < pivot] \n", + " middle = [x for x in arr if x == pivot] \n", + " right = [x for x in arr if x > pivot] \n", + " return quick_sort(left) + middle + quick_sort(right)" + ] + }, + { + "cell_type": "markdown", + "id": "3d120c83-8655-4251-b97a-7177dba537f5", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "#### 代码优化\n", + "您可以点击魔法按钮 [ Cell 右侧工具栏 ] ,libro 能够分析 Cell 中的代码,并提供优化建议,让您的代码更加高效、可读,提升整体编程体验。赶快试着优化下面的这一段代码吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1413a361-a51b-4ece-b673-a8a12e75dfce", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": [ + "def calculate_sum(numbers):\n", + " total = 0\n", + " for i in range(len(numbers)):\n", + " total += numbers[i]\n", + " return total" + ] + }, + { + "cell_type": "markdown", + "id": "ed705e80-6970-4bc7-8617-a82c70840b9c", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### Step 4:AI 工作流开发利器💡\n", + "\n", + "Prompt Cell 是一种特殊的 notebook cell,通过这个 cell,用户只需要输入自然语言指令,就可以调用大模型进行推理,得到所需的输出结果。它的出现减少了编写复杂代码的需求,并且可以灵活地融入现有的工作流中。赶快试试下面的例子吧~" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "758e3891-bec1-4017-9af6-247634d8ba1c", + "metadata": { + "execution": {}, + "libroFormatter": "formatter-string" + }, + "outputs": [], + "source": ["output_language = \"English\""] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "310bf74e-295d-4a31-8a36-7109cac02982", + "metadata": { + "libroCellType": "prompt" + }, + "outputs": [], + "source": [ + "%%prompt \n", + "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"You are a helpful assistant that translates Chinese to {output_language}.\",\"cell_id\":\"310bf74e-295d-4a31-8a36-7109cac02982\",\"record\":\"chat1\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3281ba0d-ae5d-4510-b7a5-4968b2300e6f", + "metadata": { + "libroCellType": "prompt" + }, + "outputs": [], + "source": [ + "%%prompt \n", + "{\"model_name\":\"LLM:gpt4\",\"chat_key\":\"LLM:gpt4\",\"prompt\":\"今天天气真好\",\"cell_id\":\"3281ba0d-ae5d-4510-b7a5-4968b2300e6f\",\"record\":\"chat1\"}" + ] + }, + { + "cell_type": "markdown", + "id": "840bbfa2-e89b-4b42-b73a-34ca90ef1736", + "metadata": { + "libroFormatter": "formatter-string" + }, + "source": [ + "### 最后 🎢\n", + "\n", + "面向未来,libro 将继续发挥自身灵活定制、轻松集成的特点,为 notebook 类产品探索更多的使用场景,让 libro 成为体验最好的 notebook 产品。\n", + "\n", + "同时,libro 将不断探索与大模型结合的应用场景,通过大模型让用户拥有更加智能的编程体验,让 libro 编程像写文档一样容易。\n", + "\n", + "我们欢迎不同场景的开发者,跟我们一起建设 libro 项目,再次附上 libro 开源项目链接,如果你也喜欢这个项目,欢迎在 GitHub 上为我们点亮 🌟🌟🌟\n", + "\n", + "https://github.com/difizen/libro\n", + "\n", + "**libro,不只是笔记本,更是一个灵感加速器!**" + ] + } + ], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/packages/libro-lab/src/module.tsx b/packages/libro-lab/src/module.tsx index 6bddcc76..b2e3bed4 100644 --- a/packages/libro-lab/src/module.tsx +++ b/packages/libro-lab/src/module.tsx @@ -19,6 +19,8 @@ import { LibroLabHeaderMenuModule } from './command/module.js'; import { LabConfigAppContribution } from './config/config-contribution.js'; import { CodeEditorViewerModule } from './editor-viewer/index.js'; import { GithubLinkView } from './github-link/index.js'; +import { LibroGuidebookContentContribution } from './guide/content-contribution.js'; +import { GuideView } from './guide/guide-view.js'; import { ImageViewerModule } from './image-viewer/index.js'; // import { KernelManagerView } from './kernel-manager/index.js'; import { LibroKernelAndTerminalPanelModule } from './kernel-and-terminal-panel/module.js'; @@ -117,6 +119,17 @@ export const LibroLabModule = ManaModule.create() order: 'welcome', }, }), + LibroGuidebookContentContribution, + GuideView, + createViewPreference({ + view: GuideView, + slot: LibroLabLayoutSlots.content, + autoCreate: true, + openOptions: { + reveal: true, + order: 'guide', + }, + }), EntryPointView, ) .dependOn( diff --git a/packages/libro-lab/tsconfig.json b/packages/libro-lab/tsconfig.json index c9da781c..b3ecc8d9 100644 --- a/packages/libro-lab/tsconfig.json +++ b/packages/libro-lab/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "rootDir": "./src", "outDir": "es", - "declarationDir": "es" + "declarationDir": "es", + "resolveJsonModule": true }, "types": ["jest"], "exclude": ["node_modules"],