Files
storkit/server/src/http/anthropic.rs

41 lines
1.0 KiB
Rust
Raw Normal View History

2026-02-16 16:24:21 +00:00
use crate::http::context::{AppContext, OpenApiResult, bad_request};
2026-02-16 16:35:25 +00:00
use crate::llm::chat;
use poem_openapi::{Object, OpenApi, payload::Json};
use serde::Deserialize;
use std::sync::Arc;
2026-02-16 16:24:21 +00:00
2026-02-16 16:35:25 +00:00
#[derive(Deserialize, Object)]
struct ApiKeyPayload {
api_key: String,
2026-02-16 16:24:21 +00:00
}
2026-02-16 16:35:25 +00:00
pub struct AnthropicApi {
ctx: Arc<AppContext>,
}
impl AnthropicApi {
pub fn new(ctx: Arc<AppContext>) -> Self {
Self { ctx }
}
}
#[OpenApi]
impl AnthropicApi {
#[oai(path = "/anthropic/key/exists", method = "get")]
async fn get_anthropic_api_key_exists(&self) -> OpenApiResult<Json<bool>> {
let exists =
chat::get_anthropic_api_key_exists(self.ctx.store.as_ref()).map_err(bad_request)?;
Ok(Json(exists))
}
#[oai(path = "/anthropic/key", method = "post")]
async fn set_anthropic_api_key(
&self,
payload: Json<ApiKeyPayload>,
) -> OpenApiResult<Json<bool>> {
chat::set_anthropic_api_key(self.ctx.store.as_ref(), payload.0.api_key)
.map_err(bad_request)?;
Ok(Json(true))
}
2026-02-16 16:24:21 +00:00
}