func_bot 0.1.1 → 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: 68e7cc778676e7b037cff5572cd69c2f61559763fd57b8e31328f487fa839148
4
- data.tar.gz: cb9ca4334b4c08384216a03988e7b3343809cf7d0ee9e0ba69706b17a3c91e48
3
+ metadata.gz: 3c00ad5a2b3aea12bced2b60da8ffe88910c0413ba5a56163f8f08dee540b3e0
4
+ data.tar.gz: 2c91552073019309fc23ae95046763143f1a7f403bd9ee78493201303fe9a592
5
5
  SHA512:
6
- metadata.gz: b22ff1a5ebedc9261dc022bed342d8272b1bd15ed73c749038c4c2711f7785fa9dae7452fe0e8a40337dc46ae43daa2df7bc7ba7b4af28a8fa3f0844aff9efe3
7
- data.tar.gz: 45ac6d18634f9615dcbd3807726543bab58409a7c6e20d80c8a0ad039a5f9bbcccf1c2e801c6b1070bce3aaf4632d435538aa6313f468e22dfe889efca24c156
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
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,15 @@
3
3
  module FuncBot
4
4
  module Functions
5
5
  class BaseFunction
6
- attr_reader :response
6
+ attr_reader :bot
7
7
 
8
- def initialize(response)
9
- @response = response
8
+ def initialize(bot)
9
+ @bot = bot
10
10
  end
11
11
 
12
12
  def parsed_response
13
13
  JSON.parse(
14
- response.dig("choices", 0, "message", "function_call", "arguments")
14
+ bot.response.dig("choices", 0, "message", "function_call", "arguments")
15
15
  )
16
16
  end
17
17
  end
@@ -17,7 +17,7 @@ module FuncBot
17
17
  private
18
18
 
19
19
  def function_data
20
- constantize_function.new(bot.response).execute
20
+ constantize_function.new(bot).execute
21
21
  end
22
22
 
23
23
  def constantize_function
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FuncBot
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/func_bot.rb CHANGED
@@ -12,12 +12,13 @@ require_relative "func_bot/functions/list"
12
12
 
13
13
  module FuncBot
14
14
  class Bot
15
- attr_accessor :response
15
+ attr_accessor :response, :include_functions
16
16
  attr_reader :client, :history
17
17
 
18
18
  def initialize
19
19
  @history = Bots::History.new
20
20
  @client = Bots::Client.new(self)
21
+ @include_functions = true
21
22
  end
22
23
 
23
24
  def ask(prompt)
@@ -7,6 +7,7 @@ module FuncBot
7
7
  module Functions
8
8
  class WeatherFunction < BaseFunction
9
9
  def execute
10
+ bot.include_functions = false
10
11
  weather_info = {
11
12
  location: parsed_response["location"],
12
13
  temperature: 98,
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lbp