mod audio;
mod batches;
mod chat;
mod context;
mod embeddings;
mod images;
mod models;
mod provider_selection;
mod responses;
mod responses_stream;
pub use audio::{audio_speech, audio_transcriptions, audio_translations};
pub use batches::{cancel_batch, create_batch, get_batch, list_batches};
pub use chat::chat_completions;
pub use context::{
check_permission, get_authenticated_api_key, get_authenticated_user, get_request_context,
handle_ai_request, log_api_usage,
};
pub use embeddings::embeddings;
pub use images::image_generations;
pub use models::{get_model, list_models};
pub use responses::create_response;
use actix_web::web;
pub fn configure_routes(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/v1")
.route("/chat/completions", web::post().to(chat_completions))
.route("/responses", web::post().to(create_response))
.route("/embeddings", web::post().to(embeddings))
.route("/batches", web::post().to(create_batch))
.route("/batches", web::get().to(list_batches))
.route("/batches/{batch_id}", web::get().to(get_batch))
.route("/batches/{batch_id}/cancel", web::post().to(cancel_batch))
.route("/images/generations", web::post().to(image_generations))
.route("/models", web::get().to(list_models))
.route("/models/{model_id}", web::get().to(get_model))
.route(
"/audio/transcriptions",
web::post().to(audio_transcriptions),
)
.route("/audio/translations", web::post().to(audio_translations))
.route("/audio/speech", web::post().to(audio_speech)),
);
}
#[cfg(test)]
mod tests {
use crate::core::types::context::RequestContext;
use actix_web::{App, http::StatusCode, test};
#[actix_web::test]
async fn test_get_request_context() {
let context = RequestContext::new();
assert!(!context.request_id.is_empty());
assert!(context.user_agent.is_none());
}
#[actix_web::test]
async fn test_batch_routes_mounted_with_expected_methods() {
let app = test::init_service(App::new().configure(super::configure_routes)).await;
let create_req = test::TestRequest::post()
.uri("/v1/batches")
.set_json(serde_json::json!({}))
.to_request();
let create_resp = test::call_service(&app, create_req).await;
assert_eq!(create_resp.status(), StatusCode::NOT_IMPLEMENTED);
let list_req = test::TestRequest::get().uri("/v1/batches").to_request();
let list_resp = test::call_service(&app, list_req).await;
assert_eq!(list_resp.status(), StatusCode::NOT_IMPLEMENTED);
let get_req = test::TestRequest::get()
.uri("/v1/batches/batch_test")
.to_request();
let get_resp = test::call_service(&app, get_req).await;
assert_eq!(get_resp.status(), StatusCode::NOT_IMPLEMENTED);
let cancel_req = test::TestRequest::post()
.uri("/v1/batches/batch_test/cancel")
.to_request();
let cancel_resp = test::call_service(&app, cancel_req).await;
assert_eq!(cancel_resp.status(), StatusCode::NOT_IMPLEMENTED);
}
}