-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds support for reading configuration values from a YAML file instead of using hard-coded values. This allows for greater flexibility and easier deployment of the application, as the configuration can be customized for each environment.
- Loading branch information
Showing
4 changed files
with
101 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
model: | ||
bedrock: | ||
model_id: anthropic.claude-3-haiku-20240307-v1:0 | ||
region: us-east-1 | ||
aws_profile: my-aws-bedrock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use std::{ | ||
env, fs, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct PolyglotConfig { | ||
pub model: ModelConfig, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct ModelConfig { | ||
pub bedrock: BedrockConfig, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct BedrockConfig { | ||
pub model_id: String, | ||
pub region: String, | ||
pub aws_profile: String, | ||
} | ||
|
||
impl Default for PolyglotConfig { | ||
fn default() -> Self { | ||
Self { | ||
model: ModelConfig { | ||
bedrock: BedrockConfig { | ||
model_id: "anthropic.claude-3-haiku-20240307-v1:0".to_string(), | ||
region: "us-east-1".to_string(), | ||
aws_profile: "my-aws-bedrock".to_string(), | ||
}, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl PolyglotConfig { | ||
pub fn default_file_path() -> PathBuf { | ||
let home_dir = env::var("HOME").unwrap_or_else(|_| ".".to_string()); | ||
let config_path = PathBuf::from(home_dir).join("./config/polyglot_ls.yaml"); | ||
config_path | ||
} | ||
|
||
pub fn try_read_from_file<P: AsRef<Path>>(config_path: P) -> anyhow::Result<Self> { | ||
if config_path.as_ref().exists() { | ||
match fs::read_to_string(&config_path) { | ||
Ok(config_data) => { | ||
let cfg: PolyglotConfig = serde_yaml::from_str(&config_data)?; | ||
cfg | ||
} | ||
Err(err) => anyhow::bail!(err), | ||
}; | ||
} | ||
anyhow::bail!("path does not exists") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters