mirror of
https://github.com/YGGverse/rssto.git
synced 2026-04-01 09:35:28 +00:00
use config file instead of argument options
This commit is contained in:
parent
ec0cca64f3
commit
3e94399ccb
15 changed files with 162 additions and 123 deletions
|
|
@ -1,37 +1,12 @@
|
|||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Argument {
|
||||
// LLM
|
||||
#[arg(long, default_value_t = String::from("http"))]
|
||||
pub llm_scheme: String,
|
||||
#[arg(long, default_value_t = String::from("localhost"))]
|
||||
pub llm_host: String,
|
||||
#[arg(long, default_value_t = 8080)]
|
||||
pub llm_port: u16,
|
||||
|
||||
/// Model name (e.g. `INSAIT-Institute/MamayLM-Gemma-2-9B-IT-v0.1-GGUF` or `ggml-org/gemma-3-1b-it-GGUF`)
|
||||
#[arg(long)]
|
||||
pub llm_model: String,
|
||||
|
||||
/// Initial message for the `content` subject (e.g. `translate to...`)
|
||||
#[arg(long)]
|
||||
pub llm_message: String,
|
||||
|
||||
// Database
|
||||
#[arg(long, default_value_t = String::from("localhost"))]
|
||||
pub mysql_host: String,
|
||||
#[arg(long, default_value_t = 3306)]
|
||||
pub mysql_port: u16,
|
||||
#[arg(long)]
|
||||
pub mysql_username: String,
|
||||
#[arg(long)]
|
||||
pub mysql_password: String,
|
||||
#[arg(long)]
|
||||
pub mysql_database: String,
|
||||
/// Loop update in seconds
|
||||
/// * None to exit on complete
|
||||
#[arg(long, short)]
|
||||
pub update: Option<u64>,
|
||||
/// Path to config file
|
||||
///
|
||||
/// * see `config.toml`
|
||||
#[arg(short, long)]
|
||||
pub config: PathBuf,
|
||||
}
|
||||
|
|
|
|||
27
crates/llm/src/config.rs
Normal file
27
crates/llm/src/config.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use serde::Deserialize;
|
||||
use std::net::IpAddr;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Mysql {
|
||||
pub database: String,
|
||||
pub host: IpAddr,
|
||||
pub password: String,
|
||||
pub port: u16,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Llm {
|
||||
pub scheme: String,
|
||||
pub host: IpAddr,
|
||||
pub port: u16,
|
||||
pub model: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub mysql: Mysql,
|
||||
pub llm: Llm,
|
||||
pub update: Option<u64>,
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
mod argument;
|
||||
mod config;
|
||||
|
||||
use anyhow::Result;
|
||||
use argument::Argument;
|
||||
use mysql::Database;
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -27,34 +27,36 @@ async fn main() -> Result<()> {
|
|||
.init()
|
||||
}
|
||||
|
||||
let arg = Argument::parse();
|
||||
let argument = argument::Argument::parse();
|
||||
let config: config::Config = toml::from_str(&std::fs::read_to_string(argument.config)?)?;
|
||||
|
||||
let llm = LlamaCppClient::new(format!(
|
||||
"{}://{}:{}",
|
||||
arg.llm_scheme, arg.llm_host, arg.llm_port
|
||||
config.llm.scheme, config.llm.host, config.llm.port
|
||||
))?;
|
||||
let db = Database::pool(
|
||||
&arg.mysql_host,
|
||||
arg.mysql_port,
|
||||
&arg.mysql_username,
|
||||
&arg.mysql_password,
|
||||
&arg.mysql_database,
|
||||
&config.mysql.host.to_string(),
|
||||
config.mysql.port,
|
||||
&config.mysql.username,
|
||||
&config.mysql.password,
|
||||
&config.mysql.database,
|
||||
)?;
|
||||
|
||||
let provider_id = {
|
||||
let mut conn = db.connection()?;
|
||||
match conn.provider_id_by_name(&arg.llm_model)? {
|
||||
match conn.provider_id_by_name(&config.llm.model)? {
|
||||
Some(provider_id) => {
|
||||
debug!(
|
||||
"Use existing DB provider #{} matches model name `{}`",
|
||||
provider_id, &arg.llm_model
|
||||
provider_id, &config.llm.model
|
||||
);
|
||||
provider_id
|
||||
}
|
||||
None => {
|
||||
let provider_id = conn.insert_provider(&arg.llm_model)?;
|
||||
let provider_id = conn.insert_provider(&config.llm.model)?;
|
||||
info!(
|
||||
"Provider `{}` not found in database, created new one with ID `{provider_id}`",
|
||||
&arg.llm_model
|
||||
&config.llm.model
|
||||
);
|
||||
provider_id
|
||||
}
|
||||
|
|
@ -71,15 +73,15 @@ async fn main() -> Result<()> {
|
|||
source.content_id
|
||||
);
|
||||
|
||||
let title =
|
||||
llm.chat_completion(ChatCompletionRequest::new(&arg.llm_model).message(
|
||||
Message::user(format!("{}\n{}", arg.llm_message, source.title)),
|
||||
let title = llm
|
||||
.chat_completion(ChatCompletionRequest::new(&config.llm.model).message(
|
||||
Message::user(format!("{}\n{}", config.llm.message, source.title)),
|
||||
))
|
||||
.await?;
|
||||
|
||||
let description =
|
||||
llm.chat_completion(ChatCompletionRequest::new(&arg.llm_model).message(
|
||||
Message::user(format!("{}\n{}", arg.llm_message, source.description)),
|
||||
let description = llm
|
||||
.chat_completion(ChatCompletionRequest::new(&config.llm.model).message(
|
||||
Message::user(format!("{}\n{}", config.llm.message, source.description)),
|
||||
))
|
||||
.await?;
|
||||
|
||||
|
|
@ -97,7 +99,7 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
tx.commit()?;
|
||||
debug!("Queue completed");
|
||||
if let Some(update) = arg.update {
|
||||
if let Some(update) = config.update {
|
||||
debug!("Wait {update} seconds to continue...");
|
||||
std::thread::sleep(std::time::Duration::from_secs(update))
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue