new endpoint and fixes
parent
7e1e3ac38e
commit
fe1827289b
|
|
@ -10,7 +10,7 @@ services:
|
||||||
- NOXIS_LOG_LEVEL=TRACE
|
- NOXIS_LOG_LEVEL=TRACE
|
||||||
- ML_TARGET_URL=http://192.168.249.5:11434/api/generate
|
- ML_TARGET_URL=http://192.168.249.5:11434/api/generate
|
||||||
- ML_MODEL_NAME=kis-test
|
- ML_MODEL_NAME=kis-test
|
||||||
- ML_REQUEST_TIMEOUT=20
|
- ML_REQUEST_TIMEOUT=30
|
||||||
- ML_LOG_LEVEL=TRACE
|
- ML_LOG_LEVEL=TRACE
|
||||||
- ML_API_PORT=5134
|
- ML_API_PORT=5134
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::schemas::InputMetric;
|
use crate::schemas::InputMetric;
|
||||||
use crate::endpoints::rest::__path_model_rest_handler;
|
use crate::endpoints::rest::{__path_model_rest_handler, __path_settings_handler};
|
||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
#[derive(OpenApi)]
|
#[derive(OpenApi)]
|
||||||
|
|
@ -14,7 +14,7 @@ use utoipa::OpenApi;
|
||||||
url = "https://___"
|
url = "https://___"
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
paths(model_rest_handler),
|
paths(model_rest_handler, settings_handler),
|
||||||
components(
|
components(
|
||||||
schemas(InputMetric)
|
schemas(InputMetric)
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ pub mod rest {
|
||||||
use super::{IntoResponse, StatusCode, InputMetric, Json, Config, State};
|
use super::{IntoResponse, StatusCode, InputMetric, Json, Config, State};
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
get,
|
post,
|
||||||
summary = "An endpoint using to REST communication with the Model",
|
summary = "An endpoint using to REST communication with the Model",
|
||||||
path = "/api/metrics/rest",
|
path = "/api/metrics/rest",
|
||||||
request_body = Vec<InputMetric>,
|
request_body = Vec<InputMetric>,
|
||||||
|
|
@ -34,6 +34,22 @@ pub mod rest {
|
||||||
Err(er) => (StatusCode::INTERNAL_SERVER_ERROR, format!("cannot get model response: {er}")),
|
Err(er) => (StatusCode::INTERNAL_SERVER_ERROR, format!("cannot get model response: {er}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
summary = "An endpoint using to get APi's config",
|
||||||
|
path = "/api/settings",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "API shared its config"),
|
||||||
|
),
|
||||||
|
tag = "query"
|
||||||
|
)]
|
||||||
|
pub async fn settings_handler(
|
||||||
|
State(config) : State<Config>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
trace!("GET on /api/settings");
|
||||||
|
(StatusCode::OK, config.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod ws {
|
pub mod ws {
|
||||||
|
|
|
||||||
11
src/main.rs
11
src/main.rs
|
|
@ -8,13 +8,13 @@ use std::sync::Arc;
|
||||||
use tracing::{debug, info, trace};
|
use tracing::{debug, info, trace};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use endpoints::{
|
use endpoints::{
|
||||||
rest::model_rest_handler,
|
rest::{model_rest_handler, settings_handler},
|
||||||
ws::model_ws_handler,
|
ws::model_ws_handler,
|
||||||
};
|
};
|
||||||
use setup::setup_self_config;
|
use setup::setup_self_config;
|
||||||
use models::ApiSessionConfig;
|
use models::ApiSessionConfig;
|
||||||
use axum::{
|
use axum::{
|
||||||
routing::get,
|
routing::{get, post},
|
||||||
Router};
|
Router};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use utoipa_swagger_ui::SwaggerUi;
|
use utoipa_swagger_ui::SwaggerUi;
|
||||||
|
|
@ -35,12 +35,13 @@ async fn main() -> anyhow::Result<()> {
|
||||||
// routing
|
// routing
|
||||||
trace!("configurating routing ...");
|
trace!("configurating routing ...");
|
||||||
let api = Router::new()
|
let api = Router::new()
|
||||||
.route("/rest", get(model_rest_handler))
|
.route("/metrics/rest", post(model_rest_handler))
|
||||||
.route("/ws", get(model_ws_handler))
|
.route("/metrics/ws", get(model_ws_handler))
|
||||||
|
.route("/settings", get(settings_handler))
|
||||||
.with_state(app_state.clone());
|
.with_state(app_state.clone());
|
||||||
|
|
||||||
let router = Router::new()
|
let router = Router::new()
|
||||||
.nest("/api/metrics", api)
|
.nest("/api", api)
|
||||||
.merge(SwaggerUi::new("/swagger").url("/api-docs/openapi.json", ApiDoc::openapi()));
|
.merge(SwaggerUi::new("/swagger").url("/api-docs/openapi.json", ApiDoc::openapi()));
|
||||||
// .route("/swagger", get(swagger));
|
// .route("/swagger", get(swagger));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue