惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
博客园_首页
雷峰网
雷峰网
V
V2EX
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
T
Tailwind CSS Blog
小众软件
小众软件
博客园 - 叶小钗
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
MyScale Blog
MyScale Blog
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

wuxinhua.com Blog | RSS Feed

写作者与不写作者:AI 时代的思考分水岭 - wuxinhua.com 一文搞懂 Prompt Engineering - wuxinhua.com #30 AI 颠覆我对传统创业团队的认知 - wuxinhua.com 前端面试系列 - 手写代码 - wuxinhua.com #29 微软与 OpenAI 合作内幕 - wuxinhua.com #28 离 30 岁越来越远 - wuxinhua.com Building a Blog Subscription and Pusher with AirCode and Resend - wuxinhua.com #27 创始人是公司灵魂的守护者 - wuxinhua.com 快速上手 Midjourney AI 做图 - wuxinhua.com Building your first Discord ChatGPT Bot - wuxinhua.com ChatGPT 机器人系列 - 用 JavaScript,五分钟将 Siri 接入 ChatGPT - wuxinhua.com ChatGPT 机器人系列 - 用 JavaScript 五分钟开发一个飞书 ChatGPT 机器人 - wuxinhua.com ChatGPT 机器人系列 - 用 JavaScript 开发企业微信 ChatGPT 聊天应用 - wuxinhua.com #26 SVB 硅谷银行为什么倒闭 - wuxinhua.com #25 人人都可以成为 AI 工程师 - wuxinhua.com #24 关注你身体的变化 - wuxinhua.com #23 Be positive - wuxinhua.com 前端面试系列 - 前端八股文 - wuxinhua.com #22 AI 在殖民,社交媒体在衰退 - wuxinhua.com #21 我了解到的新冠后遗症 - wuxinhua.com #20 关于死亡和告别 - wuxinhua.com #19 永远无法准备好 - wuxinhua.com macOS 前端开发环境配置 - wuxinhua.com 我的 Newsletter 321来信 - wuxinhua.com Node.js 包管理及 npm 依赖安装机制 - wuxinhua.com 知识的碎片(2021) - wuxinhua.com 放弃 newsfeed 拥抱 newsletter - wuxinhua.com 混迹于 Clubhouse 两周后的一些想法🤔 - wuxinhua.com 认识Docker - wuxinhua.com 知识的碎片(2020) - wuxinhua.com
Add AI Chatbox to your VitePress document site - wuxinhua...
2023-09-19 · via wuxinhua.com Blog | RSS Feed

This article will guide you how to quickly empower your VitePress documentation site with AI conversational capabilities using an open-source tool Documate. This will allow it to answer your users' questions based on the content of your documentation, supporting streaming outputs.

documate screenshot gif

The complete source code of the project can be viewed at https://github.com/AirCodeLabs/documate.

Integration Steps

If you want to create a brand-new VitePress project with AI conversational capabilities, use the command below:

1npm create documate@latest --template vitepress

After creation, jump directly to step 3 "Build, Upload, and Configure the Search Backend API".

To add AI conversational capabilities to an existing VitePress project, follow these steps:

1. Initialization

Run the following command in your VitePress project root directory to initialize:

1npx @documate/documate init --framework vue

documate init

This command will create a documate.json configuration file.

1{ 2 "root": ".", 3 "include": [ 4 "**/*.md" 5 ], 6 "backend": "" 7}

A documate:upload command will also be added, which is used to upload documents to create a knowledge base. I will explain its specific usage later.

1{ 2 "scripts": { 3 "docs:dev": "vitepress dev", 4 "docs:build": "vitepress build", 5 "docs:preview": "vitepress preview", 6 "documate:upload": "documate upload" 7 }, 8 "dependencies": { 9 "@documate/vue": "^0.2.3" 10 }, 11 "devDependencies": { 12 "@documate/documate": "^0.1.0" 13 } 14}

2. Add UI Entry to the Project

Add the following code to the file .vitepress/theme/index.js. If it doesn't exist, you need to create it manually. VitePress introduces how to customize your own theme in the Extending the Default Theme documentation.

1import { h } from 'vue' 2import DefaultTheme from 'vitepress/theme' 3 4// Load component and style 5import Documate from '@documate/vue' 6import '@documate/vue/dist/style.css' 7 8export default { 9 ...DefaultTheme, 10 // Add Documate UI to the slot 11 Layout: h(DefaultTheme.Layout, null, { 12 'nav-bar-content-before': () => h(Documate, { 13 endpoint: '', 14 }), 15 }), 16}

The above code will add an AI chat box UI to the navbar. After launching the service locally using npm run docs:dev, you can find the Ask AI button in the top left corner. If you don't see the Ask AI button, check to ensure all the above code has been added correctly and that you've imported the CSS style file from @documate/vue/dist/style.css.

dev

Now, you have successfully integrated the UI. Next, we'll add the interface capability for the chat box to answer questions.

Documate's backend code is used to upload document content to create a knowledge base and to receive user questions and return streaming answers.

Go to the backend folder on GitHub and click on 「Deploy to AirCode」 to quickly copy and deploy your own backend code.

Deploy to AirCode

If you are using AirCode (an online platform for writing and deploying Node.js applications) for the first time, you will be redirected to the login page. It is recommended to log in with GitHub for faster access.

login

After creating the app, set the OPENAI_API_KEY environment variable in the Environments tab to your OpenAI Key value. You can obtain the API Key from the OpenAI platform.

env OPENAI_API_KEY

Click the「Deploy」button on the top bar to deploy all functions online. Once deployed successfully, you will receive URLs to call each function.

Deploy

Here we will use the upload.js and ask.js functions, one for uploading document content and the other for answering questions.

4. Set Up the API Endpoint

In the AirCode Dashboard, select the deployed upload.js file, copy its URL, and add it to the backend field in documate.json.

1// documate.json 2{ 3 "root": ".", 4 "include": [ "**/*.md" ], 5 "backend": "替换为你的 upload.js 的 URL" 6}

API Endpoint

Similarly, in AirCode, select the deployed ask.js file, copy its URL, and modify the endpoint value in .vitepress/theme/index.js.

1// .vitepress/theme/index.js 2import { h } from 'vue' 3import DefaultTheme from 'vitepress/theme' 4import Documate from '@documate/vue' 5import '@documate/vue/dist/style.css' 6 7export default { 8 ...DefaultTheme, 9 Layout: h(DefaultTheme.Layout, null, { 10 'nav-bar-content-before': () => h(Documate, { 11 // Replace the URL with your own one 12 endpoint: '替换为你的 ask.js 的 URL', 13 }, 14 ), 15 }), 16}

5. Run the Project

Use the command below to upload the content to the backend and generate the documentation knowledge base:


documate:upload

Once the command completes, launch the project locally, click the Ask AI button in the top left corner, enter a question in the pop-up dialog box, and receive answers based on your documentation content.


screen shoot

For more usage and configuration methods, please refer to the Documate project on GitHub, Comments and discussions are welcome.

GitHub -> https://github.com/AirCodeLabs/documate.