Skip to content

Commit

Permalink
chore: port, redirect, cors config
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Aug 1, 2023
1 parent 0e9fcac commit b183145
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
OPENAI_API_KEY=
QDRANT_URL= #Default: http://localhost:6334
RUST_LOG= #Logging levels: "error", "warn", "info", "debug", "trace"
QDRANT_URL= #Defaults to http://localhost:6334
RUST_LOG= #Logging levels: "error", "warn", "info", "debug", "trace"
WEBSERVER_PORT= #Defaults to 3000
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ actix-rt = "2"
tracing-actix-web = "0.7"
env_logger = "0.10"
tokio = "1"
actix-cors = "0.6.4"
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub const EMBEDDINGS_DIMENSION: usize = 384;

//Actix-web
pub const SSE_CHANNEL_BUFFER_SIZE: usize = 1;
pub const ACTIX_WEB_SERVER_PORT: usize = 3000;
pub const HOME_ROUTE_REDIRECT_URL: &str = "https://opensauced.pizza";

//OpenAI
pub const CHAT_COMPLETION_TEMPERATURE: f64 = 0.7;
Expand Down
13 changes: 9 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ mod routes;
mod utils;
use std::{path::Path, sync::Arc};

use actix_web::{web, App, HttpResponse, HttpServer};
use constants::ACTIX_WEB_SERVER_PORT;
use actix_cors::Cors;
use actix_web::{web, App, HttpServer};
use constants::HOME_ROUTE_REDIRECT_URL;
use env_logger::Env;
use tracing_actix_web::TracingLogger;

Expand All @@ -21,18 +22,22 @@ async fn main() -> std::io::Result<()> {

let model: Arc<embeddings::Onnx> = Arc::new(embeddings::Onnx::new(Path::new("model")).unwrap());
let db: Arc<db::QdrantDB> = Arc::new(db::QdrantDB::initialize().unwrap());
let port = std::env::var("WEBSERVER_PORT").unwrap_or("3000".into());
let port = port.parse::<u16>().expect("Invalid WEBSERVER_PORT");

HttpServer::new(move || {

App::new()
.wrap(Cors::permissive())
.wrap(TracingLogger::default())
.route("/", web::get().to(HttpResponse::Ok))
.service(web::redirect("/", HOME_ROUTE_REDIRECT_URL))
.service(routes::embeddings)
.service(routes::query)
.service(routes::repo)
.app_data(web::Data::new(model.clone()))
.app_data(web::Data::new(db.clone()))
})
.bind(("0.0.0.0", ACTIX_WEB_SERVER_PORT as u16))?
.bind(("0.0.0.0", port))?
.run()
.await
}

0 comments on commit b183145

Please sign in to comment.