summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-05-08 14:04:46 +0800
committerGitHub <noreply@github.com>2024-05-08 14:04:46 +0800
commit84fab36a1fcb2e0ade38c4a4770591c6236ce8df (patch)
tree9c184b4083ce2da6cdfbd7cba1fb6ea442e70804 /assets
parent7762cd6bed7f95fa855144e01aa94e932869fe12 (diff)
downloadaichat-84fab36a1fcb2e0ade38c4a4770591c6236ce8df.tar.gz
refactor: split /data.json into /v1/models and /v1/roles (#494)
Diffstat (limited to 'assets')
-rw-r--r--assets/arena.html8
-rw-r--r--assets/playground.html9
2 files changed, 9 insertions, 8 deletions
diff --git a/assets/arena.html b/assets/arena.html
index b20553d..138849d 100644
--- a/assets/arena.html
+++ b/assets/arena.html
@@ -482,8 +482,8 @@
const QUERY = parseQueryString(location.search);
const NUM = parseInt(QUERY.num) || 2
const API_BASE = QUERY.api_base || ".";
- const DATAJSON_API = API_BASE + "/data.json";
const CHAT_COMPLETIONS_URL = API_BASE + "/v1/chat/completions";
+ const MODELS_API = API_BASE + "/v1/models";
const MODEL_IDS_STORAGE_KEY = "__model_ids__";
document.addEventListener("alpine:init", () => {
@@ -512,7 +512,7 @@
async init() {
try {
- const { models } = await fetchDataJSON(DATAJSON_API);
+ const models = await fetchJSON(MODELS_API);
this.models = models;
} catch (err) {
console.error(err);
@@ -755,10 +755,10 @@
}));
}
- async function fetchDataJSON(url) {
+ async function fetchJSON(url) {
const res = await fetch(url);
const data = await res.json()
- return data;
+ return data.data;
}
async function* fetchChatCompletions(url, body, signal) {
diff --git a/assets/playground.html b/assets/playground.html
index 0036fb4..af675fd 100644
--- a/assets/playground.html
+++ b/assets/playground.html
@@ -641,8 +641,9 @@
<script>
const QUERY = parseQueryString(location.search);
const API_BASE = QUERY.api_base || ".";
- const DATAJSON_API = API_BASE + "/data.json";
const CHAT_COMPLETIONS_URL = API_BASE + "/v1/chat/completions";
+ const MODELS_API = API_BASE + "/v1/models";
+ const ROLES_API = API_BASE + "/v1/roles";
const SETTINGS_STORAGE_KEY = "__settings__";
document.addEventListener("alpine:init", () => {
@@ -691,7 +692,7 @@
async init() {
try {
- const { models, roles } = await fetchDataJSON(DATAJSON_API);
+ const [models, roles] = await Promise.all([MODELS_API, ROLES_API].map(url => fetchJSON(url)));
this.models = models;
this.roles.push(...roles);
} catch (err) {
@@ -949,10 +950,10 @@
}
- async function fetchDataJSON(url) {
+ async function fetchJSON(url) {
const res = await fetch(url);
const data = await res.json()
- return data;
+ return data.data;
}
async function* fetchChatCompletions(url, body, signal) {