use crate::http::context::{AppContext, OpenApiResult, bad_request}; use crate::llm::chat; use poem_openapi::{Object, OpenApi, payload::Json}; use serde::Deserialize; use std::sync::Arc; #[derive(Deserialize, Object)] struct ApiKeyPayload { api_key: String, } pub struct AnthropicApi { ctx: Arc, } impl AnthropicApi { pub fn new(ctx: Arc) -> Self { Self { ctx } } } #[OpenApi] impl AnthropicApi { #[oai(path = "/anthropic/key/exists", method = "get")] async fn get_anthropic_api_key_exists(&self) -> OpenApiResult> { 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, ) -> OpenApiResult> { chat::set_anthropic_api_key(self.ctx.store.as_ref(), payload.0.api_key) .map_err(bad_request)?; Ok(Json(true)) } }