Refactored and documented the HTTP API
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
use crate::http::context::{AppContext, OpenApiResult, bad_request};
|
||||
use crate::llm::chat;
|
||||
use poem_openapi::{OpenApi, payload::Json};
|
||||
use poem_openapi::{OpenApi, Tags, payload::Json};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Tags)]
|
||||
enum ChatTags {
|
||||
Chat,
|
||||
}
|
||||
|
||||
pub struct ChatApi {
|
||||
pub ctx: Arc<AppContext>,
|
||||
}
|
||||
|
||||
#[OpenApi]
|
||||
#[OpenApi(tag = "ChatTags::Chat")]
|
||||
impl ChatApi {
|
||||
/// Cancel the currently running chat stream, if any.
|
||||
///
|
||||
/// Returns `true` once the cancellation signal is issued.
|
||||
#[oai(path = "/chat/cancel", method = "post")]
|
||||
async fn cancel_chat(&self) -> OpenApiResult<Json<bool>> {
|
||||
chat::cancel_chat(&self.ctx.state).map_err(bad_request)?;
|
||||
|
||||
Reference in New Issue
Block a user