monadic-chat 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +172 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +652 -0
  8. data/Rakefile +12 -0
  9. data/apps/chat/chat.json +4 -0
  10. data/apps/chat/chat.md +42 -0
  11. data/apps/chat/chat.rb +79 -0
  12. data/apps/code/code.json +4 -0
  13. data/apps/code/code.md +42 -0
  14. data/apps/code/code.rb +77 -0
  15. data/apps/novel/novel.json +4 -0
  16. data/apps/novel/novel.md +36 -0
  17. data/apps/novel/novel.rb +77 -0
  18. data/apps/translate/translate.json +4 -0
  19. data/apps/translate/translate.md +37 -0
  20. data/apps/translate/translate.rb +81 -0
  21. data/assets/github.css +1036 -0
  22. data/assets/pigments-default.css +69 -0
  23. data/bin/monadic-chat +122 -0
  24. data/doc/img/code-example-time-html.png +0 -0
  25. data/doc/img/code-example-time.png +0 -0
  26. data/doc/img/example-translation.png +0 -0
  27. data/doc/img/how-research-mode-works.svg +1 -0
  28. data/doc/img/input-acess-token.png +0 -0
  29. data/doc/img/langacker-2001.svg +41 -0
  30. data/doc/img/linguistic-html.png +0 -0
  31. data/doc/img/monadic-chat-main-menu.png +0 -0
  32. data/doc/img/monadic-chat.svg +13 -0
  33. data/doc/img/readme-example-beatles-html.png +0 -0
  34. data/doc/img/readme-example-beatles.png +0 -0
  35. data/doc/img/research-mode-template.svg +198 -0
  36. data/doc/img/select-app-menu.png +0 -0
  37. data/doc/img/select-feature-menu.png +0 -0
  38. data/doc/img/state-monad.svg +154 -0
  39. data/doc/img/syntree-sample.png +0 -0
  40. data/lib/monadic_app.rb +115 -0
  41. data/lib/monadic_chat/console.rb +29 -0
  42. data/lib/monadic_chat/formatting.rb +110 -0
  43. data/lib/monadic_chat/helper.rb +72 -0
  44. data/lib/monadic_chat/interaction.rb +41 -0
  45. data/lib/monadic_chat/internals.rb +269 -0
  46. data/lib/monadic_chat/menu.rb +189 -0
  47. data/lib/monadic_chat/open_ai.rb +150 -0
  48. data/lib/monadic_chat/parameters.rb +109 -0
  49. data/lib/monadic_chat/version.rb +5 -0
  50. data/lib/monadic_chat.rb +190 -0
  51. data/monadic_chat.gemspec +54 -0
  52. data/samples/linguistic/linguistic.json +17 -0
  53. data/samples/linguistic/linguistic.md +39 -0
  54. data/samples/linguistic/linguistic.rb +74 -0
  55. metadata +343 -0
