correct plenum bot config folders

This commit is contained in:
murmeldin 2025-02-09 00:49:39 +01:00
parent 8a6c6cda9a
commit 8df8d6eee6
7 changed files with 63 additions and 102 deletions

View file

@ -1,25 +0,0 @@
{pkgs ? import <nixpkgs> {}}: let
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain";
paths = with pkgs; [rustc cargo rustPlatform.rustcSrc rustfmt clippy];
};
in
pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [
rust-toolchain
pkg-config
xe
xz
cargo-tarpaulin
openssl
sqlite
gcc
gnumake
# dotnet-sdk_8
];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}

View file

@ -1,4 +1,5 @@
use crate::config_spec::{CfgField, CfgGroup};
use crate::key_value::KeyValueStore;
use ollama_rs;
use ollama_rs::generation::completion::request::GenerationRequest;
use regex::Regex;
@ -152,56 +153,64 @@ impl HedgeDoc {
Err(format!("Failed to import note: {}", res.status()).into())
}
}
}
pub fn extract_metadata(pad_content: String) -> String {
let re_yaml = Regex::new(r"(?s)---\s*(.*?)\s*(?:\.\.\.|---)").unwrap();
re_yaml.captures_iter(&pad_content).map(|c| c[1].to_string()).collect::<Vec<_>>().join("\n")
}
pub fn strip_metadata(pad_content: String) -> String {
let re_yaml = Regex::new(r"(?s)---\s*.*?\s*(?:\.\.\.|---)").unwrap();
let pad_content = re_yaml.replace_all(&pad_content, "").to_string();
let re_comment = Regex::new(r"(?s)<!--.*?-->").unwrap();
let content_without_comments = re_comment.replace_all(&pad_content, "").to_string();
content_without_comments.trim().to_string()
}
pub fn summarize(pad_content: String) -> String {
// 1. remove HTML comments
let pad_content = strip_metadata(pad_content);
// 2. accumulate topic lines
let re_header = Regex::new(r"^\s*##(#*) TOP ([\d.]+\s*.*?)\s*#*$").unwrap();
let mut result: Vec<String> = Vec::new();
for line in pad_content.lines() {
if let Some(captures) = re_header.captures(line) {
let indent = " ".repeat(captures.get(1).unwrap().as_str().len());
let title = captures.get(2).unwrap().as_str();
result.push(format!("{}{}", indent, title));
}
pub fn rotate(config: &KeyValueStore, is_dry_run: bool) -> Result<String, Box<dyn Error>> {
let hold_pad_id = &config["hedgedoc-next-id"];
config.set("hedgedoc-last-id", hold_pad_id);
let new_id = HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad()?;
config.set("hedgedoc-next-id", &new_id);
Ok(new_id)
}
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>> {
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();
pub fn extract_metadata(pad_content: String) -> String {
let re_yaml = Regex::new(r"(?s)---\s*(.*?)\s*(?:\.\.\.|---)").unwrap();
re_yaml.captures_iter(&pad_content).map(|c| c[1].to_string()).collect::<Vec<_>>().join("\n")
}
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()),
pub fn strip_metadata(pad_content: String) -> String {
let re_yaml = Regex::new(r"(?s)---\s*.*?\s*(?:\.\.\.|---)").unwrap();
let pad_content = re_yaml.replace_all(&pad_content, "").to_string();
let re_comment = Regex::new(r"(?s)<!--.*?-->").unwrap();
let content_without_comments = re_comment.replace_all(&pad_content, "").to_string();
content_without_comments.trim().to_string()
}
pub fn summarize(&self, pad_content: String) -> String {
// 1. remove HTML comments
let pad_content = Self::strip_metadata(pad_content);
// 2. accumulate topic lines
let re_header = Regex::new(r"^\s*##(#*) TOP ([\d.]+\s*.*?)\s*#*$").unwrap();
let mut result: Vec<String> = Vec::new();
for line in pad_content.lines() {
if let Some(captures) = re_header.captures(line) {
let indent = " ".repeat(captures.get(1).unwrap().as_str().len());
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>> {
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 });
match result {
Ok(res) => return Ok(res.response),
Err(err) => return Err(err.into()),
}
}
}
/// For the config, make a new pad ID (by actually making a pad.)
fn make_pad_id(
pub fn make_pad_id(
_key: &str, config: &crate::key_value::KeyValueStore, is_dry_run: bool,
) -> Result<String, Box<dyn Error>> {
HedgeDoc::new(&config.get("hedgedoc-server-url").unwrap(), is_dry_run).create_pad()
}
}

View file

@ -263,21 +263,6 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
fn rotate(future_pad_id: &str, kv: &KV) {
let next_plenum_pad = kv.get("zukünftiges-plenumspad").ok();
if let Some(next_plenum_pad) = next_plenum_pad {
kv.set("aktuelles-plenumspad", &next_plenum_pad)
.expect("Fehler beim Beschreiben der Datenbank mit neuem Plenumslink!"); // Beispiel: aktuelles-plenumspad: Ok(Some("eCH24zXGS9S8Stg5xI3aRg"))
kv.set("zukünftiges-plenumspad", future_pad_id)
.expect("Fehler beim Beschreiben der Datenbank mit neuem Plenumslink!");
// Beispiel: aktuelles-plenumspad: Ok(Some("eCH24zXGS9S8Stg5xI3aRg"))
} else {
kv.set("zukünftiges-plenumspad", future_pad_id)
.expect("Fehler beim Beschreiben der Datenbank mit neuem Plenumslink!");
// Beispiel: aktuelles-plenumspad: Ok(Some("eCH24zXGS9S8Stg5xI3aRg"))
}
}
/* ***** formatting helpers ***** */
fn relative_date(ttp: i64) -> String {
@ -497,6 +482,8 @@ fn do_protocol(
);
let _message_id = send_email(&subject, &body, email, config)?;
mediawiki::pad_ins_wiki(pad_content, wiki, plenum_day)?;
let new_id = hedgedoc::rotate(config, is_dry_run())?;
println!("Generated new pad with id '{}'", new_id);
config.set("state-name", &ProgramState::Logged.to_string()).ok();
} else {
verboseln!("There were no TOPs on this Plenum");

View file

@ -3,7 +3,6 @@ Description=CCCB Plenum-Bot
After=network-online.target
[Service]
WorkingDirectory=/home/$User/plenum-bot
ExecStart=./util/run_release.sh
Type=simple
User=root
WorkingDirectory=%h
ExecStart=.cargo/bin/Plenum-Bot -f .config/Plenum-Bot.sqlite
Type=simple

View file

@ -1,7 +1,5 @@
#!/bin/sh
# This script is being ran every time the systemd job is triggered
# This script can be run in order to change the Plenum-Bot config
u=$USER
../target/release/Plenum-Bot -f /home/$u/.config/plenum-bot/config.sqlite -c
$HOME/.cargo/bin/Plenum-Bot -f .config/Plenum-Bot.sqlite -c

View file

@ -1,7 +0,0 @@
#!/bin/sh
# This script is being ran every time the systemd job is triggered
u=$USER
../target/release/Plenum-Bot -f /home/$u/.config/plenum-bot/config.sqlite

View file

@ -3,9 +3,9 @@
# This script can be run to update or newly install
# the systemd services needed for
sudo -i
cat ../systemd/plenumbot.service > /etc/systemd/system/plenumsbot.service
cat ../systemd/plenumbot.timer > /etc/systemd/system/plenumsbot.timer
chmod 755 /etc/systemd/system/plenumsbot.timer
chmod 755 /etc/systemd/system/plenumsbot.service
cat ../systemd/plenumbot.service > $HOME/.config/systemd/user/Plenum-Bot.service
cat ../systemd/plenumbot.timer > $HOME/.config/systemd/user/Plenum-Bot.timer
chmod 755 $HOME/.config/systemd/user/Plenum-Bot.timer
chmod 755 $HOME/.config/systemd/user/Plenum-Bot.service
systemctl daemon-reload
systemctl daemon-reload --user