Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add port to config #37

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions atoma-inference/src/jrpc_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use tokio::sync::{mpsc, oneshot};

pub type RequestSender = mpsc::Sender<(Value, oneshot::Sender<Value>)>;

pub async fn run(sender: RequestSender) {
pub async fn run(sender: RequestSender, port: u64) {
let (shutdown_signal_sender, mut shutdown_signal_receiver) = mpsc::channel::<()>(1);
let app = Router::new()
.route("/", post(jrpc_call))
.route("/healthz", post(healthz))
.layer(Extension(Arc::new(sender)))
.layer(Extension(Arc::new(shutdown_signal_sender)));

let listener = tokio::net::TcpListener::bind("0.0.0.0:21212")
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}"))
.await
.unwrap();
axum::serve(listener, app)
Expand Down
3 changes: 2 additions & 1 deletion atoma-inference/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async fn main() -> Result<(), ModelServiceError> {
.expect("Incorrect private key bytes length");

let private_key = PrivateKey::from(private_key_bytes);
let jrpc_port = model_config.jrpc_port();
let mut service = ModelService::start(model_config, private_key, req_receiver)
.expect("Failed to start inference service");

Expand All @@ -27,7 +28,7 @@ async fn main() -> Result<(), ModelServiceError> {
Ok::<(), ModelServiceError>(())
});

jrpc_server::run(req_sender).await;
jrpc_server::run(req_sender, jrpc_port).await;

Ok(())
}
14 changes: 14 additions & 0 deletions atoma-inference/src/models/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct ModelsConfig {
flush_storage: bool,
models: Vec<ModelConfig>,
tracing: bool,
jrpc_port: u64,
}

impl ModelsConfig {
Expand All @@ -71,13 +72,15 @@ impl ModelsConfig {
flush_storage: bool,
models: Vec<ModelConfig>,
tracing: bool,
jrpc_port: u64,
) -> Self {
Self {
api_key,
cache_dir,
flush_storage,
models,
tracing,
jrpc_port,
}
}

Expand All @@ -101,6 +104,10 @@ impl ModelsConfig {
self.tracing
}

pub fn jrpc_port(&self) -> u64 {
self.jrpc_port
}

pub fn from_file_path(config_file_path: PathBuf) -> Self {
let builder = Config::builder().add_source(config::File::with_name(
config_file_path.to_str().as_ref().unwrap(),
Expand Down Expand Up @@ -137,12 +144,18 @@ impl ModelsConfig {
.parse()
.unwrap();

let jrpc_port = std::env::var("JRPC_PORT")
.expect("Failed to retrieve jrpc port from .env file")
.parse()
.unwrap();

Self {
api_key,
cache_dir,
flush_storage,
models,
tracing,
jrpc_port,
}
}
}
Expand All @@ -165,6 +178,7 @@ pub mod tests {
true,
)],
true,
18001,
);

let toml_str = toml::to_string(&config).unwrap();
Expand Down