AI 风口已来,手摸手带你入门AI开发!
7 分钟
2022-07-22
最近更新于: 2022-07-22 00:00:00
在使用 ChatGPT 过程中,大家不可避免的会遇到这些问题
- 如何在国内使用ChatGPT?
- 如何搭建代理服务器?
- 如何自定义私有 GPT?
- 如何开发一个知识库?
接下来我将手摸手带大家进入 AI 世界,最终效果先给 xdm 体验一下
国内使用 ChatGPT
使用 sms-activate
- 充值
- 购买 openai 服务
- 注册 openai 账号
- 号码验证 注册流程有一个号码验证,输入上述号码,等待验证码即可
如何搭建开发代理服务器
使用 Deno Deploy,如果嫌麻烦可以使用我的代理:https://proxy.aitimi.cn/
- 创建项目
- 建立代理服务器
- 托管
- 获取代理
另外你也可以使用 cf workers
,代码如下:
如何自定义私有 GPT
为了简便,我们直接使用 OpenAI,我们使用前篇的 脚手架 工具快速创建一个 nuxt3 工程:
ucli create ai
,等待安装完成,直接进入项目输入pnpm dev
启动即可。
配置代理
我们需要在 .env 中配置代理
在调用时
封装 OpenAI API
在服务端,我们需要对 OpenAI API
进行封装调用:
基础 API 封装
Chat API
对话,另外 Completions API
被标记为兼容,不再推荐,可以使用 Chat API
实现
Dalle API
图像生成,图像生成后图片做了一个代理,以便客户端可以访问到生成图片
Embedding API
矢量化
Whisper API
语音转文本
其他
OpenAI API
还支持 内容安全检查(moderation)、模型微调(finetune),大家自行封装。
NuxtAPI 封装
Chat API
Dalle API
Embedding API
Embedding API
封装我们会在知识库详细讲解
调用
以 Chat API
为例:
- 使用 Fetch 调用
- 处理流数据
- Markdown 转 HTML
- 输出显示
获取数据
使用 Fetch API 获取接口数据,读取流信息获取生成文本,使用 store 储存 当前生成文本
Markdown 转 HTML
初始化 Markdown
使用 markdown-it
来转换成 HTML
转换 HTML
使用 Worker 转换 HTML
md.worker.ts
输出显示
使用 nuxt3 plugin
注入 markdown util
在 显示组件中调用 markdown util
生成 HTML
如何开发个人知识库
知识库开发详见 这篇文章
最后
完结撒花🎉,接下来的路,只能大家自己走了😄,希望大家在 AI 这片热土上掘金顺利!