pub const HEALTH: &str = "/health";
pub const METRICS: &str = "/metrics";
pub const CACHE_STATS: &str = "/cache/stats";
pub const V1_MODELS: &str = "/v1/models";
pub const V1_CHAT_COMPLETIONS: &str = "/v1/chat/completions";
pub const V1_COMPLETIONS: &str = "/v1/completions";
pub const V1_TOKENIZE: &str = "/v1/tokenize";
pub const V1_DETOKENIZE: &str = "/v1/detokenize";
pub const V1_EMBEDDINGS: &str = "/v1/embeddings";
pub const V1_MESSAGES: &str = "/v1/messages";
pub const V1_CANCEL: &str = "/v1/cancel";
pub const V1_STREAM: &str = "/v1/stream/{request_id}";
pub const V1_STREAM_POLL: &str = "/v1/stream/{request_id}/poll";
pub const ADMIN_MODELS: &str = "/admin/models";
pub const ADMIN_MODELS_LOAD: &str = "/admin/models/load";
pub const ADMIN_MODELS_UNLOAD: &str = "/admin/models/unload";
pub const ADMIN_DOWNLOAD: &str = "/admin/download";
pub const ADMIN_TASKS: &str = "/admin/tasks";
pub const ADMIN_TASK_CANCEL: &str = "/admin/tasks/{task_id}/cancel";
pub const ADMIN_STATS: &str = "/admin/stats";
pub fn admin_task_cancel(task_id: &str) -> String {
ADMIN_TASK_CANCEL.replace("{task_id}", task_id)
}
pub fn v1_stream(request_id: &str) -> String {
V1_STREAM.replace("{request_id}", request_id)
}
pub fn v1_stream_poll(request_id: &str) -> String {
V1_STREAM_POLL.replace("{request_id}", request_id)
}
pub const ALL: &[&str] = &[
HEALTH,
METRICS,
CACHE_STATS,
V1_MODELS,
V1_CHAT_COMPLETIONS,
V1_COMPLETIONS,
V1_TOKENIZE,
V1_DETOKENIZE,
V1_EMBEDDINGS,
V1_MESSAGES,
V1_CANCEL,
ADMIN_MODELS,
ADMIN_MODELS_LOAD,
ADMIN_MODELS_UNLOAD,
ADMIN_DOWNLOAD,
ADMIN_TASKS,
ADMIN_STATS,
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_route_is_absolute_and_unique() {
let mut seen = std::collections::BTreeSet::new();
for route in ALL {
assert!(route.starts_with('/'), "{route} is not an absolute path");
assert!(!route.ends_with('/'), "{route} has a trailing slash");
assert!(seen.insert(*route), "{route} is listed twice");
}
}
#[test]
fn the_admin_surface_is_namespaced() {
for route in ALL.iter().filter(|r| r.starts_with("/admin")) {
assert!(
route.starts_with("/admin/"),
"{route} would collide with the /admin prefix itself"
);
}
}
#[test]
fn the_cancel_template_is_not_enumerated_as_a_real_path() {
assert!(!ALL.contains(&ADMIN_TASK_CANCEL));
assert!(ADMIN_TASK_CANCEL.contains("{task_id}"));
}
#[test]
fn the_stream_templates_are_not_enumerated_as_real_paths() {
for template in [V1_STREAM, V1_STREAM_POLL] {
assert!(!ALL.contains(&template));
assert!(template.contains("{request_id}"));
}
assert_eq!(v1_stream("chatcmpl-7"), "/v1/stream/chatcmpl-7");
assert_eq!(
v1_stream_poll("chatcmpl-7"),
"/v1/stream/chatcmpl-7/poll".to_string()
);
assert!(!v1_stream("chatcmpl-7").contains('{'));
}
#[test]
fn the_poll_route_is_nested_under_the_resume_route() {
assert!(V1_STREAM_POLL.starts_with(V1_STREAM));
assert!(V1_STREAM.starts_with("/v1/"));
}
#[test]
fn a_cancel_path_substitutes_the_only_placeholder() {
assert_eq!(
admin_task_cancel("task-7"),
"/admin/tasks/task-7/cancel".to_string()
);
assert!(!admin_task_cancel("task-7").contains('{'));
}
}