api key auth for api handlers

This commit is contained in:
Per Stark
2024-12-14 23:14:30 +01:00
parent 96f2e765f6
commit ae4781363f
9 changed files with 143 additions and 713 deletions

View File

@@ -1,8 +1,8 @@
pub mod helper;
pub mod prompt;
use crate::{error::ApiError, server::AppState};
use axum::{extract::State, response::IntoResponse, Json};
use crate::{error::ApiError, server::AppState, storage::types::user::User};
use axum::{extract::State, response::IntoResponse, Extension, Json};
use helper::get_answer_with_references;
use serde::Deserialize;
use tracing::info;
@@ -27,9 +27,11 @@ pub struct LLMResponseFormat {
pub async fn query_handler(
State(state): State<AppState>,
Extension(user): Extension<User>,
Json(query): Json<QueryInput>,
) -> Result<impl IntoResponse, ApiError> {
info!("Received input: {:?}", query);
info!("{:?}", user);
let answer =
get_answer_with_references(&state.surreal_db_client, &state.openai_client, &query.query)