Skip to content

Commit

Permalink
refactor: simplify apis
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 27, 2023
1 parent b6dddc9 commit 1a166fc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
11 changes: 6 additions & 5 deletions counit-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ async fn main() -> anyhow::Result<()> {

let mut config: Configuration;
if config_file.exists() {
let config_string = std::fs::read_to_string(config_file)?;
config = serde_json::from_str(&config_string)?;
config = serde_json::from_str(&std::fs::read_to_string(config_file)?)?;
info!("Configuration loaded from public/config.json");
} else {
config = Configuration::default()
Expand All @@ -37,9 +36,9 @@ async fn main() -> anyhow::Result<()> {
let bind = SocketAddr::new(config.host.parse()?, config.port);
let app = Application::initialize(config).await?;

let mut api = Router::new()
.with_state(app.clone())
let mut api = Router::new().with_state(app.clone())
.route("/", get(root))
// core api for query
.route("/query", get(semantic_api::query))
.route("/text-embedding", get(semantic_api::embedding))

Expand All @@ -48,6 +47,7 @@ async fn main() -> anyhow::Result<()> {

// knowledge init
.nest("/translate/domain-language", translate_api::router())

//align to archguard api
.nest("/scanner", archguard_api::router())
;
Expand All @@ -60,7 +60,8 @@ async fn main() -> anyhow::Result<()> {
.layer(CorsLayer::permissive())
.layer(CatchPanicLayer::new());

let mut router = Router::new().nest("/api", api);
let mut router = Router::new()
.nest("/api", api);

info!(%bind, "starting webserver");

Expand Down
1 change: 1 addition & 0 deletions counit-server/src/model/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod query;
6 changes: 6 additions & 0 deletions counit-server/src/model/dto/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct SimpleQuery {
pub q: String,
}
6 changes: 4 additions & 2 deletions counit-server/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub use archguard_model::*;
pub use chapi_model::*;

pub mod analyser;

pub mod chapi_model;

pub use chapi_model::*;
pub mod archguard_model;
pub use archguard_model::*;
pub mod archguard_openapi;
pub mod dto;
10 changes: 3 additions & 7 deletions counit-server/src/server/agent_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};

use crate::agent::prompts::tool_prompt;
use crate::dsl::query_description::QAExample;
use crate::model::dto::query::SimpleQuery;

pub(crate) fn router() -> Router {
use axum::routing::*;
Expand All @@ -14,18 +15,13 @@ pub(crate) fn router() -> Router {
.route("/prompt/functions/matching", post(tool_prompter))
}

#[derive(Debug, Deserialize)]
pub struct PromptQuery {
pub q: String,
}

#[derive(Serialize)]
pub struct PromptResult {
pub prompt: String,
}

pub(crate) async fn explain_query(
Query(args): Query<PromptQuery>,
Query(args): Query<SimpleQuery>,
) -> (StatusCode, Json<PromptResult>) {
let output = PromptResult {
prompt: QAExample::prompt(&args.q),
Expand All @@ -40,7 +36,7 @@ pub struct PathListArgs {
}

pub(crate) async fn tool_prompter(
Query(args): Query<PromptQuery>,
Query(args): Query<SimpleQuery>,
) -> (StatusCode, Json<PromptResult>) {
let paths = vec![args.q];
let output = PromptResult {
Expand Down
7 changes: 1 addition & 6 deletions counit-server/src/server/semantic_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
use serde::{Deserialize, Serialize};

use crate::application::Application;
use crate::model::dto::query::SimpleQuery;
use crate::repository::{
payload::CodePayload, semantic_query::SemanticQuery,
};
Expand Down Expand Up @@ -57,12 +58,6 @@ pub struct EmbeddingResponse {
pub data: Embedding,
}


#[derive(Debug, Deserialize)]
pub struct SimpleQuery {
pub q: String,
}

#[derive(Debug, Deserialize)]
pub struct ApiQuery {
pub q: String,
Expand Down

0 comments on commit 1a166fc

Please sign in to comment.