Class: MonkeysPaw::HtmlFromDescriptionGenerator

Inherits:
Sublayer::Generators::Base
  • Object
show all
Defined in:
lib/monkeyspaw/generators/html_from_description_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(description:, layout_prompt: nil, style_prompt: nil) ⇒ HtmlFromDescriptionGenerator

Returns a new instance of HtmlFromDescriptionGenerator.



7
8
9
10
11
# File 'lib/monkeyspaw/generators/html_from_description_generator.rb', line 7

def initialize(description:, layout_prompt: nil, style_prompt: nil)
  @description = description
  @layout_prompt = layout_prompt
  @style_prompt = style_prompt
end

Instance Method Details

#generateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/monkeyspaw/generators/html_from_description_generator.rb', line 13

def generate
  max_retries = 3
  retry_count = 0

  begin
    super
  rescue => e
    retry_count += 1
    if retry_count <= max_retries
      puts "Generator attempt #{retry_count}/#{max_retries} failed: #{e.message}. Retrying..."
      sleep(1) # Add a small delay between retries
      retry
    else
      puts "Generator failed after #{max_retries} attempts. Last error: #{e.message}"
      raise
    end
  end
end

#promptObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/monkeyspaw/generators/html_from_description_generator.rb', line 32

def prompt
  layout_section = ""
  style_section = ""

  if @layout_prompt
    layout_section = <<~LAYOUT_SECTION
      ## Layout Requirements:
      #{@layout_prompt}
    LAYOUT_SECTION
  end

  if @style_prompt
    style_section = <<~STYLE_SECTION
      ## Style Guidelines:
      #{@style_prompt}
    STYLE_SECTION
  end

  <<~PROMPT
    You are an expert HTML developer.

    You are tasked with writing HTML code based on the following description:

    #{@description}

    #{layout_section}
    #{style_section}

    Take a deep breath and think step by step before you start coding. Ensure the HTML is well-formed and valid.

    The three components work together as follows:
    1. The page description provides the specific content and features this page should have
    2. The layout requirements define the structural organization and placement of elements
    3. The style guidelines inform the visual presentation and aesthetic choices

    Harmonize these elements to create a cohesive and effective web page that fulfills the intended purpose.
  PROMPT
end