func_bot 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2642f560765801d53e14efe88c613738759eb83c5ea65bac70696987eb38783
4
- data.tar.gz: fc5683415acbaed9f68013aad668dbb180d1059b1496c514bcbcd05d5be6044c
3
+ metadata.gz: 3c00ad5a2b3aea12bced2b60da8ffe88910c0413ba5a56163f8f08dee540b3e0
4
+ data.tar.gz: 2c91552073019309fc23ae95046763143f1a7f403bd9ee78493201303fe9a592
5
5
  SHA512:
6
- metadata.gz: a17a9594c4a6ec3cdfbf31db3531afb2074e314fd092851c76d73fa41f221a3e03c35a183ef2a7a86618e15bbd20cd9ff7d642e5efb5dbb9c55e48495eef1165
7
- data.tar.gz: 615b2b10f8c235b67dd7489ea3624a83c3b53a9b0eb57843d816d66dc1672a4c6692cfd615dd7c2238e3c62c5521093dfd32b8186c358fb595b7eedaca201499
6
+ metadata.gz: 3397880c0ff9482c56653bc3f9b552cdd747f946d13e5091dffa5cc004127506e1c49b2a409daf03c1699fd6368f884d42fd07c4f1fa9b0ca546ea17127c5923
7
+ data.tar.gz: d7139064f6ec1dd6546356be3ff93a2a31a0c12307d426e0ffe686db40fca419564d944c30d426cb03d26f093918df411a10d7503f6cdf1f825f63917ad5f880
data/README.md CHANGED
@@ -37,6 +37,26 @@ rails g func_bot:function <function_name>
37
37
  - The `parsed_response` and `response` methods are available to all functions.
38
38
  - `parsed_response` is a hash that contains the response relevant to your function from OpenAI.
39
39
  - `response` is the raw response from OpenAI.
40
+ - Functions also have access to the `bot` attribute which returns the instance of the bot that called the function.
41
+
42
+ - This is useful if you need to access the bot's history or other methods.
43
+ - There might be times when you need to ask gpt a question from within a function, but you don't want to trigger the function again. You can set the `bot.include_functions` attribute to false before asking the question and then set it back to true after.
44
+
45
+ ```ruby
46
+ module FuncBot
47
+ module Functions
48
+ class SomeFunction < BaseFunction
49
+ def execute
50
+ bot.include_functions = false
51
+ response = bot.ask "Some question that you don't want to trigger any functions for"
52
+ bot.include_functions = true
53
+ do_something_with_response(response)
54
+ ....
55
+ end
56
+ end
57
+ end
58
+ end
59
+ ```
40
60
 
41
61
  - Update your new function in the list of functions in `app/lib/func_bot/functions/list.yml`.
42
62
  - This list of functions will be available to the bot with every request.
@@ -11,17 +11,26 @@ module FuncBot
11
11
 
12
12
  def call
13
13
  open_ai.chat(
14
- parameters: {
15
- model: "gpt-3.5-turbo-0613",
16
- messages: bot.history.payload,
17
- temperature: 0.7,
18
- functions: FuncBot::Functions::List.call(bot)
19
- }
14
+ parameters: chat_params
20
15
  )
21
16
  end
22
17
 
23
18
  private
24
19
 
20
+ def chat_params
21
+ params = {
22
+ model: "gpt-3.5-turbo-0613",
23
+ messages: bot.history.payload,
24
+ temperature: 0.7
25
+ }
26
+ params.merge!(function_params) if bot.include_functions
27
+ params
28
+ end
29
+
30
+ def function_params
31
+ {functions: FuncBot::Functions::List.call}
32
+ end
33
+
25
34
  def open_ai
26
35
  @client ||= OpenAI::Client.new
27
36
  end
@@ -3,15 +3,11 @@
3
3
  module FuncBot
4
4
  module Functions
5
5
  class List
6
- def self.call(bot)
7
- if bot.include_functions
8
- if File.exist?(Rails.root.join("app", "lib", "func_bot", "functions", "list.yml"))
9
- YAML.load_file(Rails.root.join("app", "lib", "func_bot", "functions", "list.yml"))["functions"]
10
- else
11
- raise "app/lib/func_bot/functions/list.yml file not found. Please create it by running rails func_bot:install."
12
- end
6
+ def self.call
7
+ if File.exist?(Rails.root.join("app", "lib", "func_bot", "functions", "list.yml"))
8
+ YAML.load_file(Rails.root.join("app", "lib", "func_bot", "functions", "list.yml"))["functions"]
13
9
  else
14
- []
10
+ raise "app/lib/func_bot/functions/list.yml file not found. Please create it by running rails func_bot:install."
15
11
  end
16
12
  end
17
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FuncBot
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: func_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lbp