monadic-chat 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -53
- data/README.md +29 -36
- data/apps/chat/chat.rb +4 -4
- data/apps/code/code.rb +4 -4
- data/apps/linguistic/linguistic.rb +5 -5
- data/apps/novel/novel.rb +4 -4
- data/apps/translate/translate.rb +4 -4
- data/doc/img/extra-template-json.png +0 -0
- data/doc/img/how-research-mode-works.svg +1 -1
- data/doc/img/research-mode-template.svg +1 -198
- data/lib/monadic_app.rb +4 -4
- data/lib/monadic_chat/interaction.rb +2 -2
- data/lib/monadic_chat/internals.rb +6 -6
- data/lib/monadic_chat/menu.rb +4 -5
- data/lib/monadic_chat/open_ai.rb +4 -0
- data/lib/monadic_chat/parameters.rb +2 -2
- data/lib/monadic_chat/version.rb +1 -1
- data/lib/monadic_chat.rb +2 -0
- metadata +4 -3
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
|
37
|
+
when RESEARCH_MODE
|
38
38
|
@template_initial = File.read(tmarkdown)
|
39
39
|
@template = @template_initial.dup
|
40
|
-
when
|
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
|
79
|
+
when RESEARCH_MODE
|
80
80
|
bind_research_mode(input, num_retry: NUM_RETRY)
|
81
|
-
when
|
81
|
+
when NORMAL_MODE
|
82
82
|
bind_normal_mode(input, num_retry: NUM_RETRY)
|
83
83
|
end
|
84
84
|
rescue StandardError => e
|
@@ -61,13 +61,13 @@ class MonadicApp
|
|
61
61
|
|
62
62
|
def objectify
|
63
63
|
case @method
|
64
|
-
when
|
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
|
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
|
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
|
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
|
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
|
117
|
+
when NORMAL_MODE
|
118
118
|
@messages << { "role" => "assistant", "content" => res }
|
119
119
|
end
|
120
120
|
end
|
data/lib/monadic_chat/menu.rb
CHANGED
@@ -128,12 +128,12 @@ class MonadicApp
|
|
128
128
|
begin
|
129
129
|
File.open(filepath, "w") do |f|
|
130
130
|
case @method
|
131
|
-
when
|
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
|
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
|
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
|
179
|
-
pp data
|
178
|
+
when NORMAL_MODE
|
180
179
|
raise unless data["messages"] && data["messages"][0]["role"]
|
181
180
|
|
182
181
|
@messages = data["messages"]
|
data/lib/monadic_chat/open_ai.rb
CHANGED
@@ -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
|
24
|
+
when RESEARCH_MODE
|
25
25
|
@template = @template_original.dup
|
26
|
-
when
|
26
|
+
when NORMAL_MODE
|
27
27
|
@template = JSON.parse @template_original
|
28
28
|
end
|
29
29
|
when "max_tokens"
|
data/lib/monadic_chat/version.rb
CHANGED
data/lib/monadic_chat.rb
CHANGED
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.
|
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-
|
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.
|
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
|