Class: Everyai

Inherits:
Object
  • Object
show all
Defined in:
lib/everyai.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEveryai

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

#clientObject (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

.lsObject



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