Refactored and documented the HTTP API

This commit is contained in:
Dave
2026-02-16 16:50:50 +00:00
parent f76376b203
commit feb05dc8d0
9 changed files with 148 additions and 136 deletions

View File

@@ -1,6 +1,6 @@
use crate::http::context::{AppContext, OpenApiResult, bad_request};
use crate::llm::chat;
use poem_openapi::{Object, OpenApi, payload::Json};
use poem_openapi::{Object, OpenApi, Tags, payload::Json};
use serde::Deserialize;
use std::sync::Arc;
@@ -9,6 +9,11 @@ struct ApiKeyPayload {
api_key: String,
}
#[derive(Tags)]
enum AnthropicTags {
Anthropic,
}
pub struct AnthropicApi {
ctx: Arc<AppContext>,
}
@@ -19,8 +24,11 @@ impl AnthropicApi {
}
}
#[OpenApi]
#[OpenApi(tag = "AnthropicTags::Anthropic")]
impl AnthropicApi {
/// Check whether an Anthropic API key is stored.
///
/// Returns `true` if a non-empty key is present, otherwise `false`.
#[oai(path = "/anthropic/key/exists", method = "get")]
async fn get_anthropic_api_key_exists(&self) -> OpenApiResult<Json<bool>> {
let exists =
@@ -28,6 +36,9 @@ impl AnthropicApi {
Ok(Json(exists))
}
/// Store or update the Anthropic API key used for requests.
///
/// Returns `true` when the key is saved successfully.
#[oai(path = "/anthropic/key", method = "post")]
async fn set_anthropic_api_key(
&self,