fix: cors in /, stop words removal (#171)

support-coreml
Meng Zhang 2023-05-30 17:12:10 -07:00 committed by GitHub
parent f3b37b253b
commit b8d67770ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 8 deletions

View File

@ -37,7 +37,7 @@ pub enum Event<'a> {
completion_id: &'a str,
choice_index: u32,
},
Selected {
Select {
completion_id: &'a str,
choice_index: u32,
},

View File

@ -3,13 +3,12 @@ use regex::Regex;
use std::collections::HashMap;
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> = {
let mut map = HashMap::new();
map.insert("unknown", Regex::new(r"(?m)^(\n\n)").unwrap());
map.insert(
"python",
Regex::new(r"(?m)^(\n\n|def|#|from|class)").unwrap(),
Regex::new(r"(?m)(\n\n|^def|^#|^from|^class)").unwrap(),
);
map
};

View File

@ -26,8 +26,8 @@ pub async fn log_event(Json(request): Json<LogEventRequest>) -> StatusCode {
}
.log();
StatusCode::OK
} else if request.event_type == "selected" {
events::Event::Selected {
} else if request.event_type == "select" {
events::Event::Select {
completion_id: &request.completion_id,
choice_index: request.choice_index,
}

View File

@ -66,7 +66,8 @@ pub async fn main(args: &ServeArgs) -> Result<(), Error> {
let app = Router::new()
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
.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));
println!("Listening at {}", address);
@ -81,7 +82,6 @@ fn api_router(args: &ServeArgs) -> Router {
routing::post(completions::completion)
.with_state(Arc::new(completions::CompletionState::new(args))),
)
.layer(CorsLayer::permissive())
}
fn fallback(experimental_admin_panel: bool) -> routing::MethodRouter {