Class: RubynCode::LLM::MessageBuilder
- Inherits:
-
Object
- Object
- RubynCode::LLM::MessageBuilder
- Defined in:
- lib/rubyn_code/llm/message_builder.rb
Constant Summary collapse
- SYSTEM_TEMPLATE =
<<~PROMPT You are an AI coding assistant operating inside a developer's project. Project path: %<project_path>s %<skills_section>s %<instincts_section>s PROMPT
Instance Method Summary collapse
- #build_system_prompt(skills: [], instincts: [], project_path: Dir.pwd) ⇒ Object
- #format_messages(conversation) ⇒ Object
- #format_tool_results(results) ⇒ Object
Instance Method Details
#build_system_prompt(skills: [], instincts: [], project_path: Dir.pwd) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubyn_code/llm/message_builder.rb', line 51 def build_system_prompt(skills: [], instincts: [], project_path: Dir.pwd) skills_section = if skills.empty? '' else "## Available Skills\n#{skills.map { |s| "- #{s}" }.join("\n")}" end instincts_section = if instincts.empty? '' else "## Learned Instincts\n#{instincts.map { |i| "- #{i}" }.join("\n")}" end format( SYSTEM_TEMPLATE, project_path: project_path, skills_section: skills_section, instincts_section: instincts_section ).strip end |
#format_messages(conversation) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rubyn_code/llm/message_builder.rb', line 72 def (conversation) conversation.map do |msg| case msg in { role: String => role, content: String => content } { role: role, content: content } in { role: String => role, content: Array => blocks } { role: role, content: format_content_blocks(blocks) } else msg.transform_keys(&:to_s) end end end |
#format_tool_results(results) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rubyn_code/llm/message_builder.rb', line 85 def format_tool_results(results) content = results.map do |result| { type: 'tool_result', tool_use_id: result[:tool_use_id] || result[:id], content: result[:content].to_s, **(result[:is_error] ? { is_error: true } : {}) } end { role: 'user', content: content } end |