diff options
| author | salmonik <salmonik@tuta.io> | 2026-07-13 17:21:21 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-07-13 17:21:21 +0200 |
| commit | 4961aae1737b77ff77102d37bf5f37f31a43824e (patch) | |
| tree | e344777946a6d4354312ffb638ece6e9cbbf3a0e /src/events/mod.rs | |
| parent | make cron follow local time zone (diff) | |
| download | senator-sperma-4961aae1737b77ff77102d37bf5f37f31a43824e.tar.gz senator-sperma-4961aae1737b77ff77102d37bf5f37f31a43824e.zip | |
fix assistant and senator
Signed-off-by: salmonik <salmonik@tuta.io>
Diffstat (limited to 'src/events/mod.rs')
| -rw-r--r-- | src/events/mod.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/events/mod.rs b/src/events/mod.rs index 457ebcd..9a193d0 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs | |||
| @@ -335,20 +335,22 @@ pub async fn handle_message( | |||
| 335 | let is_mention = new_message.mentions_user_id(ctx.cache.current_user().id); | 335 | let is_mention = new_message.mentions_user_id(ctx.cache.current_user().id); |
| 336 | let has_keyword = content_lower.contains(&data.config.assistant_keyword); | 336 | let has_keyword = content_lower.contains(&data.config.assistant_keyword); |
| 337 | 337 | ||
| 338 | if (is_mention || has_keyword) && data.config.openrouter_api_key.is_some() { | 338 | if is_mention || has_keyword { |
| 339 | let api_key = data.config.openrouter_api_key.clone().unwrap(); | 339 | let (api_url, api_key, model) = data.config.resolve_llm(); |
| 340 | let model = data.config.openrouter_model.clone().unwrap_or_else(|| { | 340 | let client = crate::openrouter::OpenRouterClient::new(api_url, api_key, model); |
| 341 | "cognitivecomputations/dolphin-mistral-24b-venice-edition:free".into() | ||
| 342 | }); | ||
| 343 | |||
| 344 | let client = crate::openrouter::OpenRouterClient::new(api_key, model); | ||
| 345 | let assistant_prompt = lang::ASSISTANT_SYSTEM_PROMPT; | 341 | let assistant_prompt = lang::ASSISTANT_SYSTEM_PROMPT; |
| 346 | 342 | ||
| 343 | let bot_id = ctx.cache.current_user().id; | ||
| 347 | let mut messages = Vec::new(); | 344 | let mut messages = Vec::new(); |
| 348 | let mut current_msg = Some(new_message.clone()); | 345 | let mut current_msg = Some(new_message.clone()); |
| 349 | for _ in 0..5 { | 346 | for _ in 0..5 { |
| 350 | if let Some(msg) = current_msg { | 347 | if let Some(msg) = current_msg { |
| 351 | messages.push(("user".into(), msg.content.clone())); | 348 | let role = if msg.author.id == bot_id { |
| 349 | "assistant" | ||
| 350 | } else { | ||
| 351 | "user" | ||
| 352 | }; | ||
| 353 | messages.push((role.into(), msg.content.clone())); | ||
| 352 | current_msg = match msg.message_reference.and_then(|r| r.message_id) { | 354 | current_msg = match msg.message_reference.and_then(|r| r.message_id) { |
| 353 | Some(ref_id) => msg.channel_id.message(ctx, ref_id).await.ok(), | 355 | Some(ref_id) => msg.channel_id.message(ctx, ref_id).await.ok(), |
| 354 | None => None, | 356 | None => None, |
