Skip to content

Commit

Permalink
env guarding
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jones <[email protected]>
  • Loading branch information
AlexsJones committed Dec 21, 2023
1 parent 8489fe5 commit 002ea82
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 9 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ tokio = { version = "1", features = ["full"] }
unescape = "0.1.0"
v = "0.1.0"
chrono = "0.4.31"
log = "0.4.20"
env_logger = "0.10.1"

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
5 changes: 4 additions & 1 deletion src/analyze/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::error::Error;
use std::sync::mpsc;
use std::sync::mpsc::{Receiver, Sender};
use std::time::Duration;
use log::warn;

pub async fn list_analyzers() -> Result<(), Box<dyn Error>> {
// Setup available providers
Expand Down Expand Up @@ -149,7 +150,9 @@ pub async fn run_analysis(
// check if the processed results analyzer exists as key
// upsert the analysis result into the vector
}
Err(_e) => (),
Err(e) => (
warn!("{}", e)
),
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/bedrock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,27 @@ impl From<ClaudParams> for Blob {
Blob::new(serde_json::to_string(&val).unwrap())
}
}
pub struct BedrockClient {}
pub struct BedrockClient {
region: Region,
bedrock_model: String
}

impl BedrockClient {
pub fn new() -> Self {
Self {}
Self {
region: Region::new(env::var("BEDROCK_REGION").unwrap().clone()),
bedrock_model: env::var("BEDROCK_MODEL").unwrap().clone()
}
}
pub async fn enrich(&self, prompt: String) -> Result<String, Box<dyn Error>> {
// force the config rejoin be set
let bedrock_region = env::var("BEDROCK_REGION")?.clone();
let region = Region::new(bedrock_region);
let config = aws_config::from_env().region(region).load().await;
let config = aws_config::from_env().region(self.region.clone()).load().await;
let client = aws_sdk_bedrockruntime::Client::new(&config);
let bedrock_model = env::var("BEDROCK_MODEL")?;

let question = format!("{} {}", prompt::DEFAULT_PROMPT, prompt.as_str());

let response = client
.invoke_model()
.model_id(bedrock_model)
.model_id(self.bedrock_model.clone())
.content_type("application/json")
.body(ClaudParams::new(question.as_str()).into())
.send()
Expand Down
21 changes: 21 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;
use std::process::exit;
use clap::{Parser, Subcommand};
mod analyze;
mod analyzer;
Expand Down Expand Up @@ -40,8 +42,27 @@ enum Commands {
resource: String,
},
}

const ENVS: &'static [&'static str] = &["BEDROCK_REGION",
"BEDROCK_MODEL",
"AWS_REGION","AWS_ACCESS_KEY","AWS_SECRET_ACCESS_KEY"];


#[tokio::main]
async fn main() {
env_logger::init();

for e in ENVS {
let r = env::var(e);
match r {
Ok(x) => {},
Err(_e) => {
println!("ENV: {} not found",e);
exit(1);
},
}
}

let args = Args::parse();

match &args.command {
Expand Down

0 comments on commit 002ea82

Please sign in to comment.