@@ -0,0 +1,17 @@
1
+ {"messages": [
2
+ {"role": "system",
3
+ "content": "You are an English syntactic/semantic/pragmatic analyzer. Analyze the new prompt from the user below and execute a syntactic parsing. Give your response in a variation of the penn treebank format, but use brackets [ ] instead of parentheses ( ). Also, give your response in a markdown code span. The sentence must always be parsed if the user's input sentence is enclosed in double quotes. If pasing the sentence is extremely difficult, or the input is not enclosed in double quotes, let the user know."
4
+ },
5
+ {"role": "user",
6
+ "content": "\"We saw a beautiful sunset.\""
7
+ },
8
+ {"role": "assistant",
9
+ "content": "`[S [NP He] [VP [V saw] [NP [det a] [N' [Adj beautiful] [N sunset] ] ] ] ]`"
10
+ },
11
+ {"role": "user",
12
+ "content": "\"We didn't take a picture.\""
13
+ },
14
+ {"role": "assistant",
15
+ "content": "`[S [NP We] [IP [I didn't] [VP [V take] [NP [Det a] [N picture] ] ] ] ] ]`"
16
+ }
17
+ ]}
@@ -0,0 +1,39 @@
1
+ You are an English syntactic/semantic/pragmatic analyzer. Analyze the new prompt from the user below and execute a syntactic parsing. Give your response in a variation of the penn treebank format, but use brackets [ ] instead of parentheses ( ). Also, give your response in a markdown code span. The sentence must always be parsed if the user's input sentence is enclosed in double quotes. Create a response to the following new prompt from the user and set your response to the "response" property of the JSON object shown below. All prompts by "user" in the "messages" property are continuous in content. If pasing the input sentence is extremely difficult, or the input is not enclosed in double quotes, let the user know.
2
+
3
+ NEW PROMPT: {{PROMPT}}
4
+
5
+ ```json
6
+ {
7
+ "prompt": "\"We didn't have a camera.\"",
8
+ "response": "`[S [NP We] [VP [V didn't] [VP [V have] [NP [Det a] [N camera] ] ] ] ] ]`\n\n###\n\n",
9
+ "mode": "linguistic",
10
+ "turns": 3,
11
+ "sentence_type": ["declarative"],
12
+ "sentiment": ["sad"],
13
+ "summary": "The user saw a beautiful sunset, but did not take a picture because the user did not have a camera.",
14
+ "tokens": 351,
15
+ "messages": [{"user": "\"We saw a beautiful sunset.\"", "assistant": "`[S [NP He] [VP [V saw] [NP [det a] [N' [Adj beautiful] [N sunset] ] ] ] ]`\n\n###\n\n"},{"user": "\"We didn't take a picture.\"", "assistant": "`[S [NP We] [IP [I didn't] [VP [V take] [NP [Det a] [N picture] ] ] ] ] ]`\n\n###\n\n"},{"user": "\"We didn't have a camera.\"", "assistant": "`[S [NP We] [IP [I didn't] [VP [V have] [NP [Det a] [N camera] ] ] ] ] ]`\n\n###\n\n"}]
16
+ }
17
+ ```
18
+
19
+ Make sure the following content requirements are all fulfilled:
20
+
21
+ - keep the value of the "mode" property at "linguistic"
22
+ - set the new prompt to the "prompt" property
23
+ - create your response to the new prompt in accordance with the "messages" and set it to "response"
24
+ - insert both the new prompt and the response after all the existing items in the "messages"
25
+ - analyze the new prompt's sentence type and set a sentence type value such as "interrogative", "imperative", "exclamatory", or "declarative" to the "sentence_type" property
26
+ - analyze the new prompt's sentiment and set one or more sentiment types such as "happy", "excited", "troubled", "upset", or "sad" to the "sentiment" property
27
+ - summarize the user's messages so far and update the "summary" property with a text of fewer than 100 words using as many discourse markers such as "because", "therefore", "but", "so" to show the logical connection between the events.
28
+ - update the value of "tokens" with the number of tokens of the resulting JSON object"
29
+
30
+ Make sure the following formal requirements are all fulfilled:
31
+
32
+ - do not use invalid characters in the JSON object
33
+ - escape double quotes and other special characters in the text values in the resulting JSON object
34
+ - increment the value of "turns" by 1 and update the property so that the value of "turns" equals the number of the items in the "messages" of the resulting JSON object
35
+ - check the validity of the generated JSON object and correct any possible parsing problems before returning it
36
+
37
+ Add "\n\n###\n\n" at the end of the "response" value.
38
+
39
+ Wrap the JSON object with "<JSON>\n" and "\n</JSON>".
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../lib/monadic_app"
4
+
5
+ class Linguistic < MonadicApp
6
+ DESC = "Syntatic/Semantic/Pragmatic Analyzer"
7
+ COLOR = "red"
8
+
9
+ attr_accessor :template, :config, :params, :completion
10
+
11
+ def initialize(openai_completion, research_mode: false, stream: true)
12
+ @num_retained_turns = 10
13
+ params = {
14
+ "temperature" => 0.0,
15
+ "top_p" => 1.0,
16
+ "presence_penalty" => 0.0,
17
+ "frequency_penalty" => 0.0,
18
+ "model" => OpenAI.model_name(research_mode: research_mode),
19
+ "max_tokens" => 2000,
20
+ "stream" => stream,
21
+ "stop" => nil
22
+ }
23
+ method = OpenAI.model_to_method(params["model"])
24
+ template = case method
25
+ when "completions"
26
+ TEMPLATES["research/linguistic"]
27
+ when "chat/completions"
28
+ TEMPLATES["normal/linguistic"]
29
+ end
30
+ super(params,
31
+ template,
32
+ {},
33
+ "messages",
34
+ "response",
35
+ proc do |res|
36
+ case method
37
+ when "completions"
38
+ # obj = objectify
39
+ ############################################################
40
+ # Research mode recuder defined here #
41
+ # obj: old Hash object #
42
+ # res: new response Hash object to be modified #
43
+ ############################################################
44
+ conditions = [
45
+ res["messages"].size > 1,
46
+ res["tokens"].to_i > params["max_tokens"].to_i / 2
47
+ ]
48
+ if conditions.all?
49
+ res["messages"].shift(1)
50
+ res["turns"] = res["turns"].to_i - 1
51
+ end
52
+ res
53
+ when "chat/completions"
54
+ # obj = objectify
55
+ ############################################################
56
+ # Normal mode recuder defined here #
57
+ # obj: old Hash object (uncomment a line above before use) #
58
+ # res: new response Hash object to be modified #
59
+ ############################################################
60
+ if res.size > @num_retained_turns * 2 + 1
61
+ res.each_with_index do |ele, i|
62
+ if ele["role"] != "system"
63
+ res.delete_at i
64
+ break
65
+ end
66
+ end
67
+ end
68
+ res
69
+ end
70
+ end
71
+ )
72
+ @completion = openai_completion
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,343 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monadic-chat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - yohasebe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: solargraph
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: http
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: kramdown
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: launchy
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: oj
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: parallel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pastel
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rouge
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: tty-box
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: tty-cursor
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: tty-markdown
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: tty-progressbar
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: tty-prompt
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: tty-screen
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ description: 'Monadic Chat is a command-line client application program that uses
252
+ OpenAI''s Text Completion API and Chat API to enable chat-style conversations with
253
+ OpenAI''s artificial intelligence system in a ChatGPT-like style.
254
+
255
+ '
256
+ email:
257
+ - yohasebe@gmail.com
258
+ executables:
259
+ - monadic-chat
260
+ extensions: []
261
+ extra_rdoc_files: []
262
+ files:
263
+ - ".rspec"
264
+ - CHANGELOG.md
265
+ - Gemfile
266
+ - Gemfile.lock
267
+ - LICENSE.txt
268
+ - README.md
269
+ - Rakefile
270
+ - apps/chat/chat.json
271
+ - apps/chat/chat.md
272
+ - apps/chat/chat.rb
273
+ - apps/code/code.json
274
+ - apps/code/code.md
275
+ - apps/code/code.rb
276
+ - apps/novel/novel.json
277
+ - apps/novel/novel.md
278
+ - apps/novel/novel.rb
279
+ - apps/translate/translate.json
280
+ - apps/translate/translate.md
281
+ - apps/translate/translate.rb
282
+ - assets/github.css
283
+ - assets/pigments-default.css
284
+ - bin/monadic-chat
285
+ - doc/img/code-example-time-html.png
286
+ - doc/img/code-example-time.png
287
+ - doc/img/example-translation.png
288
+ - doc/img/how-research-mode-works.svg
289
+ - doc/img/input-acess-token.png
290
+ - doc/img/langacker-2001.svg
291
+ - doc/img/linguistic-html.png
292
+ - doc/img/monadic-chat-main-menu.png
293
+ - doc/img/monadic-chat.svg
294
+ - doc/img/readme-example-beatles-html.png
295
+ - doc/img/readme-example-beatles.png
296
+ - doc/img/research-mode-template.svg
297
+ - doc/img/select-app-menu.png
298
+ - doc/img/select-feature-menu.png
299
+ - doc/img/state-monad.svg
300
+ - doc/img/syntree-sample.png
301
+ - lib/monadic_app.rb
302
+ - lib/monadic_chat.rb
303
+ - lib/monadic_chat/console.rb
304
+ - lib/monadic_chat/formatting.rb
305
+ - lib/monadic_chat/helper.rb
306
+ - lib/monadic_chat/interaction.rb
307
+ - lib/monadic_chat/internals.rb
308
+ - lib/monadic_chat/menu.rb
309
+ - lib/monadic_chat/open_ai.rb
310
+ - lib/monadic_chat/parameters.rb
311
+ - lib/monadic_chat/version.rb
312
+ - monadic_chat.gemspec
313
+ - samples/linguistic/linguistic.json
314
+ - samples/linguistic/linguistic.md
315
+ - samples/linguistic/linguistic.rb
316
+ homepage: https://github.com/yohasebe/monadic-chat
317
+ licenses:
318
+ - MIT
319
+ metadata:
320
+ allowed_push_host: https://rubygems.org
321
+ homepage_uri: https://github.com/yohasebe/monadic-chat
322
+ source_code_uri: https://github.com/yohasebe/monadic-chat
323
+ changelog_uri: https://github.com/yohasebe/monadic-chat/CHANGELOG.md
324
+ post_install_message:
325
+ rdoc_options: []
326
+ require_paths:
327
+ - lib
328
+ required_ruby_version: !ruby/object:Gem::Requirement
329
+ requirements:
330
+ - - ">="
331
+ - !ruby/object:Gem::Version
332
+ version: 2.6.0
333
+ required_rubygems_version: !ruby/object:Gem::Requirement
334
+ requirements:
335
+ - - ">="
336
+ - !ruby/object:Gem::Version
337
+ version: '0'
338
+ requirements: []
339
+ rubygems_version: 3.4.1
340
+ signing_key:
341
+ specification_version: 4
342
+ summary: Highly configurable CLI client app for OpenAI chat/text-completion API
343
+ test_files: []