一个基于 EO Functions 的 AI 聊天应用,使用 CNB API 提供智能对话服务,支持不限量调用 hunyuan-a13b 模型。
git clone https://cnb.cool/Anyexyz/CNB-Chat.git
cd CNB-Chat
创建 CNB 访问令牌
repo-code(只读)配置环境变量
编辑 .env 文件,填入你的 CNB 凭证:
CNB_TOKEN=your_api_token_here CNB_REPO=your_repo_id_here
创建 EO Pages 项目
国内版请点击:https://console.cloud.tencent.com/edgeone/pages/upload
国际版请点击:https://console.tencentcloud.com/edgeone/pages
添加自定义域名
访问预览地址确认服务可用,可以添加自定义域名进行访问
测试服务
使用以下代码测试服务是否正常:
curl -X POST https://your-domain.com/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "hunyuan-a13b",
"messages": [{"role": "user", "content": "你好"}]
}'
得到响应即可正常使用
本项目提供了本地开发服务器,模拟 EdgeOne Functions 环境。
安装依赖
npm install
配置环境变量
在项目根目录创建 .env 文件,填入 CNB 凭证:
CNB_TOKEN=your_api_token_here CNB_REPO=your_repo_id_here
启动服务
npm start
访问 http://localhost:3000 即可使用。
CNB-Chat/ ├── index.html # 主应用文件 (HTML + CSS + JS) ├── functions/ # EO Functions 函数 │ └── v1/ │ ├── chat/ │ │ └── completions.js # 聊天完成 API │ └── models.js # 模型列表 API ├── .env # 环境变量配置 └── README.md # 项目文档
支持以下 Markdown 语法:
GET /v1/models - 获取可用模型列表POST /v1/chat/completions - 发送聊天请求(支持流式响应)| 变量名 | 说明 | 示例 |
|---|---|---|
CNB_TOKEN | CNB API 访问令牌 | your_api_token_here |
CNB_REPO | CNB 仓库 ID | your_repo_id_here |
编辑 index.html 中的以下配置:
// 默认模型
let currentModel = 'hunyuan-a13b';
欢迎提交 Issue 和 Pull Request!