ruboty-openai_chat 0.1.1 → 0.2.0

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: f5acda135cb2a4635413d1a40a3946ac5a5b8aeb5649a0598c064e6d0e5b8cf5
4
- data.tar.gz: 0aa38a53b0b2f6b5120b1fe892ba2ba2b26a68fe5e7895d013cc2e01f15fc605
3
+ metadata.gz: 353bed59e624fc927b316d6336c367e23475d0bf534ed126db6b07fcefc497ce
4
+ data.tar.gz: 0d50dd6f60af89192adb12f64b156914a1ce2663ff8b9c9d7238ba18eae1a596
5
5
  SHA512:
6
- metadata.gz: 63acc6128d68c96114394bc3bf0f0e83f24a00bb45a6248979b93bf8609b0c5853a92c83b7ab5fd65878843020353cf3875cf912d11c652738ae30724ecec343
7
- data.tar.gz: 982f819a9a4ee37b33078b56b37b4850983e555025ed787e468fe1a4e8296be8d35248e29a25f15838c05b91b6cb5a5a3d8ea3389c66cf8ab9ddd922108acde9
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/Gemfile CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in ruboty-openai-chat.gemspec
6
6
  gemspec
7
7
 
8
+ gem "bump"
8
9
  gem "rake", "~> 13.0"
9
10
  gem "rspec", "~> 3.0"
10
11
  gem "rubocop", "~> 1.21"
11
- gem "bump"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ruboty::OpenAIChat
2
2
 
3
- [OpenAI](https://openai.com/) responds to given message if any other handler does not matches.
3
+ [OpenAI](https://openai.com/) responds to given message if any other handler does not match.
4
4
 
5
5
  This gem uses conversation with an AI assistant like https://beta.openai.com/examples/default-chat as prompt for OpenAI.
6
6
 
@@ -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
@@ -7,7 +7,7 @@ module Ruboty
7
7
  class OpenAIChat < Base
8
8
  env :OPENAI_ACCESS_TOKEN, "Pass OpenAI ACCESS TOKEN"
9
9
  env :OPENAI_ORGANIZATION_ID, "Pass OpenAI Organization ID"
10
- env :OPENAI_CHAT_PRETEXT, "Pretext of OpenAI prompt"
10
+ env :OPENAI_CHAT_PRETEXT, "Pretext of OpenAI prompt", optional: true
11
11
  env :OPENAI_CHAT_LANGUAGE, "Pass your primary language", optional: true
12
12
  env :OPENAI_CHAT_MEMORIZE_SECONDS, "AI remembers the past dialogs in the specified seconds", optional: true
13
13
 
@@ -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 += [ENV["OPENAI_CHAT_PRETEXT"]&.gsub(/\R/, " ")].compact
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ruboty
4
4
  module OpenAIChat
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -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
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["tomo.asleep@gmail.com"]
10
10
  spec.license = "Apache-2.0"
11
11
 
12
- spec.summary = "OpenAI responds to given message if any other handler does not matches."
12
+ spec.summary = "OpenAI responds to given message if any other handler does not match."
13
13
  spec.homepage = "https://github.com/tomoasleep/ruboty-openai_chat"
14
14
  spec.required_ruby_version = ">= 2.6.0"
15
15
 
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.1.1
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-20 00:00:00.000000000 Z
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
@@ -88,5 +90,5 @@ requirements: []
88
90
  rubygems_version: 3.1.6
89
91
  signing_key:
90
92
  specification_version: 4
91
- summary: OpenAI responds to given message if any other handler does not matches.
93
+ summary: OpenAI responds to given message if any other handler does not match.
92
94
  test_files: []