Class: Z4ai::C

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

Instance Method Summary collapse

Constructor Details

#initialize(i) ⇒ C

Returns a new instance of C.



21
22
23
24
25
# File 'lib/z4ai.rb', line 21

def initialize i
  @id = i
  @face = HuggingFace::InferenceApi.new(api_token: ENV['HUGGING_FACE_API_TOKEN'])
  @facts = []
end

Instance Method Details

#ask(q) ⇒ Object

query given context.



38
39
40
# File 'lib/z4ai.rb', line 38

def ask q
  @face.question_answering(question: q, context: @facts.join("\n"))
end

#embed(t) ⇒ Object

generate embeddings from given text.



46
47
48
# File 'lib/z4ai.rb', line 46

def embed t
  @face.embedding(input: t)
end

#fact(f) ⇒ Object

add fact.



34
35
36
# File 'lib/z4ai.rb', line 34

def fact f
  @facts << f
end

#generate(c) ⇒ Object

expand given context.



42
43
44
# File 'lib/z4ai.rb', line 42

def generate c
  @face.text_generation(input: c)
end

#idObject



26
27
28
# File 'lib/z4ai.rb', line 26

def id
  @id
end

#reset!Object

reset facts.



30
31
32
# File 'lib/z4ai.rb', line 30

def reset!
  @facts = []
end