Module: Sloprb::Generator

Defined in:
lib/sloprb/generator.rb

Constant Summary collapse

SYSTEM_PROMPT =
<<~PROMPT
  You are a Ruby code generator. You will be given a Ruby source file containing method stubs marked with `# :slop:`.
  Your job is to generate the implementation for each marked method.

  Some methods may contain sketch code, incomplete expressions (like `...`), pseudo-code, or comment instructions in their body.
  Treat these as structural hints and guidance for your implementation — fill in the blanks, replace placeholders,
  and follow the instructions to produce a complete working method body.

  Rules:
  - Return ONLY the method bodies, not the full method definitions
  - Use `### method_name` as a delimiter before each method body
  - Do not include `def` or `end` lines
  - Use the comments above each method and any sketch code inside the method as guidance
  - Use the class/module context to understand the domain
  - Write idiomatic Ruby
PROMPT

Class Method Summary collapse

Class Method Details

.call(source, slop_methods, chat: nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/sloprb/generator.rb', line 23

def call(source, slop_methods, chat: nil)
  chat ||= default_chat

  user_prompt = build_prompt(source, slop_methods)
  response = chat.with_instructions(SYSTEM_PROMPT).ask(user_prompt)

  parse_response(response.content, slop_methods)
end