summaryrefslogtreecommitdiffstats
path: root/src
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 /src
parent7762cd6bed7f95fa855144e01aa94e932869fe12 (diff)
downloadaichat-84fab36a1fcb2e0ade38c4a4770591c6236ce8df.tar.gz
refactor: split /data.json into /v1/models and /v1/roles (#494)
Diffstat (limited to 'src')
-rw-r--r--src/serve.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/serve.rs b/src/serve.rs
index 4413c89..3fa0d90 100644
--- a/src/serve.rs
+++ b/src/serve.rs
@@ -158,12 +158,14 @@ impl Server {
let mut status = StatusCode::OK;
let res = if path == "/v1/chat/completions" {
self.chat_completion(req).await
+ } else if path == "/v1/models" {
+ self.list_models()
+ } else if path == "/v1/roles" {
+ self.list_roles()
} else if path == "/playground" || path == "/playground.html" {
self.playground_page()
} else if path == "/arena" || path == "/arena.html" {
self.arena_page()
- } else if path == "/data.json" {
- self.data_json()
} else {
status = StatusCode::NOT_FOUND;
Err(anyhow!("The requested endpoint was not found."))
@@ -198,11 +200,16 @@ impl Server {
Ok(res)
}
- fn data_json(&self) -> Result<AppResponse> {
- let data = json!({
- "models": self.models,
- "roles": self.roles,
- });
+ fn list_models(&self) -> Result<AppResponse> {
+ let data = json!({ "data": self.models });
+ let res = Response::builder()
+ .header("Content-Type", "application/json; charset=utf-8")
+ .body(Full::new(Bytes::from(data.to_string())).boxed())?;
+ Ok(res)
+ }
+
+ fn list_roles(&self) -> Result<AppResponse> {
+ let data = json!({ "data": self.roles });
let res = Response::builder()
.header("Content-Type", "application/json; charset=utf-8")
.body(Full::new(Bytes::from(data.to_string())).boxed())?;