Module: RubyLLM::Text::Rewrite
- Defined in:
- lib/ruby_llm/text/rewrite.rb
Constant Summary collapse
- TONES =
{ casual: "friendly, informal, and conversational", professional: "business-appropriate, formal, and polished", academic: "scholarly, formal, and precise", creative: "engaging, descriptive, and imaginative", brief: "brief, direct, and to-the-point" }.freeze
- STYLES =
{ concise: "Make it shorter and more direct while preserving meaning", detailed: "Expand with more context, examples, and explanation", formal: "Use formal language and professional terminology", informal: "Use informal, friendly language" }.freeze
Class Method Summary collapse
- .build_prompt(text, tone:, style:, instruction:) ⇒ Object
- .call(text, tone: nil, style: nil, instruction: nil, model: nil, **options) ⇒ Object
Class Method Details
.build_prompt(text, tone:, style:, instruction:) ⇒ Object
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 |
# File 'lib/ruby_llm/text/rewrite.rb', line 33 def self.build_prompt(text, tone:, style:, instruction:) transformations = [] if tone tone_description = TONES[tone] || tone.to_s transformations << "Tone: #{tone_description}" end if style style_description = STYLES[style] || style.to_s transformations << "Style: #{style_description}" end if instruction transformations << "Additional instruction: #{instruction}" end transformation_text = transformations.join("\n") <<~PROMPT Rewrite the following text according to these requirements: #{transformation_text} Return only the rewritten text, no explanation or commentary. Text: #{text} PROMPT end |
.call(text, tone: nil, style: nil, instruction: nil, model: nil, **options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_llm/text/rewrite.rb', line 19 def self.call(text, tone: nil, style: nil, instruction: nil, model: nil, **) model ||= RubyLLM::Text.config.model_for(:rewrite) # Validate that at least one transformation is specified if tone.nil? && style.nil? && instruction.nil? raise ArgumentError, "Must specify at least one of: tone, style, or instruction" end prompt = build_prompt(text, tone: tone, style: style, instruction: instruction) Base.call_llm(prompt, model: model, **) end |