Class: ActiveAI::Controller
- Inherits:
-
Object
- Object
- ActiveAI::Controller
- Defined in:
- lib/activeai/controller.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #call(request) ⇒ Object
-
#initialize(provider) ⇒ Controller
constructor
A new instance of Controller.
- #prepare_action(request) ⇒ Object
- #run_action(action_name, params) ⇒ Object
Constructor Details
#initialize(provider) ⇒ Controller
Returns a new instance of Controller.
20 21 22 |
# File 'lib/activeai/controller.rb', line 20 def initialize(provider) @provider = provider end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
18 19 20 |
# File 'lib/activeai/controller.rb', line 18 def params @params end |
Class Method Details
.auto_load_routing ⇒ Object
5 6 7 8 9 |
# File 'lib/activeai/controller.rb', line 5 def self.auto_load_routing routes_path = Rails.root.join('config', 'routes', self.to_s.underscore.gsub('_controller', '.yml')) routes_config = YAML::load(File.read(routes_path)) self.load_routing(routes_config) end |
.load_routing(routes_config) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/activeai/controller.rb', line 11 def self.load_routing(routes_config) @llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-cushman-001', temperature: 0) examples = ActiveAI.route_examples_to_function_call_examples(routes_config['examples']) self.routing_behavior = ActiveAI::Behavior::LLM::WriteFunctionCall.new(@llm, { examples: examples }) end |
Instance Method Details
#call(request) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/activeai/controller.rb', line 45 def call(request) mapped_request = prepare_action(request) if mapped_request return run_action(mapped_request[:action], mapped_request[:params]) else return nil end end |
#prepare_action(request) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/activeai/controller.rb', line 24 def prepare_action(request) # samples to parse: # plugins.slack.send_message({ \"channel\": \"#general\", \"text\": \"Hi\" }) # unmatched() function = self.class.routing_behavior.call(request) *controller_path, action_name = function[:path].split(".") controller_name = controller_path.join("/").presence # TODO verify it's the right controller and the action name exists and it's not a reserved / internal thing if controller_name.present? return { action: action_name, params: function[:params] } else return nil end end |
#run_action(action_name, params) ⇒ Object
55 56 57 58 59 |
# File 'lib/activeai/controller.rb', line 55 def run_action(action_name, params) @params = params response = send(action_name) # handle response somehow, or do we just dump JSON back? end |