Skip to content

Commit

Permalink
Connect ai dls to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamdavidonuh committed Sep 29, 2024
1 parent 5d82c3a commit 78d4789
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
25 changes: 20 additions & 5 deletions ahnlich/cli/src/connect.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::config::cli::Agent;
use ahnlich_client_rs::{
ai::{AIClient, AIConnManager},
ai::{AIClient, AIConnManager, AIPipeline},
db::{DbClient, DbConnManager, DbPipeline},
prelude::{AIServerResponse, ServerResponse},
};
use ahnlich_types::{db::ServerDBQuery, ServerType};
use ahnlich_types::{ai::AIServerQuery, db::ServerDBQuery, ServerType};
use deadpool::managed::Pool;
use dsl::db::parse_db_query;
use dsl::{ai::parse_ai_query, db::parse_db_query};

use crossterm::style::Stylize;
use serde::Serialize;
Expand Down Expand Up @@ -75,7 +75,22 @@ impl AgentPool {

pub async fn parse_queries(&self, input: &str) -> Result<Vec<String>, String> {
match self {
AgentPool::AI(_pool) => Err(String::from("Unimplemented")),
AgentPool::AI(pool) => {
let queries = parse_ai_query(input).map_err(|err| err.to_string())?;

let server_query = AIServerQuery::from_queries(&queries);

let conn = pool
.get()
.await
.map_err(|err| format!("Could not get ai client connection {err}"))?;

let pipeline = AIPipeline::new_from_queries_and_conn(server_query, conn);

let response = pipeline.exec().await.map_err(|err| err.to_string())?;

Ok(render(response.into_inner()))
}
AgentPool::DB(pool) => {
let queries = parse_db_query(input).map_err(|err| err.to_string())?;

Expand Down Expand Up @@ -112,7 +127,7 @@ fn render(input: Vec<Result<impl Serialize, String>>) -> Vec<String> {
Ok(success) => format_success(
serde_json::to_string_pretty(&success)
.map_err(|err| err.to_string())
.expect("Failed to parse ai success response to json"),
.expect("Failed to parse success response to json"),
),
Err(err) => format_error(err),
})
Expand Down
1 change: 0 additions & 1 deletion ahnlich/cli/src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl Term {
)))?;
stdout.execute(SetForegroundColor(Color::White))?;
stdout.flush()?;
stdout.flush()?;
Ok(())
}

Expand Down

0 comments on commit 78d4789

Please sign in to comment.