monadic-chat 0.2.0 → 0.2.1

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.
data/lib/monadic_app.rb CHANGED
@@ -34,10 +34,10 @@ class MonadicApp
34
34
  @messages = @messages_initial.dup
35
35
 
36
36
  case @method
37
- when "completions"
37
+ when RESEARCH_MODE
38
38
  @template_initial = File.read(tmarkdown)
39
39
  @template = @template_initial.dup
40
- when "chat/completions"
40
+ when NORMAL_MODE
41
41
  @template_initial = ""
42
42
  @template = ""
43
43
  end
@@ -76,9 +76,9 @@ class MonadicApp
76
76
  if input && confirm_query(input)
77
77
  begin
78
78
  case @method
79
- when "completions"
79
+ when RESEARCH_MODE
80
80
  bind_research_mode(input, num_retry: NUM_RETRY)
81
- when "chat/completions"
81
+ when NORMAL_MODE
82
82
  bind_normal_mode(input, num_retry: NUM_RETRY)
83
83
  end
84
84
  rescue StandardError => e
@@ -18,9 +18,9 @@ class MonadicApp
18
18
 
19
19
  def show_greet
20
20
  current_mode = case @method
21
- when "completions"
21
+ when RESEARCH_MODE
22
22
  PASTEL.red("Research")
23
- when "chat/completions"
23
+ when NORMAL_MODE
24
24
  PASTEL.green("Normal")
25
25
  end
26
26
  greet_md = <<~GREET
@@ -61,13 +61,13 @@ class MonadicApp
61
61
 
62
62
  def objectify
63
63
  case @method
64
- when "completions"
64
+ when RESEARCH_MODE
65
65
  m = /\n\n```json\s*(\{.+\})\s*```\n\n/m.match(@template)
66
66
  json = m[1].gsub(/(?!\\\\\\)\\\\"/) { '\\\"' }
67
67
  res = JSON.parse(json)
68
68
  res["messages"] = @messages
69
69
  res
70
- when "chat/completions"
70
+ when NORMAL_MODE
71
71
  @messages
72
72
  end
73
73
  end
@@ -77,7 +77,7 @@ class MonadicApp
77
77
 
78
78
  @update_proc.call
79
79
  case @method
80
- when "completions"
80
+ when RESEARCH_MODE
81
81
  messages = +""
82
82
  system = +""
83
83
  @messages.each do |mes|
@@ -98,7 +98,7 @@ class MonadicApp
98
98
 
99
99
  params["prompt"] = template
100
100
  @messages << { "role" => "user", "content" => input }
101
- when "chat/completions"
101
+ when NORMAL_MODE
102
102
  @messages << { "role" => "user", "content" => input }
103
103
  @update_proc.call
104
104
  params["messages"] = @messages
@@ -109,12 +109,12 @@ class MonadicApp
109
109
 
110
110
  def update_template(res)
111
111
  case @method
112
- when "completions"
112
+ when RESEARCH_MODE
113
113
  @metadata = res
114
114
  @messages << { "role" => "assistant", "content" => res["response"] }
115
115
  json = res.to_json.strip
116
116
  @template.sub!(/\n\n```json.+```\n\n/m, "\n\n```json\n#{json}\n```\n\n")
117
- when "chat/completions"
117
+ when NORMAL_MODE
118
118
  @messages << { "role" => "assistant", "content" => res }
119
119
  end
120
120
  end
@@ -128,12 +128,12 @@ class MonadicApp
128
128
  begin
129
129
  File.open(filepath, "w") do |f|
130
130
  case @method
131
- when "completions"
131
+ when RESEARCH_MODE
132
132
  m = /\n\n```json\s*(\{.+\})\s*```\n\n/m.match(@template)
133
133
  data = JSON.parse(m[1])
134
134
  data["messages"] = @messages
135
135
  f.write JSON.pretty_generate(data)
136
- when "chat/completions"
136
+ when NORMAL_MODE
137
137
  f.write JSON.pretty_generate({ "messages" => @messages })
138
138
  end
139
139
 
@@ -168,15 +168,14 @@ class MonadicApp
168
168
  json = File.read(filepath)
169
169
  data = JSON.parse(json)
170
170
  case @method
171
- when "completions"
171
+ when RESEARCH_MODE
172
172
  self.class.name.downcase.split("::")[-1]
173
173
 
174
174
  raise unless data["mode"] == self.class.name.downcase.split("::")[-1]
175
175
 
176
176
  @messages = data.delete "messages"
177
177
  @template = @template.sub(/\n\n```json\s*\{.+\}\s*```\n\n/m, "\n\n```json\n#{JSON.pretty_generate(data).strip}\n```\n\n")
178
- when "chat/completions"
179
- pp data
178
+ when NORMAL_MODE
180
179
  raise unless data["messages"] && data["messages"][0]["role"]
181
180
 
182
181
  @messages = data["messages"]
@@ -18,6 +18,10 @@ module OpenAI
18
18
  def self.model_to_method(model)
19
19
  {
20
20
  "text-davinci-003" => "completions",
21
+ "gpt-4" => "completions",
22
+ "gpt-4-0314" => "completions",
23
+ "gpt-4-32K" => "completions",
24
+ "gpt-4-32k-0314" => "completions",
21
25
  "gpt-3.5-turbo" => "chat/completions",
22
26
  "gpt-3.5-turbo-0301" => "chat/completions"
23
27
  }[model]
@@ -21,9 +21,9 @@ class MonadicApp
21
21
  when "model"
22
22
  value = change_model
23
23
  case @method
24
- when "completions"
24
+ when RESEARCH_MODE
25
25
  @template = @template_original.dup
26
- when "chat/completions"
26
+ when NORMAL_MODE
27
27
  @template = JSON.parse @template_original
28
28
  end
29
29
  when "max_tokens"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MonadicChat
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/monadic_chat.rb CHANGED
@@ -25,6 +25,8 @@ module MonadicChat
25
25
  MIN_LENGTH = 5
26
26
  TIMEOUT_SEC = 120
27
27
  TITLE_WIDTH = 72
28
+ NORMAL_MODE = "chat/completions"
29
+ RESEARCH_MODE = "completions"
28
30
 
29
31
  APPS_DIR = File.absolute_path(File.join(__dir__, "..", "apps"))
30
32
  APPS_DIR_LIST = Dir.entries(APPS_DIR)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monadic-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yohasebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-13 00:00:00.000000000 Z
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -275,6 +275,7 @@ files:
275
275
  - doc/img/code-example-time-html.png
276
276
  - doc/img/code-example-time.png
277
277
  - doc/img/example-translation.png
278
+ - doc/img/extra-template-json.png
278
279
  - doc/img/how-research-mode-works.svg
279
280
  - doc/img/input-acess-token.png
280
281
  - doc/img/langacker-2001.svg
@@ -322,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
323
  - !ruby/object:Gem::Version
323
324
  version: '0'
324
325
  requirements: []
325
- rubygems_version: 3.4.1
326
+ rubygems_version: 3.4.8
326
327
  signing_key:
327
328
  specification_version: 4
328
329
  summary: Highly configurable CLI client app for OpenAI chat/text-completion API