cargo fmt
This commit is contained in:
parent
c15188ec9d
commit
8a6c6cda9a
|
@ -1,10 +1,10 @@
|
|||
use crate::config_spec::{CfgField, CfgGroup};
|
||||
use ollama_rs;
|
||||
use ollama_rs::generation::completion::request::GenerationRequest;
|
||||
use regex::Regex;
|
||||
use reqwest::blocking::Client;
|
||||
use reqwest::blocking::Response;
|
||||
use std::error::Error;
|
||||
use ollama_rs;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
pub const CONFIG: CfgGroup<'static> = CfgGroup {
|
||||
|
@ -179,22 +179,23 @@ pub fn summarize(pad_content: String) -> String {
|
|||
let title = captures.get(2).unwrap().as_str();
|
||||
result.push(format!("{}{}", indent, title));
|
||||
}
|
||||
};
|
||||
}
|
||||
result.join("\n")
|
||||
}
|
||||
|
||||
pub fn summarize_with_ollama(pad_content: &str, ollama_pre_prompt: &str, ollama_address: &str, ollama_port: &u16) -> Result<String, Box<dyn Error>> {
|
||||
pub fn summarize_with_ollama(
|
||||
pad_content: &str, ollama_pre_prompt: &str, ollama_address: &str, ollama_port: &u16,
|
||||
) -> Result<String, Box<dyn Error>> {
|
||||
let ollama = ollama_rs::Ollama::new(ollama_address, ollama_port.clone());
|
||||
let model = "qwen2.5:32b".to_string();
|
||||
let prompt = ollama_pre_prompt.to_string() + pad_content;
|
||||
let rt = Runtime::new().unwrap();
|
||||
|
||||
let result = rt.block_on(async {
|
||||
ollama.generate(GenerationRequest::new(model, prompt)).await
|
||||
});
|
||||
let result =
|
||||
rt.block_on(async { ollama.generate(GenerationRequest::new(model, prompt)).await });
|
||||
match result {
|
||||
Ok(res) => {return Ok(res.response)},
|
||||
Err(err) => {return Err(err.into())}
|
||||
Ok(res) => return Ok(res.response),
|
||||
Err(err) => return Err(err.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -1,10 +1,5 @@
|
|||
// Dies ist der Plenumsbot vom Chaos Computer Club Berlin. Mehr Infos zum aktuellen Stand des Projektss in der ReadMe.
|
||||
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::io::IsTerminal;
|
||||
use std::time::Instant;
|
||||
use cccron_lib::config_spec::{self, CfgField, CfgGroup, CfgSpec};
|
||||
use cccron_lib::date;
|
||||
use cccron_lib::email::{self, Email, SimpleEmail};
|
||||
|
@ -18,6 +13,11 @@ use cccron_lib::{trace_var, trace_var_, verboseln};
|
|||
use chrono::{Local, NaiveDate};
|
||||
use clap::{Arg, Command};
|
||||
use colored::Colorize;
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::io::IsTerminal;
|
||||
use std::time::Instant;
|
||||
|
||||
/* ***** Config Spec ***** */
|
||||
const CONFIG_SPEC: CfgSpec<'static> = CfgSpec {
|
||||
|
@ -368,7 +368,10 @@ fn do_announcement(
|
|||
&config["matrix-room-id-2"],
|
||||
is_dry_run(),
|
||||
);
|
||||
let message = format!("{}\n\n{}{}",&config["text-email-greeting"], &body, &config["text-email-signature"]);
|
||||
let message = format!(
|
||||
"{}\n\n{}{}",
|
||||
&config["text-email-greeting"], &body, &config["text-email-signature"]
|
||||
);
|
||||
matrix.send_message_to_two_rooms(&message)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -433,7 +436,10 @@ fn do_reminder(
|
|||
&config["matrix-room-id-2"],
|
||||
is_dry_run(),
|
||||
);
|
||||
let message = format!("{}\n\n{}{}",&config["text-email-greeting"], &body, &config["text-email-signature"]);
|
||||
let message = format!(
|
||||
"{}\n\n{}{}",
|
||||
&config["text-email-greeting"], &body, &config["text-email-signature"]
|
||||
);
|
||||
matrix.send_message_to_two_rooms(&message)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -455,13 +461,20 @@ fn do_protocol(
|
|||
},
|
||||
};
|
||||
let summary_or_toc: String = if ollama_enabled && !toc.is_empty() {
|
||||
let ollama_port: &u16 = &config["hedgedoc-ollama-port"].parse::<u16>().expect("The ollama port wasn't given a valid u16 port, please check the config");
|
||||
match hedgedoc::summarize_with_ollama(&pad_content, &config["hedgedoc-ollama-pre-prompt"], &config["hedgedoc-ollama-address"], ollama_port) {
|
||||
let ollama_port: &u16 = &config["hedgedoc-ollama-port"]
|
||||
.parse::<u16>()
|
||||
.expect("The ollama port wasn't given a valid u16 port, please check the config");
|
||||
match hedgedoc::summarize_with_ollama(
|
||||
&pad_content,
|
||||
&config["hedgedoc-ollama-pre-prompt"],
|
||||
&config["hedgedoc-ollama-address"],
|
||||
ollama_port,
|
||||
) {
|
||||
Ok(ollama_summary) => ollama_summary,
|
||||
Err(err) => {
|
||||
eprintln!("Ollama failed, continuing with standard toc. This was the error Message: {err}");
|
||||
toc.clone()
|
||||
}
|
||||
},
|
||||
}
|
||||
} else {
|
||||
verboseln!("Ollama is disabled, just using toc");
|
||||
|
@ -524,7 +537,10 @@ fn do_protocol(
|
|||
&config["wiki-plenum-page"],
|
||||
&summary_or_toc
|
||||
);
|
||||
let full_message = format!("{}\n\n{}{}",&config["text-email-greeting"], &message, &config["text-email-signature"]);
|
||||
let full_message = format!(
|
||||
"{}\n\n{}{}",
|
||||
&config["text-email-greeting"], &message, &config["text-email-signature"]
|
||||
);
|
||||
matrix.send_message_to_two_rooms(&full_message)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::error::Error;
|
||||
use lazy_static::lazy_static;
|
||||
use std::error::Error;
|
||||
|
||||
use colored::Colorize;
|
||||
use regex::Regex;
|
||||
|
@ -83,8 +83,8 @@ impl std::fmt::Debug for MatrixClient {
|
|||
|
||||
impl MatrixClient {
|
||||
pub fn new(
|
||||
homeserver_url: &str, user_id: &str, access_token: &str, room_id_1: &str,
|
||||
room_id_2: &str, is_dry_run: bool,
|
||||
homeserver_url: &str, user_id: &str, access_token: &str, room_id_1: &str, room_id_2: &str,
|
||||
is_dry_run: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
homeserver_url: homeserver_url.to_string(),
|
||||
|
@ -234,12 +234,9 @@ impl MatrixClient {
|
|||
verboseln!("room event:{}", &endpoint.green());
|
||||
self.put(&endpoint, None, Some(content), false)
|
||||
}
|
||||
pub fn send_message_to_two_rooms(
|
||||
&mut self, message: &str
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
self.send_room_message( &self.room_id_2.clone(), &message,)?;
|
||||
self.send_room_message( &self.room_id_1.clone(), &message,)?;
|
||||
pub fn send_message_to_two_rooms(&mut self, message: &str) -> Result<(), Box<dyn Error>> {
|
||||
self.send_room_message(&self.room_id_2.clone(), &message)?;
|
||||
self.send_room_message(&self.room_id_1.clone(), &message)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue