From d4bfbd2c1ae662bcb80b7c79cc5d5b3e945a8eba Mon Sep 17 00:00:00 2001 From: iff Date: Sun, 6 Apr 2025 18:15:55 +0200 Subject: [PATCH] feat: additional prompts --- module-request-ai/README.md | 2 ++ module-request-ai/src/requests.rs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/module-request-ai/README.md b/module-request-ai/README.md index 34d0d33..b2b4918 100644 --- a/module-request-ai/README.md +++ b/module-request-ai/README.md @@ -18,6 +18,8 @@ Configuration is done via environment variables: - `_PR_AI_MODEL`: Model used - `_PR_AI_DISABLE`: Setting to any value disables AI integration - `_PR_AI_LOCALE`: Locale in which the AI explains the suggestion. Defaults to user system locale +- `_PR_AI_ADDITIONAL_PROMPT`: Additional prompts to be included. (Yes, you can include role-playing prompts you pervert) + - `You are a cute catgirl. Always use cute phrases and expressions to prove your cuteness in the note, including cat imitations like nya~, にゃ~, 喵~.` Compile time variables: Default values for the respective variables above when not set diff --git a/module-request-ai/src/requests.rs b/module-request-ai/src/requests.rs index 3f31651..bdb8e2c 100644 --- a/module-request-ai/src/requests.rs +++ b/module-request-ai/src/requests.rs @@ -71,8 +71,15 @@ pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option "".to_string() }; + let addtional_prompt = if std::env::var("_PR_AI_ADDITIONAL_PROMPT").is_ok() { + std::env::var("_PR_AI_ADDITIONAL_PROMPT").unwrap() + } else { + "".to_string() + }; + let ai_prompt = format!( r#" +{addtional_prompt} `{last_command}` returns the following error message: `{error_msg}`. Provide possible commands to fix it. Answer in the following exact JSON template without any extra text: ``` {{"commands":["command 1","command 2"],"note":"why they may fix the error{set_locale}"}} @@ -80,6 +87,9 @@ pub fn ai_suggestion(last_command: &str, error_msg: &str) -> Option "# ); + #[cfg(debug_assertions)] + eprintln!("AI module: AI prompt: {}", ai_prompt); + let res; let messages = Messages { messages: vec![Input {