最近 Sessions
| Session | App | User | 狀態 | 耗時 | 時間 |
|---|
API Key 池
| ID | 標籤 | Key | Base URL | 模型 | 速率 | 調用 | 狀態 | 操作 |
|---|
已註冊應用
已選 0 項
| App ID | 名稱 | 用戶數 | 創建 | 操作 |
|---|
用戶列表
已選 0 項
| App | User ID | Local Path | 最後活躍 | 操作 |
|---|
Session 歷史
已選 0 項
| Session ID | App | User | 狀態 | 查詢 | 耗時 | 時間 | 操作 |
|---|
用戶彙整
已選 0 項
| App | User | 週區間 | 摘要 | 時間 | 操作 |
|---|
📐 客戶端接入協議
客戶端透過 HTTPS POST 發送 JSON 封裝的請求,取得 AI 回覆。所有通信均使用 TLS 加密(Let's Encrypt 證書)。
⚠️ 中國大陸網路備用入口
主入口: https://www.herelai.fun/ws/05-ai-gateway/api/query
備用入口: https://43-135-184-31.sslip.io/ws/05-ai-gateway/api/query
若中國大陸未開 VPN 時 herelai.fun 域名 HTTPS 被中斷,請將客戶端 endpoint 臨時切換到備用入口。備用入口同樣使用 Let's Encrypt 正式 HTTPS 憑證,可直接用於 iOS/Android/Web 客戶端。
1️⃣ 請求格式 (Client → Server)
POST https://www.herelai.fun/ws/05-ai-gateway/api/query
Content-Type: application/json
Protocol: HTTPS (TLS 1.2+, Let's Encrypt 證書)
{
"app_id": "your_app_identifier",
"user_id": "user_unique_id",
"query_data": "用戶的問題或輸入內容",
"messages": [
{"role": "user", "content": "之前的對話"},
{"role": "assistant", "content": "AI 之前的回覆"},
{"role": "user", "content": "用戶的問題或輸入內容"}
],
"options": {
"temperature": 0.7,
"max_tokens": 2000
}
}
💡 messages 陣列支持多輪對話上下文(原生 OpenAI 格式),AI 能準確理解歷史對話。若同時提供 query_data 和 messages,優先使用 messages。
2️⃣ 成功回覆 (Server → Client)
{
"success": true,
"session_id": "sess_app1_user1_1746123456789",
"response": "AI 生成的回覆內容...",
"local_path": "/data/app1/user1",
"duration_ms": 2340,
"context_used": true,
"model": "meta/llama-3.1-8b-instruct"
}
3️⃣ 錯誤回覆
{
"success": false,
"session_id": "sess_xxx",
"error": "錯誤描述(Queue full / API timeout 等)"
}
4️⃣ JavaScript / React Native 範例
async function queryAI(appId, userId, question) {
const res = await fetch(
'https://www.herelai.fun/ws/05-ai-gateway/api/query',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
app_id: appId,
user_id: userId,
query_data: question,
}),
}
);
const result = await res.json();
return result.success ? result.response : null;
}
// 使用
const answer = await queryAI('my_app', 'user123', '你好');
5️⃣ Swift / iOS 範例
func queryAI(appId: String, userId: String, question: String) async -> String? {
var req = URLRequest(url: URL(string: "https://www.herelai.fun/ws/05-ai-gateway/api/query")!)
req.httpMethod = "POST"
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = try? JSONSerialization.data(withJSONObject: [
"app_id": appId,
"user_id": userId,
"query_data": question
])
let (data, _) = try? await URLSession.shared.data(for: req)
let r = try? JSONSerialization.jsonObject(with: data!) as? [String: Any]
return r?["success"] as? Bool == true ? r?["response"] as? String : nil
}
6️⃣ Kotlin / Android 範例
suspend fun queryAI(appId: String, userId: String, q: String): String? {
val json = JSONObject().apply {
put("app_id", appId); put("user_id", userId); put("query_data", q)
}
val body = json.toString().toRequestBody("application/json".toMediaType())
val req = Request.Builder()
.url("https://www.herelai.fun/ws/05-ai-gateway/api/query")
.post(body).build()
return OkHttpClient().newCall(req).execute().use { resp ->
val r = JSONObject(resp.body!!.string())
if (r.getBoolean("success")) r.getString("response") else null
}
}