ruboty-openai_chat 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +7 -0
- data/lib/ruboty/handlers/openai_chat.rb +20 -0
- data/lib/ruboty/openai_chat/actions/base.rb +7 -0
- data/lib/ruboty/openai_chat/actions/chat.rb +1 -3
- data/lib/ruboty/openai_chat/actions/remember_profile.rb +23 -0
- data/lib/ruboty/openai_chat/actions/show_profile.rb +24 -0
- data/lib/ruboty/openai_chat/version.rb +1 -1
- data/lib/ruboty/openai_chat.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 353bed59e624fc927b316d6336c367e23475d0bf534ed126db6b07fcefc497ce
|
4
|
+
data.tar.gz: 0d50dd6f60af89192adb12f64b156914a1ce2663ff8b9c9d7238ba18eae1a596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7598b2b3644f09cf7b78358c4a9a8fb78a6aa6e3944a83c0f19037f80cd9ab60a8d416bb34675c94cbd70680bc8e07b8ecc1f9744775211b9a7b156498727cd0
|
7
|
+
data.tar.gz: eabeb98f4d348d33868554a3abe3c473aac32895d7d3e33a236831fa72a7f1b9df0ae78a868b695759e7199bec3f78f6c24287bf8f71b31b7f4831b03f12b8a0
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
|
+
## [0.2.0] - 2022-12-26
|
3
|
+
|
4
|
+
- Add `remember openai profile` command to remember the pretext of AI prompt.
|
5
|
+
- Add `show openai profile` command to show the pretext of AI prompt.
|
6
|
+
- Make `OPENAI_CHAT_PRETEXT` optional.
|
2
7
|
|
3
8
|
## [0.1.0] - 2022-12-17
|
4
9
|
|
data/README.md
CHANGED
@@ -10,6 +10,13 @@ Install the gem and add to the application's Gemfile by executing:
|
|
10
10
|
|
11
11
|
$ bundle add ruboty-openai-chat
|
12
12
|
|
13
|
+
## Commands
|
14
|
+
|
15
|
+
```
|
16
|
+
ruboty /remember chatbot profile (?<body>.+)/ - Remembers given sentence as pretext of AI prompt
|
17
|
+
ruboty /show chatbot profile/ - Show the remembered profile
|
18
|
+
```
|
19
|
+
|
13
20
|
### ENV
|
14
21
|
|
15
22
|
- `OPENAI_ACCESS_TOKEN` - Pass OpenAI ACCESS TOKEN
|
@@ -18,9 +18,29 @@ module Ruboty
|
|
18
18
|
name: "chat"
|
19
19
|
)
|
20
20
|
|
21
|
+
on(
|
22
|
+
/remember chatbot profile (?<body>.+)/,
|
23
|
+
description: "Remembers given sentence as pretext of AI prompt",
|
24
|
+
name: "remember_profile"
|
25
|
+
)
|
26
|
+
|
27
|
+
on(
|
28
|
+
/show chatbot profile/,
|
29
|
+
description: "Show the remembered profile",
|
30
|
+
name: "show_profile"
|
31
|
+
)
|
32
|
+
|
21
33
|
def chat(message)
|
22
34
|
Ruboty::OpenAIChat::Actions::Chat.new(message).call
|
23
35
|
end
|
36
|
+
|
37
|
+
def remember_profile(message)
|
38
|
+
Ruboty::OpenAIChat::Actions::RememberProfile.new(message).call
|
39
|
+
end
|
40
|
+
|
41
|
+
def show_profile(message)
|
42
|
+
Ruboty::OpenAIChat::Actions::ShowProfile.new(message).call
|
43
|
+
end
|
24
44
|
end
|
25
45
|
end
|
26
46
|
end
|
@@ -5,6 +5,9 @@ module Ruboty
|
|
5
5
|
module Actions
|
6
6
|
# @abstract
|
7
7
|
class Base
|
8
|
+
NAMESPACE = "openai-chat-actions-chat"
|
9
|
+
PROFILE_KEY = "profile"
|
10
|
+
|
8
11
|
attr_reader :message
|
9
12
|
|
10
13
|
# @param message [Ruboty::Message]
|
@@ -27,6 +30,10 @@ module Ruboty
|
|
27
30
|
def memory
|
28
31
|
@memory ||= Memory.new(robot)
|
29
32
|
end
|
33
|
+
|
34
|
+
def pretext
|
35
|
+
[ENV["OPENAI_CHAT_PRETEXT"], memory.namespace(NAMESPACE)[PROFILE_KEY]].compact.map { |text| text.strip.gsub(/\R/, " ") }.join(" ")
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
32
39
|
end
|
@@ -6,8 +6,6 @@ module Ruboty
|
|
6
6
|
module OpenAIChat
|
7
7
|
module Actions
|
8
8
|
class Chat < Base
|
9
|
-
NAMESPACE = "openai-chat-actions-chat"
|
10
|
-
|
11
9
|
# @return [String]
|
12
10
|
attr_reader :human_comment, :ai_comment
|
13
11
|
|
@@ -49,7 +47,7 @@ module Ruboty
|
|
49
47
|
|
50
48
|
def build_prompt(human_comment)
|
51
49
|
prefix = [prompt_prefix]
|
52
|
-
prefix += [
|
50
|
+
prefix += [pretext].compact
|
53
51
|
|
54
52
|
dialogs = [example_dialog, *dialogs_from_memory,
|
55
53
|
Dialog.new(human_comment: human_comment, ai_comment: "")].map do |dialog|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module OpenAIChat
|
7
|
+
module Actions
|
8
|
+
class RememberProfile < Base
|
9
|
+
def call
|
10
|
+
new_profile = message[:body].strip
|
11
|
+
memory.namespace(NAMESPACE)[PROFILE_KEY] = new_profile
|
12
|
+
|
13
|
+
message.reply("Remembered the profile.")
|
14
|
+
rescue StandardError => e
|
15
|
+
message.reply(e.message, code: true)
|
16
|
+
raise e if ENV["OPENAI_CHAT_DEBUG"]
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Ruboty
|
6
|
+
module OpenAIChat
|
7
|
+
module Actions
|
8
|
+
class ShowProfile < Base
|
9
|
+
def call
|
10
|
+
if (profile = memory.namespace(NAMESPACE)[PROFILE_KEY])
|
11
|
+
message.reply(profile, code: true)
|
12
|
+
else
|
13
|
+
message.reply("No profile is set.")
|
14
|
+
end
|
15
|
+
rescue StandardError => e
|
16
|
+
message.reply(e.message, code: true)
|
17
|
+
raise e if ENV["OPENAI_CHAT_DEBUG"]
|
18
|
+
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ruboty/openai_chat.rb
CHANGED
@@ -6,6 +6,8 @@ require "ruby/openai"
|
|
6
6
|
require_relative "openai_chat/version"
|
7
7
|
require_relative "openai_chat/actions/base"
|
8
8
|
require_relative "openai_chat/actions/chat"
|
9
|
+
require_relative "openai_chat/actions/remember_profile"
|
10
|
+
require_relative "openai_chat/actions/show_profile"
|
9
11
|
require_relative "openai_chat/dialog"
|
10
12
|
require_relative "openai_chat/memory"
|
11
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-openai_chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomoya Chiba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -59,6 +59,8 @@ files:
|
|
59
59
|
- lib/ruboty/openai_chat.rb
|
60
60
|
- lib/ruboty/openai_chat/actions/base.rb
|
61
61
|
- lib/ruboty/openai_chat/actions/chat.rb
|
62
|
+
- lib/ruboty/openai_chat/actions/remember_profile.rb
|
63
|
+
- lib/ruboty/openai_chat/actions/show_profile.rb
|
62
64
|
- lib/ruboty/openai_chat/dialog.rb
|
63
65
|
- lib/ruboty/openai_chat/memory.rb
|
64
66
|
- lib/ruboty/openai_chat/version.rb
|