Class: Boxcars::Gpt4allEng
- Defined in:
- lib/boxcars/engine/gpt4all_eng.rb
Overview
A engine that uses local GPT4All API.
Constant Summary collapse
- DEFAULT_NAME =
the default name of the engine
"Gpt4all engine"
- DEFAULT_DESCRIPTION =
the default description of the engine
"useful for when you need to use local AI to answer questions. " \ "You should ask targeted questions"
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
readonly
Returns the value of attribute batch_size.
-
#model_kwargs ⇒ Object
readonly
Returns the value of attribute model_kwargs.
-
#prompts ⇒ Object
readonly
Returns the value of attribute prompts.
Instance Method Summary collapse
-
#client(prompt:, inputs: {}, **_kwargs) ⇒ Object
Get an answer from the engine.
-
#initialize(name: DEFAULT_NAME, description: DEFAULT_DESCRIPTION, prompts: [], batch_size: 2, **_kwargs) ⇒ Gpt4allEng
constructor
A engine is a container for a single tool to run.
-
#run(question, **kwargs) ⇒ Object
get an answer from the engine for a question.
Methods inherited from Engine
#generate, #generation_info, #get_num_tokens
Constructor Details
#initialize(name: DEFAULT_NAME, description: DEFAULT_DESCRIPTION, prompts: [], batch_size: 2, **_kwargs) ⇒ Gpt4allEng
A engine is a container for a single tool to run.
22 23 24 25 26 |
# File 'lib/boxcars/engine/gpt4all_eng.rb', line 22 def initialize(name: DEFAULT_NAME, description: DEFAULT_DESCRIPTION, prompts: [], batch_size: 2, **_kwargs) @prompts = prompts @batch_size = batch_size super(description: description, name: name) end |
Instance Attribute Details
#batch_size ⇒ Object (readonly)
Returns the value of attribute batch_size.
8 9 10 |
# File 'lib/boxcars/engine/gpt4all_eng.rb', line 8 def batch_size @batch_size end |
#model_kwargs ⇒ Object (readonly)
Returns the value of attribute model_kwargs.
8 9 10 |
# File 'lib/boxcars/engine/gpt4all_eng.rb', line 8 def model_kwargs @model_kwargs end |
#prompts ⇒ Object (readonly)
Returns the value of attribute prompts.
8 9 10 |
# File 'lib/boxcars/engine/gpt4all_eng.rb', line 8 def prompts @prompts end |
Instance Method Details
#client(prompt:, inputs: {}, **_kwargs) ⇒ Object
Get an answer from the engine.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/boxcars/engine/gpt4all_eng.rb', line 33 def client(prompt:, inputs: {}, **_kwargs) gpt4all = Gpt4all::ConversationalAI.new gpt4all.prepare_resources(force_download: false) gpt4all.start_bot input_text = prompt.as_prompt(inputs: inputs)[:prompt] Boxcars.debug("Prompt after formatting:\n#{input_text}", :cyan) if Boxcars.configuration.log_prompts gpt4all.prompt(input_text) rescue StandardError => e Boxcars.error(["Error from gpt4all engine: #{e}", e.backtrace[-5..-1]].flatten.join("\n ")) ensure gpt4all.stop_bot end |
#run(question, **kwargs) ⇒ Object
get an answer from the engine for a question.
49 50 51 52 53 54 |
# File 'lib/boxcars/engine/gpt4all_eng.rb', line 49 def run(question, **kwargs) prompt = Prompt.new(template: question) answer = client(prompt: prompt, **kwargs) Boxcars.debug("Answer: #{answer}", :cyan) answer end |