Class: Z4ai::C
- Inherits:
-
Object
- Object
- Z4ai::C
- Defined in:
- lib/z4ai.rb
Instance Method Summary collapse
-
#ask(q) ⇒ Object
query given context.
-
#embed(t) ⇒ Object
generate embeddings from given text.
-
#fact(f) ⇒ Object
add fact.
-
#generate(c) ⇒ Object
expand given context.
- #id ⇒ Object
-
#initialize(i) ⇒ C
constructor
A new instance of C.
-
#reset! ⇒ Object
reset facts.
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 t @face.(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 |
#id ⇒ Object
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 |