Module: Lf
- Defined in:
- lib/llamafile.rb
Defined Under Namespace
Modules: LLAMA
Constant Summary collapse
- AI =
%[a helpful artificial intelligence who responds accurately and truthfully to User.]
- AND_BOOL =
%[ Respond yes or no.]
- @@CHAR =
AI
- @@GRAM =
{ bool: %[root ::= "yes" | "no"], string: %[root ::= en+ (" " en+)+ "\n"\nen ::= [a-zA-Z] | [.!?]], }
- @@TMPL =
{ bool: %[AI is <%= Lf.inspector %>\nUser: Does "<%= @output %>" <%= @condition %> "<%= @input %>"\nAI: ], string: %[AI is <%= Lf.character %>\nUser: <%= [@input].flatten.join("\n") %>\nAI: ], }
Class Method Summary collapse
- .character ⇒ Object
- .does?(output, condition, input) ⇒ Boolean
- .erb(s) ⇒ Object
- .grammar ⇒ Object
- .inspector ⇒ Object
- .prompt(*input) ⇒ Object
- .template ⇒ Object
Instance Method Summary collapse
Class Method Details
.character ⇒ Object
67 68 69 |
# File 'lib/llamafile.rb', line 67 def self.character @@CHAR end |
.does?(output, condition, input) ⇒ Boolean
94 95 96 97 98 99 |
# File 'lib/llamafile.rb', line 94 def self.does? output, condition, input @input = input @output = output @condition = condition LLAMA.post(n_predict: 4, grammar: @@GRAM[:bool], prompt: Lf.erb(Lf.template[:bool])) == 'yes'; end |
.erb(s) ⇒ Object
90 91 92 |
# File 'lib/llamafile.rb', line 90 def self.erb s ERB.new(s).result(binding) end |
.grammar ⇒ Object
78 79 80 |
# File 'lib/llamafile.rb', line 78 def self.grammar @@GRAM end |
.inspector ⇒ Object
70 71 72 |
# File 'lib/llamafile.rb', line 70 def self.inspector %[#{@@CHAR} #{AND_BOOL}] end |
.prompt(*input) ⇒ Object
100 101 102 103 |
# File 'lib/llamafile.rb', line 100 def self.prompt *input @input = input LLAMA.post(grammar: @@GRAM[:string], prompt: Lf.erb(Lf.template[:string])); end |
.template ⇒ Object
86 87 88 |
# File 'lib/llamafile.rb', line 86 def self.template @@TMPL end |
Instance Method Details
#llamafile ⇒ Object
105 106 107 |
# File 'lib/llamafile.rb', line 105 def llamafile Lf end |