Class: ActivePrompt::Generators::PromptGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- ActivePrompt::Generators::PromptGenerator
- Defined in:
- lib/generators/active_prompt/prompt_generator.rb
Overview
This generator creates a new prompt in the app/prompts directory
Instance Method Summary collapse
-
#create_prompt_files ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Details
#create_prompt_files ⇒ Object
rubocop:disable Metrics/MethodLength
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/active_prompt/prompt_generator.rb', line 13 def create_prompt_files unless File.exist?("app/prompts/application_prompt.rb") create_file "app/prompts/application_prompt.rb", <<~RUBY # frozen_string_literal: true class ApplicationPrompt < ActivePrompt::Base def run(model: 'gpt-3.5-turbo-0613', json_output: false, temperature: 1.0) # client = OpenAI::Client.new # parameters = { # model: model, # messages: render_messages, # temperature: temperature # } # parameters[:response_format] = { type: 'json_object' } if json_output # client.chat(parameters: parameters) raise NotImplementedError, 'please implement this function using your chosen LLM library' end end RUBY end empty_directory "app/prompts/templates/#{name.underscore}_prompt" template "system.liquid", "app/prompts/templates/#{name.underscore}_prompt/system.liquid" template "user.liquid", "app/prompts/templates/#{name.underscore}_prompt/user.liquid" create_file "app/prompts/#{name.underscore}_prompt.rb", <<~RUBY # frozen_string_literal: true class #{name.camelize}Prompt < ApplicationPrompt # variable :name end RUBY end |