Class: Everyai
- Inherits:
-
Object
- Object
- Everyai
- Defined in:
- lib/everyai.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #generate(prompt, model) ⇒ Object
-
#initialize ⇒ Everyai
constructor
A new instance of Everyai.
Constructor Details
#initialize ⇒ Everyai
Returns a new instance of Everyai.
5 6 7 8 9 10 |
# File 'lib/everyai.rb', line 5 def initialize @client = Ollama.new( credentials: { address: 'http://localhost:11434' }, opiions: { server_sent_events: true } ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/everyai.rb', line 4 def client @client end |
Class Method Details
.generate(prompt, model: "llama3.1") ⇒ Object
25 26 27 28 |
# File 'lib/everyai.rb', line 25 def generate(prompt, model: "llama3.1") @ai ||= new @ai.generate(prompt, model) end |
.ls ⇒ Object
30 31 32 33 34 |
# File 'lib/everyai.rb', line 30 def ls puts "Listing Ollama AI Models" str = `ollama list` puts str.split("\n") end |
Instance Method Details
#generate(prompt, model) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/everyai.rb', line 12 def generate(prompt, model) result = client.generate( { model: model, prompt: prompt } ) result.map { |r| r['response']}.join rescue Ollama::Errors::RequestError puts "This Ollama model is not installed. Type y to install or any key to continue" answer = gets.chomp.downcase `ollama run #{model}` if answer == "y" end |