Module: CompletionKit::McpTools::Prompts
- Extended by:
- Base
- Defined in:
- app/services/completion_kit/mcp_tools/prompts.rb
Constant Summary collapse
- TOOLS =
{ "prompts_list" => { description: "List all prompts", inputSchema: {type: "object", properties: {}, required: []}, handler: :list }, "prompts_get" => { description: "Get a prompt by ID", inputSchema: {type: "object", properties: {id: {type: "integer", description: "Prompt ID"}}, required: ["id"]}, handler: :get }, "prompts_create" => { description: "Create a prompt", inputSchema: { type: "object", properties: { name: {type: "string"}, description: {type: "string"}, template: {type: "string"}, llm_model: {type: "string"}, tag_names: {type: "array", items: {type: "string"}} }, required: ["name", "template", "llm_model"] }, handler: :create }, "prompts_update" => { description: "Update a prompt", inputSchema: { type: "object", properties: { id: {type: "integer"}, name: {type: "string"}, description: {type: "string"}, template: {type: "string"}, llm_model: {type: "string"}, tag_names: {type: "array", items: {type: "string"}} }, required: ["id"] }, handler: :update }, "prompts_delete" => { description: "Delete a prompt", inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]}, handler: :delete }, "prompts_publish" => { description: "Publish a prompt version, making it the current version", inputSchema: {type: "object", properties: {id: {type: "integer"}}, required: ["id"]}, handler: :publish }, "prompts_suggest_improvement" => { description: "Suggest an improved version of a prompt, grounded in a run's test results and judge feedback. Analyzes the run's responses, scores, and reviews, then returns reasoning plus a rewritten template (preserving {{variables}}) and persists it as a Suggestion. Requires a run that has a prompt (not a judge-only run).", inputSchema: { type: "object", properties: {run_id: {type: "integer", description: "The run whose results ground the improvement."}}, required: ["run_id"] }, handler: :suggest_improvement }, }.freeze
Class Method Summary collapse
- .create(args) ⇒ Object
- .delete(args) ⇒ Object
- .get(args) ⇒ Object
- .list(_args) ⇒ Object
- .publish(args) ⇒ Object
- .suggest_improvement(args) ⇒ Object
- .update(args) ⇒ Object
Methods included from Base
call, definitions, error_result, text_result
Class Method Details
.create(args) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 72 def self.create(args) prompt = Prompt.new(args.slice("name", "description", "template", "llm_model")) prompt.tag_names = args["tag_names"] if args.key?("tag_names") if prompt.save text_result(prompt.reload.as_json) else error_result(prompt.errors..join(", ")) end end |
.delete(args) ⇒ Object
98 99 100 101 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 98 def self.delete(args) Prompt.find(args["id"]).destroy! text_result("Prompt #{args["id"]} deleted") end |
.get(args) ⇒ Object
68 69 70 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 68 def self.get(args) text_result(Prompt.find(args["id"]).as_json) end |
.list(_args) ⇒ Object
64 65 66 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 64 def self.list(_args) text_result(Prompt.order(created_at: :desc).map(&:as_json)) end |
.publish(args) ⇒ Object
103 104 105 106 107 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 103 def self.publish(args) prompt = Prompt.find(args["id"]) prompt.publish! text_result(prompt.reload.as_json) end |
.suggest_improvement(args) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 109 def self.suggest_improvement(args) run = Run.find(args["run_id"]) return error_result("Judge-only runs don't have a prompt to improve.") if run.prompt.nil? result = PromptImprovementService.new(run).suggest suggestion = run.suggestions.create!( prompt: run.prompt, reasoning: result["reasoning"], suggested_template: result["suggested_template"], original_template: result["original_template"] ) text_result( suggestion_id: suggestion.id, prompt_id: run.prompt.id, reasoning: suggestion.reasoning, suggested_template: suggestion.suggested_template, original_template: suggestion.original_template ) end |
.update(args) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/services/completion_kit/mcp_tools/prompts.rb', line 82 def self.update(args) prompt = Prompt.find(args["id"]) attrs = args.except("id").slice("name", "description", "template", "llm_model") if prompt.runs.exists? new_prompt = prompt.clone_as_new_version(attrs) new_prompt.publish! new_prompt.update!(tag_names: args["tag_names"]) if args.key?("tag_names") text_result(new_prompt.reload.as_json) elsif prompt.update(attrs) prompt.update!(tag_names: args["tag_names"]) if args.key?("tag_names") text_result(prompt.reload.as_json) else error_result(prompt.errors..join(", ")) end end |