Code_Generation_From_Description
This code snippet defines a class named `CodeFromDescriptionGenerator` which inherits from `Sublayer::Generators::Base`. The class is designed to generate code based on a given description and a set of technologies. It uses a low-level model (llm) output adapter of type `:single_string` to return the generated code as a single string. The `initialize` method takes in a `description` of the task and a list of `technologies` to be used for code generation. The `generate` method is intended to generate the code, calling upon the `super` method presumably to utilize functionality from its parent class. The `prompt` method constructs and returns a multi-line string that encourages the programmer to think critically before starting to code based on the provided task description and technologies. Noteworthy is the usage of `heredoc` syntax (`<<-PROMPT`) for creating the prompt string, providing a clear and readable way to include multi-line strings in Ruby.
class CodeFromDescriptionGenerator < Sublayer::Generators::Base
llm_output_adapter type: :single_string,
name: "generated_code",
description: "The generated code in the requested language"
def initialize(description:, technologies:)
@description = description
@technologies = technologies
end
def generate
super
end
def prompt
<<-PROMPT
You are an expert programmer in #{@technologies.join(", ")}.
You are tasked with writing code using the following technologies: #{@technologies.join(", ")}.
The description of the task is #{@description}
Take a deep breath and think step by step before you start coding.
PROMPT
end
end