Fix some bugs.
This commit is contained in:
1 parent
2af23e7757
commit
c92184c958
2 files changed
+41
-3
No files matched your search
@@ -0,0 +1,31 @@
|
|||||||
|
# cf-chatbot
|
||||||
|
|
||||||
|
基于 Cloudflare Workers + Pages 的 AI 聊天机器人,支持自定义 OpenAI 兼容 API。
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### 环境变量(wrangler.jsonc / Cloudflare Dashboard)
|
||||||
|
|
||||||
|
| 变量 | 说明 | 默认值 |
|
||||||
|
|---|---|---|
|
||||||
|
| `OPENAI_BASE_URL` | API 地址 | `http://awa.kim:8000/v1` |
|
||||||
|
| `MODEL` | 模型名称 | `gpt-5.4-nano` |
|
||||||
|
| `SYSTEM_PROMPT` | 系统提示词 | `You are a helpful assistant.` |
|
||||||
|
| `OPENAI_API_KEY` | API 密钥(可选,前端也可配置) | - |
|
||||||
|
|
||||||
|
### 前端 Settings
|
||||||
|
|
||||||
|
点击页面右上角 **Settings** 按钮,可配置 Model、API Key、User ID,数据存储在浏览器 localStorage。
|
||||||
|
|
||||||
|
## Deploy
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm deploy
|
||||||
|
```
|
||||||
+10
-3
@@ -75,13 +75,20 @@
|
|||||||
|
|
||||||
function getConfig() {
|
function getConfig() {
|
||||||
return {
|
return {
|
||||||
model: localStorage.getItem('chat_model') || '',
|
model: localStorage.getItem('chat_model') || 'gpt-5.4-nano',
|
||||||
key: localStorage.getItem('chat_key') || '',
|
key: localStorage.getItem('chat_key') || 'sk-ABCD',
|
||||||
userId: localStorage.getItem('chat_userid') || '',
|
userId: localStorage.getItem('chat_userid') || '65535',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadConfig()
|
loadConfig()
|
||||||
|
function saveDefaults() {
|
||||||
|
getConfig() // trigger defaults
|
||||||
|
if (!localStorage.getItem('chat_model')) localStorage.setItem('chat_model', 'gpt-5.4-nano')
|
||||||
|
if (!localStorage.getItem('chat_key')) localStorage.setItem('chat_key', 'sk-ABCD')
|
||||||
|
if (!localStorage.getItem('chat_userid')) localStorage.setItem('chat_userid', '65535')
|
||||||
|
}
|
||||||
|
saveDefaults()
|
||||||
document.getElementById('modelInput').addEventListener('input', saveConfig)
|
document.getElementById('modelInput').addEventListener('input', saveConfig)
|
||||||
document.getElementById('keyInput').addEventListener('input', saveConfig)
|
document.getElementById('keyInput').addEventListener('input', saveConfig)
|
||||||
document.getElementById('userIdInput').addEventListener('input', saveConfig)
|
document.getElementById('userIdInput').addEventListener('input', saveConfig)
|
||||||
|
|||||||
Reference in new issue
Block a user