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 +4 -4
- data/README.md +20 -0
- data/lib/func_bot/bots/client.rb +15 -6
- data/lib/func_bot/functions/list.rb +4 -8
- data/lib/func_bot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c00ad5a2b3aea12bced2b60da8ffe88910c0413ba5a56163f8f08dee540b3e0
|
4
|
+
data.tar.gz: 2c91552073019309fc23ae95046763143f1a7f403bd9ee78493201303fe9a592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/func_bot/bots/client.rb
CHANGED
@@ -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
|
7
|
-
if
|
8
|
-
|
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
|
data/lib/func_bot/version.rb
CHANGED