Skip to content

web search done right

control if alice should be included in api with a feature flag

Mikkel Denker97a9c57082b0
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 93ef1f08..ae6c6b88 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -9,9 +9,10 @@ default-run = "stract"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
-default = ["cors"]
+default = ["cors", "with_alice"]
dev = ["cors"]
cors = []
+with_alice = []
[[bin]]
name = "stract"
diff --git a/core/src/api/alice.rs b/core/src/api/alice.rs
index 59579e38..cf6828f6 100644
--- a/core/src/api/alice.rs
+++ b/core/src/api/alice.rs
@@ -41,7 +41,21 @@ pub async fn save_state(
extract::State(state): extract::State<Arc<super::State>>,
extract::Json(params): extract::Json<SaveStateParams>,
) -> Result<impl IntoResponse, http::StatusCode> {
- if !state.config.with_alice.unwrap_or(true) {
+ // We don't use
+ // #[cfg(not(feature = "with_alice"))]
+ // {
+ // return Err(StatusCode::NOT_FOUND);
+ // }
+ // here since this would result in a bunch of lint warnings.
+ // The following is a bit hacky, but works and is easily readable.
+
+ #[cfg(not(feature = "with_alice"))]
+ let with_alice = false;
+
+ #[cfg(feature = "with_alice")]
+ let with_alice = true;
+
+ if !with_alice {
return Err(StatusCode::NOT_FOUND);
}
@@ -133,7 +147,21 @@ pub async fn alice_route(
Sse<impl Stream<Item = std::result::Result<axum::response::sse::Event, Infallible>>>,
StatusCode,
> {
- if !state.config.with_alice.unwrap_or(true) {
+ // We don't use
+ // #[cfg(not(feature = "with_alice"))]
+ // {
+ // return Err(StatusCode::NOT_FOUND);
+ // }
+ // here since this would result in a bunch of lint warnings.
+ // The following is a bit hacky, but works and is easily readable.
+
+ #[cfg(not(feature = "with_alice"))]
+ let with_alice = false;
+
+ #[cfg(feature = "with_alice")]
+ let with_alice = true;
+
+ if !with_alice {
return Err(StatusCode::NOT_FOUND);
}
diff --git a/core/src/api/docs.rs b/core/src/api/docs.rs
index 10c892df..a172689d 100644
--- a/core/src/api/docs.rs
+++ b/core/src/api/docs.rs
@@ -91,6 +91,22 @@ The API might also change quite a bit during the beta period, but we will try to
Remember to always give proper attributions to the sources you use from the search results."#.to_string(),
);
+
+ #[cfg(not(feature = "with_alice"))]
+ {
+ openapi.paths.paths.remove("/beta/api/alice");
+ openapi.paths.paths.remove("/beta/api/alice/save_state");
+ openapi.paths.paths.remove("/beta/api/fact_check");
+
+ if let Some(components) = openapi.components.as_mut() {
+ components.schemas.remove("SimplifiedWebsite");
+ components.schemas.remove("ExecutionState");
+ components.schemas.remove("EncodedEncryptedState");
+ components.schemas.remove("EncodedSavedState");
+ components.schemas.remove("FactCheckParams");
+ components.schemas.remove("FactCheckResponse");
+ }
+ }
}
}
diff --git a/core/src/config/mod.rs b/core/src/config/mod.rs
index 961ddf82..be157d51 100644
--- a/core/src/config/mod.rs
+++ b/core/src/config/mod.rs
@@ -200,7 +200,6 @@ pub struct ApiConfig {
pub crossencoder_model_path: Option<String>,
pub lambda_model_path: Option<String>,
pub qa_model_path: Option<String>,
- pub with_alice: Option<bool>,
pub bangs_path: String,
pub summarizer_path: String,
pub fact_check_model_path: String,