2026-02-16 16:24:21 +00:00
|
|
|
use crate::http::context::{AppContext, OpenApiResult, bad_request};
|
|
|
|
|
use crate::llm::chat;
|
2026-02-16 16:50:50 +00:00
|
|
|
use poem_openapi::{OpenApi, Tags, payload::Json};
|
2026-02-16 16:35:25 +00:00
|
|
|
use std::sync::Arc;
|
2026-02-16 16:24:21 +00:00
|
|
|
|
2026-02-16 16:50:50 +00:00
|
|
|
#[derive(Tags)]
|
|
|
|
|
enum ChatTags {
|
|
|
|
|
Chat,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 16:35:25 +00:00
|
|
|
pub struct ChatApi {
|
|
|
|
|
pub ctx: Arc<AppContext>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 16:50:50 +00:00
|
|
|
#[OpenApi(tag = "ChatTags::Chat")]
|
2026-02-16 16:35:25 +00:00
|
|
|
impl ChatApi {
|
2026-02-16 16:50:50 +00:00
|
|
|
/// Cancel the currently running chat stream, if any.
|
|
|
|
|
///
|
|
|
|
|
/// Returns `true` once the cancellation signal is issued.
|
2026-02-16 16:35:25 +00:00
|
|
|
#[oai(path = "/chat/cancel", method = "post")]
|
|
|
|
|
async fn cancel_chat(&self) -> OpenApiResult<Json<bool>> {
|
|
|
|
|
chat::cancel_chat(&self.ctx.state).map_err(bad_request)?;
|
|
|
|
|
Ok(Json(true))
|
|
|
|
|
}
|
2026-02-16 16:24:21 +00:00
|
|
|
}
|