activeai 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a327faafb1ed168dfbbfce2c3f5beed3b6090c8ed5c95d24913d988e39227143
4
- data.tar.gz: f3bb5b04eabc7838193f099e649f5dbe48ae3f151537b28469d1b6738848fb00
3
+ metadata.gz: 446cdb7b4d1341e1450486380b0926a68ff594b4361a330f6baa7466ac208c76
4
+ data.tar.gz: 5416c0e23d45fb0c7b7833b3ed8888a7339a5e51fb8bf2f34447283452e3db5b
5
5
  SHA512:
6
- metadata.gz: c3530fdce13cab64414b9b921a49672cd2dae8c170e6f50af5486fe30b33055403a1ef37b6a8c2e3172178ff61ac8c4d26292a3708877111d329cecb0dc59a72
7
- data.tar.gz: 9dc7550488f4dab988b11719a065f0e7fd0c17afa2712c6670b97e8300969fb9d218ac47e2939d295134e5313594f00f45e8838c34c5d9fb178237e3292adcce
6
+ metadata.gz: 0e5f825a3d3b3c2781cc353462ed74087b5c56bd5492e70dad21f3294328dce63d1e198b28e745f98e503a5483b9eb7f0d41c4a552f680200809753a6527b09e
7
+ data.tar.gz: b7fa0ae8250c6bacd2f5083acfbcbcf2fa58f481721e69b9ce060f5a4fac934b8d6b28b41386ce2bafa6f1cef019543e113b04929fcb7bd2e086858068a38596
data/README.md CHANGED
@@ -108,7 +108,7 @@ controller.call("Pay Mom R127 for groceries")
108
108
  It's possible to instantiate an `ActiveAI::Router`, load up the examples from multiple controllers, and then have it handle many types of requests. It does this in a similar way to how the controller uses an LLM to map to action and params, but it concatenates all controller routing examples and strips out the parameter preparation step for efficiency, since the controller handles this.
109
109
 
110
110
  ```ruby
111
- router = ActiveAI::Router.new
111
+ router = ActiveAI::Router.new # TODO you need to add providers now.. should be optional?
112
112
 
113
113
  # load all auto-detected routes:
114
114
  router.auto_load_routing(Rails.root.join('config','routes')) # loads all .yml files as controller examples
@@ -6,26 +6,31 @@ class ActiveAI::Behavior::LLM::WriteFunctionCall < ActiveAI::Behavior::LLM
6
6
  end
7
7
 
8
8
  def base_prompt
9
- @state[:examples].map do |example|
10
- [
11
- "// #{example[:description]}",
12
- example[:code]
13
- ].join("\n")
14
- end.join("\n\n") + "\n\n"
9
+ (@state[:examples].map do |example|
10
+ "/* #{example[:description]} */\n#{example[:code]}"
11
+ end + [""]).join("<|endoftext|>")
15
12
  end
16
13
 
17
14
  def call(comment)
18
- prompt = base_prompt + "\n\n"
19
- prompt += "//#{comment}\n"
20
- complete_result = complete(prompt, stop: "\n")
15
+ prompt = base_prompt
16
+ prompt += "/* #{comment} */\n"
21
17
 
22
- # TODO stop \n works for the router but not for other stuff, later
18
+ complete_result = complete(prompt) # this still breaks sometimes by generating like 50 functions instead of stopping. think i fixed it? forgot an <|endoftext|> at the end
19
+
20
+ # puts prompt
21
+ # puts complete_result
23
22
 
24
23
  completion = complete_result['choices'][0]['text']
24
+ completion = completion.strip.gsub("\n", "\\n") # fixes parsing errors (in JSON??)
25
25
 
26
- matcher = /(.*)\((.*)\)/
26
+ matcher = /(.*?)\((.*)\)/m # should be made ungreedy, but then i dont see when it over-completes because it fails silently
27
27
  matches = matcher.match(completion)
28
28
 
29
+ if matches.nil?
30
+ # binding.pry
31
+ raise "Unmatched router response in #{self.class}"
32
+ end
33
+
29
34
  return {
30
35
  text: completion.strip,
31
36
  path: matches[1],
@@ -9,7 +9,7 @@ class ActiveAI::Controller
9
9
  end
10
10
 
11
11
  def self.load_routing(routes_config)
12
- @llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-davinci-002', temperature: 0.2)
12
+ @llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-cushman-001', temperature: 0)
13
13
 
14
14
  examples = ActiveAI.route_examples_to_function_call_examples(routes_config['examples'])
15
15
  self.routing_behavior = ActiveAI::Behavior::LLM::WriteFunctionCall.new(@llm, { examples: examples })
@@ -17,6 +17,10 @@ class ActiveAI::Controller
17
17
 
18
18
  attr_accessor :params
19
19
 
20
+ def initialize(provider)
21
+ @provider = provider
22
+ end
23
+
20
24
  def prepare_action(request)
21
25
  # samples to parse:
22
26
  # plugins.slack.send_message({ \"channel\": \"#general\", \"text\": \"Hi\" })
@@ -4,7 +4,7 @@ class ActiveAI::Router
4
4
 
5
5
  def initialize
6
6
  @routings = []
7
- @llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-davinci-002', temperature: 0.2)
7
+ @llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-cushman-001', temperature: 0)
8
8
  end
9
9
 
10
10
  def add_controller_routing(routing)
@@ -69,11 +69,18 @@ class ActiveAI::Router
69
69
  end
70
70
  end
71
71
 
72
- def call(request)
73
- if controller = find_controller(request)
74
- controller.new.call(request)
75
- else
76
- return nil
77
- end
78
- end
72
+ # This stopped being necessary, because we find controller and call it elsewhere:
73
+ # def call(request, providers=nil)
74
+ # if controller = find_controller(request)
75
+
76
+ # provider = if providers.respond_to?(:find_by)
77
+ # provider_name = controller.to_s.gsub("Plugins::", "").gsub("Controller","")
78
+ # providers.find_by(name: provider_name)
79
+ # end
80
+
81
+ # controller.new(provider).call(request)
82
+ # else
83
+ # return nil
84
+ # end
85
+ # end
79
86
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAI
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeriko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday