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

Instance Method Summary collapse

Class Method Details

.characterObject



67
68
69
# File 'lib/llamafile.rb', line 67

def self.character
	@@CHAR
end

.does?(output, condition, input) ⇒ Boolean

Returns:

  • (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

.grammarObject



78
79
80
# File 'lib/llamafile.rb', line 78

def self.grammar
	@@GRAM
end

.inspectorObject



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

.templateObject



86
87
88
# File 'lib/llamafile.rb', line 86

def self.template
	@@TMPL
end

Instance Method Details

#llamafileObject



105
106
107
# File 'lib/llamafile.rb', line 105

def llamafile
	Lf
end