fix: cors in /, stop words removal (#171)
parent
f3b37b253b
commit
b8d67770ee
|
|
@ -37,7 +37,7 @@ pub enum Event<'a> {
|
||||||
completion_id: &'a str,
|
completion_id: &'a str,
|
||||||
choice_index: u32,
|
choice_index: u32,
|
||||||
},
|
},
|
||||||
Selected {
|
Select {
|
||||||
completion_id: &'a str,
|
completion_id: &'a str,
|
||||||
choice_index: u32,
|
choice_index: u32,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@ use regex::Regex;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref DEFAULT: Regex = Regex::new(r"(?m)^\n\n").unwrap();
|
static ref DEFAULT: Regex = Regex::new(r"(?m)\n\n").unwrap();
|
||||||
static ref LANGUAGES: HashMap<&'static str, Regex> = {
|
static ref LANGUAGES: HashMap<&'static str, Regex> = {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("unknown", Regex::new(r"(?m)^(\n\n)").unwrap());
|
|
||||||
map.insert(
|
map.insert(
|
||||||
"python",
|
"python",
|
||||||
Regex::new(r"(?m)^(\n\n|def|#|from|class)").unwrap(),
|
Regex::new(r"(?m)(\n\n|^def|^#|^from|^class)").unwrap(),
|
||||||
);
|
);
|
||||||
map
|
map
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ pub async fn log_event(Json(request): Json<LogEventRequest>) -> StatusCode {
|
||||||
}
|
}
|
||||||
.log();
|
.log();
|
||||||
StatusCode::OK
|
StatusCode::OK
|
||||||
} else if request.event_type == "selected" {
|
} else if request.event_type == "select" {
|
||||||
events::Event::Selected {
|
events::Event::Select {
|
||||||
completion_id: &request.completion_id,
|
completion_id: &request.completion_id,
|
||||||
choice_index: request.choice_index,
|
choice_index: request.choice_index,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ pub async fn main(args: &ServeArgs) -> Result<(), Error> {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
|
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
|
||||||
.nest("/v1", api_router(args))
|
.nest("/v1", api_router(args))
|
||||||
.fallback(fallback(args.experimental_admin_panel));
|
.fallback(fallback(args.experimental_admin_panel))
|
||||||
|
.layer(CorsLayer::permissive());
|
||||||
|
|
||||||
let address = SocketAddr::from((Ipv4Addr::UNSPECIFIED, args.port));
|
let address = SocketAddr::from((Ipv4Addr::UNSPECIFIED, args.port));
|
||||||
println!("Listening at {}", address);
|
println!("Listening at {}", address);
|
||||||
|
|
@ -81,7 +82,6 @@ fn api_router(args: &ServeArgs) -> Router {
|
||||||
routing::post(completions::completion)
|
routing::post(completions::completion)
|
||||||
.with_state(Arc::new(completions::CompletionState::new(args))),
|
.with_state(Arc::new(completions::CompletionState::new(args))),
|
||||||
)
|
)
|
||||||
.layer(CorsLayer::permissive())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fallback(experimental_admin_panel: bool) -> routing::MethodRouter {
|
fn fallback(experimental_admin_panel: bool) -> routing::MethodRouter {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue