Move hardcoded LLM prompts to template files (#3934)
Co-authored-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::config::permission::PermissionLevel;
|
||||
use crate::config::PermissionManager;
|
||||
use crate::conversation::message::{Message, MessageContent, ToolRequest};
|
||||
use crate::conversation::Conversation;
|
||||
use crate::prompt_template::render_global_file;
|
||||
use crate::providers::base::Provider;
|
||||
use chrono::Utc;
|
||||
use indoc::indoc;
|
||||
@@ -13,6 +14,11 @@ use serde_json::Value;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PermissionJudgeContext {
|
||||
// Empty struct for now since the current template doesn't need variables
|
||||
}
|
||||
|
||||
/// Creates the tool definition for checking read-only permissions.
|
||||
fn create_read_only_tool() -> Tool {
|
||||
Tool::new(
|
||||
@@ -133,12 +139,12 @@ pub async fn detect_read_only_tools(
|
||||
let tool = create_read_only_tool();
|
||||
let check_messages = create_check_messages(tool_requests);
|
||||
|
||||
let context = PermissionJudgeContext {};
|
||||
let system_prompt = render_global_file("permission_judge.md", &context)
|
||||
.unwrap_or_else(|_| "You are a good analyst and can detect operations whether they have read-only operations.".to_string());
|
||||
|
||||
let res = provider
|
||||
.complete(
|
||||
"You are a good analyst and can detect operations whether they have read-only operations.",
|
||||
check_messages.messages(),
|
||||
&[tool.clone()],
|
||||
)
|
||||
.complete(&system_prompt, check_messages.messages(), &[tool.clone()])
|
||||
.await;
|
||||
|
||||
// Process the response and return an empty vector if the response is invalid
|
||||
|
||||
Reference in New Issue
Block a user