Class: RagRuby::Generators::RubyLLM
- Defined in:
- lib/rag_ruby/generators/ruby_llm.rb
Instance Method Summary collapse
- #generate(prompt:, system_prompt: nil, temperature: 0.7) ⇒ Object
-
#initialize(model: "gpt-4o", provider: nil) ⇒ RubyLLM
constructor
A new instance of RubyLLM.
Constructor Details
#initialize(model: "gpt-4o", provider: nil) ⇒ RubyLLM
Returns a new instance of RubyLLM.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rag_ruby/generators/ruby_llm.rb', line 6 def initialize(model: "gpt-4o", provider: nil) begin require "ruby_llm" rescue LoadError raise LoadError, "ruby_llm gem is required. Add `gem 'ruby_llm'` to your Gemfile." end @model = model @provider = provider end |
Instance Method Details
#generate(prompt:, system_prompt: nil, temperature: 0.7) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rag_ruby/generators/ruby_llm.rb', line 17 def generate(prompt:, system_prompt: nil, temperature: 0.7) chat = ::RubyLLM.chat(model: @model) chat.with_temperature(temperature) chat.with_instructions(system_prompt) if system_prompt response = chat.ask(prompt) { text: response.content, tokens_used: { prompt: response.input_tokens, completion: response.output_tokens } } end |