-
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.
- Loading branch information
Showing
14 changed files
with
181 additions
and
52 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
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ target/ | |
Cargo.lock | ||
**/*.rs.bk | ||
*.pdb | ||
config.toml |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
members = ["rimc", "rimc-cli"] | ||
members = ["rim", "rim-cli"] | ||
resolver = "2" | ||
|
||
[profile.release] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
[package] | ||
name = "rimc-cli" | ||
version = "0.1.0" | ||
name = "rim-cli" | ||
version = "0.1.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
librimc = { path = "../rimc" } | ||
librim = { path = "../rim" } | ||
clap = { version= "4.5.4", features=["derive"] } | ||
toml = { version = "0.8.12"} | ||
|
||
[[bin]] | ||
name = "rimc" | ||
name = "rim" | ||
path = "src/cli.rs" |
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,40 @@ | ||
use clap::{Args, Parser}; | ||
use librim::client::RimClient; | ||
|
||
mod conf; | ||
|
||
#[derive(Args)] | ||
#[group(required = true, multiple = false)] | ||
struct Opts { | ||
#[arg(short = 'f', long, name = "FILE")] | ||
file: Option<String>, | ||
|
||
#[arg(short = 'd', long, name = "DIR")] | ||
dir: Option<String>, | ||
} | ||
|
||
#[derive(Parser)] | ||
struct Cli { | ||
#[command(flatten)] | ||
opt: Opts, | ||
|
||
#[arg(short = 'c', long, name = "CONFIG")] | ||
config: String, | ||
} | ||
|
||
fn main() { | ||
let cli = Cli::parse(); | ||
|
||
let (prompt, gemini_keys, _) = conf::load(&cli.config).expect("Failed to decode TOML config"); | ||
|
||
let client = RimClient::build("gemini", prompt, gemini_keys); | ||
|
||
let _ = client.log_prompt(); | ||
|
||
// let opt = &cli.opt; | ||
// if let Some(file_path) = opt.file.as_deref() { | ||
// let _ = single_cap(file_path, cli.config); | ||
// } else if let Some(dir_path) = opt.dir.as_deref() { | ||
// let _ = batch_cap(dir_path, cli.config); | ||
// } | ||
} |
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,40 @@ | ||
use toml::Value; | ||
use std::fs; | ||
|
||
pub fn load(path: &str) -> Result<(String, Vec<String>, Vec<String>), Box<dyn std::error::Error>> { | ||
let toml_str = fs::read_to_string(path)?; | ||
let toml_value: Value = toml::from_str(&toml_str)?; | ||
|
||
let prompt = toml_value | ||
.get("prompt") | ||
.ok_or("Missing 'prompt' key in TOML")? | ||
.get("value") | ||
.ok_or("Missing 'value' key ")? | ||
.as_str() | ||
.ok_or("Invalid type for 'prompt'")? | ||
.to_string(); | ||
|
||
let gemini_keys = toml_value | ||
.get("gemini") | ||
.ok_or("Missing 'gemini' table in TOML")? | ||
.get("keys") | ||
.ok_or("Missing 'keys' key in 'gemini' table")? | ||
.as_array() | ||
.ok_or("Invalid type for 'gemini.keys'")? | ||
.iter() | ||
.map(|value| value.as_str().unwrap().to_string()) // Assuming keys are strings | ||
.collect(); | ||
|
||
let gpt4v_keys = toml_value | ||
.get("gpt4v") | ||
.ok_or("Missing 'gpt4v' table in TOML")? | ||
.get("keys") | ||
.ok_or("Missing 'keys' key in 'gpt4v' table")? | ||
.as_array() | ||
.ok_or("Invalid type for 'gpt4v.keys'")? | ||
.iter() | ||
.map(|value| value.as_str().unwrap().to_string()) // Assuming keys are strings | ||
.collect(); | ||
|
||
Ok((prompt, gemini_keys, gpt4v_keys)) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[package] | ||
name = "librimc" | ||
name = "librim" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tokio = { version = "1.37.0", features = ["full"] } | ||
|
||
[lib] | ||
name = "librimc" | ||
name = "librim" | ||
path = "src/lib.rs" |
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,49 @@ | ||
use super::model::google::Gemini; | ||
use super::model::openai::GPT; | ||
|
||
pub trait LLM { | ||
fn generate_caption(&self) -> Result<String, Box<dyn std::error::Error>>; | ||
fn log_prompt(&self) -> &String; | ||
} | ||
|
||
impl LLM for Gemini { | ||
fn generate_caption(&self) -> Result<String, Box<dyn std::error::Error>> { | ||
Ok("Gemini Caption".to_string()) | ||
} | ||
|
||
fn log_prompt(&self) -> &String{ | ||
&self.get_prompt() | ||
} | ||
} | ||
|
||
impl LLM for GPT { | ||
fn generate_caption(&self) -> Result<String, Box<dyn std::error::Error>> { | ||
Ok("GPT4V Caption".to_string()) | ||
} | ||
fn log_prompt(&self) -> &String{ | ||
&self.get_prompt() | ||
} | ||
} | ||
|
||
pub struct RimClient { | ||
client: Box<dyn LLM>, | ||
} | ||
|
||
impl RimClient { | ||
pub fn build(client_type: &str, prompt: String, keys: Vec<String>) -> Self { | ||
let client: Box<dyn LLM> = match client_type { | ||
"gemini" => Box::new(Gemini::build(prompt, keys)), | ||
"gpt" => Box::new(GPT::build(prompt, keys)), | ||
_ => panic!("Invalid client type"), | ||
}; | ||
Self { client } | ||
} | ||
|
||
pub fn generate_caption(&self) -> Result<String, Box<dyn std::error::Error>> { | ||
self.client.generate_caption() | ||
} | ||
|
||
pub fn log_prompt(&self) { | ||
println!("Prompt: {}", self.client.log_prompt()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pub struct Gemini { | ||
prompt: String, | ||
keys: Vec<String>, | ||
} | ||
|
||
impl Gemini { | ||
pub fn build(prompt: String, keys: Vec<String>) -> Self { | ||
Self { prompt, keys } | ||
} | ||
pub fn get_prompt(&self) -> &String{ | ||
&self.prompt | ||
} | ||
} |
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,2 @@ | ||
pub mod google; | ||
pub mod openai; |
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,13 @@ | ||
pub struct GPT { | ||
prompt: String, | ||
keys: Vec<String>, | ||
} | ||
|
||
impl GPT { | ||
pub fn build(prompt: String, keys: Vec<String>) -> Self { | ||
Self { prompt, keys } | ||
} | ||
pub fn get_prompt(&self) -> &String{ | ||
&self.prompt | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.