diff --git a/src/session/mod.rs b/src/session/mod.rs index 263a7b5d..fabe215e 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::error::Error; use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; use uuid::Uuid; #[derive(Clone, Serialize, Deserialize)] @@ -25,6 +26,7 @@ pub struct SessionManager { sessions: HashMap, waiting_for_input: HashSet, redis: Option>, + interaction_counts: HashMap, } impl SessionManager { @@ -34,6 +36,7 @@ impl SessionManager { sessions: HashMap::new(), waiting_for_input: HashSet::new(), redis: redis_client, + interaction_counts: HashMap::new(), } } @@ -304,6 +307,67 @@ impl SessionManager { Ok(String::new()) } + pub fn increment_and_get_interaction_count( + &mut self, + session_id: Uuid, + user_id: Uuid, + ) -> Result> { + use redis::Commands; + + let redis_key = format!("interactions:{}:{}", user_id, session_id); + let count = if let Some(redis_client) = &self.redis { + let mut conn = redis_client.get_connection()?; + let count: usize = conn.incr(&redis_key, 1)?; + count + } else { + let counter = self.interaction_counts + .entry(session_id) + .or_insert(AtomicUsize::new(0)); + counter.fetch_add(1, Ordering::SeqCst) + 1 + }; + Ok(count) + } + + pub fn replace_conversation_history( + &mut self, + sess_id: Uuid, + user_uuid: Uuid, + new_history: &[(String, String)], + ) -> Result<(), Box> { + use crate::shared::models::message_history::dsl::*; + + // Delete existing history + diesel::delete(message_history) + .filter(session_id.eq(sess_id)) + .execute(&mut self.conn)?; + + // Insert new compacted history + for (idx, (role_str, content)) in new_history.iter().enumerate() { + let role_num = match role_str.as_str() { + "user" => 1, + "assistant" => 2, + "system" => 3, + _ => 0, + }; + + diesel::insert_into(message_history) + .values(( + id.eq(Uuid::new_v4()), + session_id.eq(sess_id), + user_id.eq(user_uuid), + role.eq(role_num), + content_encrypted.eq(content), + message_type.eq(1), + message_index.eq(idx as i64), + created_at.eq(chrono::Utc::now()), + )) + .execute(&mut self.conn)?; + } + + info!("Replaced conversation history for session {}", sess_id); + Ok(()) + } + pub fn get_conversation_history( &mut self, sess_id: Uuid, diff --git a/templates/announcements.gbai/annoucements.gbot/config.csv b/templates/announcements.gbai/annoucements.gbot/config.csv index 9602c420..f056cf02 100644 --- a/templates/announcements.gbai/annoucements.gbot/config.csv +++ b/templates/announcements.gbai/annoucements.gbot/config.csv @@ -1,5 +1,2 @@ name,value prompt-compact, 10 -prompt-cache,true -prompt-fixed-kb,geral -response-suggestions,true diff --git a/templates/default.gbai/default.gbot/config.csv b/templates/default.gbai/default.gbot/config.csv index 6a7790b7..dbe0d8b0 100644 --- a/templates/default.gbai/default.gbot/config.csv +++ b/templates/default.gbai/default.gbot/config.csv @@ -17,8 +17,8 @@ llm-server-host,0.0.0.0 llm-server-port,8081 llm-server-gpu-layers,0 llm-server-n-moe,0 -llm-server-ctx-size,512 -llm-server-n-predict,256 +llm-server-ctx-size,2048 +llm-server-n-predict,512 llm-server-parallel,6 llm-server-cont-batching,true llm-server-mlock,false diff --git a/web/html/index.html b/web/html/index.html index 0b3f63c7..2837a0e3 100644 --- a/web/html/index.html +++ b/web/html/index.html @@ -1,2023 +1,204 @@ - - - General Bots - - - - - - - - -
-
- - - - - - -
-
- - -
- - - -
-
-
- General Bots Logo -
-

- Bem-vindo ao General Bots -

-

Seu assistente de IA avançado

-
-
- -
-
- - -
-
-
- - - - - - - - + + +General Bots + + + + + + + + +
+ + + +
+
+ + +
+ +
+
+
GB
+

Bem-vindo ao General Bots

+

Seu assistente de IA avançado

+
+
+
+
+ + +
+
+
+ + + + + \ No newline at end of file