Class: Everyai

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

Constant Summary collapse

DOMAIN =
"https://every-llm.com"
API_GENERATIONS_PATH =
"#{DOMAIN}/api/v1/generations"

Class Method Summary collapse

Class Method Details

.anthropic(prompt, model: "anthropic") ⇒ Object



39
40
41
# File 'lib/everyai.rb', line 39

def anthropic(prompt, model: "anthropic")
  generate(prompt, model: model)
end

.api_keyObject



16
17
18
# File 'lib/everyai.rb', line 16

def api_key
  @api_key
end

.api_key=(key) ⇒ Object



12
13
14
# File 'lib/everyai.rb', line 12

def api_key=(key)
  @api_key = key
end

.chatgpt(prompt, model: "chatgpt") ⇒ Object



31
32
33
# File 'lib/everyai.rb', line 31

def chatgpt(prompt, model: "chatgpt")
  generate(prompt, model: model )
end

.generate(prompt, model: "llama3.1", **model_options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/everyai.rb', line 20

def generate(prompt, model: "llama3.1", **model_options)
  url = URI.parse(API_GENERATIONS_PATH)
  response = Net::HTTP.post_form(url, { "prompt": prompt, "model": model, "token": api_key, "options": model_options.to_json })
  body = JSON.parse(response.body)
  if response.kind_of? Net::HTTPSuccess
    body["results"]
  else
    body["errors"]
  end
end

.llama(prompt, model: "llama3.1", context: nil) ⇒ Object



35
36
37
# File 'lib/everyai.rb', line 35

def llama(prompt, model: "llama3.1", context: nil)
  generate(prompt, model: model, context: context)
end