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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ee0dcb302392e3e503b2f26a777953956a998244634c5935fc5be3e2316dc28
4
- data.tar.gz: 1a42d5a6c02552ee676f89e338a8f7ff550b1905497cce42d0ba55e54c28038d
3
+ metadata.gz: c6c1eec7b2ccb702d089ea8c9a149598d9849ed65b6cc86bd973eb7b89f9ccc0
4
+ data.tar.gz: df870526831d8585a4dba437e0258626eafc1046e128866e6d32858455b4867a
5
5
  SHA512:
6
- metadata.gz: 1bca191c52aad2d0b2fd0de6dad2a806046e57546e038b9905d19a78e58047c3cd2e44dbc9fed69b88e648e3970290130d4350ec3fb94aa59b28baf8b07fbe46
7
- data.tar.gz: 7e9e8a1752c11ff3a50de51ab20ab7f77c4a85b46c15134e253b42f6522b30be15b4cbb8cb8bb9ed52c96588a36d9c409cfb75cc14f28f686279324f468d1ded
6
+ metadata.gz: a8d55eaae3d54fa3278d10d0690336854c1c3b014f73e4a55816ff23e0e2c6e60cc7c26e2f9cde10351d70a430dbe5df26aaf182f5713953b1e3578eeee8637d
7
+ data.tar.gz: 0f6435e95973154d0afbd97414701b0e3d0b743d2dc375b91e333d1d41e2f2d1cfda48b8343dfb62791bf2d59ccc2d357453cfb4dc31304a9a479dda04ae7a2a
data/CHANGELOG.md CHANGED
@@ -13,3 +13,7 @@
13
13
 
14
14
  - Research mode architecture changed
15
15
  - Stability improvement
16
+
17
+ ## [0.2.1] - 2023-03-21
18
+
19
+ - GPT-4 models supported (experimental)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monadic-chat (0.2.0)
4
+ monadic-chat (0.2.1)
5
5
  http
6
6
  kramdown
7
7
  launchy
@@ -21,13 +21,9 @@ GEM
21
21
  specs:
22
22
  addressable (2.8.1)
23
23
  public_suffix (>= 2.0.2, < 6.0)
24
- ast (2.4.2)
25
- backport (1.2.0)
26
- benchmark (0.2.1)
27
24
  diff-lcs (1.5.0)
28
25
  domain_name (0.5.20190701)
29
26
  unf (>= 0.0.5, < 1.0.0)
30
- e2mmap (0.1.0)
31
27
  ffi (1.15.5)
32
28
  ffi-compiler (1.0.1)
33
29
  ffi (>= 1.0.0)
@@ -40,32 +36,19 @@ GEM
40
36
  http-cookie (1.0.5)
41
37
  domain_name (~> 0.5)
42
38
  http-form_data (2.3.0)
43
- jaro_winkler (1.5.4)
44
- json (2.6.3)
45
39
  kramdown (2.4.0)
46
40
  rexml
47
- kramdown-parser-gfm (1.1.0)
48
- kramdown (~> 2.0)
49
41
  launchy (2.5.2)
50
42
  addressable (~> 2.8)
51
43
  llhttp-ffi (0.4.0)
52
44
  ffi-compiler (~> 1.0)
53
45
  rake (~> 13.0)
54
- nokogiri (1.14.2-x86_64-darwin)
55
- racc (~> 1.4)
56
46
  oj (3.14.2)
57
47
  parallel (1.22.1)
58
- parser (3.2.1.1)
59
- ast (~> 2.4.1)
60
48
  pastel (0.8.0)
61
49
  tty-color (~> 0.5)
62
50
  public_suffix (5.0.1)
63
- racc (1.6.2)
64
- rainbow (3.1.1)
65
51
  rake (13.0.6)
66
- regexp_parser (2.7.0)
67
- reverse_markdown (2.1.1)
68
- nokogiri
69
52
  rexml (3.2.5)
70
53
  rouge (4.1.0)
71
54
  rspec (3.12.0)
@@ -81,41 +64,11 @@ GEM
81
64
  diff-lcs (>= 1.2.0, < 2.0)
82
65
  rspec-support (~> 3.12.0)
83
66
  rspec-support (3.12.0)
84
- rubocop (1.48.0)
85
- json (~> 2.3)
86
- parallel (~> 1.10)
87
- parser (>= 3.2.0.0)
88
- rainbow (>= 2.2.2, < 4.0)
89
- regexp_parser (>= 1.8, < 3.0)
90
- rexml (>= 3.2.5, < 4.0)
91
- rubocop-ast (>= 1.26.0, < 2.0)
92
- ruby-progressbar (~> 1.7)
93
- unicode-display_width (>= 2.4.0, < 3.0)
94
- rubocop-ast (1.27.0)
95
- parser (>= 3.2.1.0)
96
- ruby-progressbar (1.13.0)
97
- solargraph (0.48.0)
98
- backport (~> 1.2)
99
- benchmark
100
- bundler (>= 1.17.2)
101
- diff-lcs (~> 1.4)
102
- e2mmap
103
- jaro_winkler (~> 1.5)
104
- kramdown (~> 2.3)
105
- kramdown-parser-gfm (~> 1.1)
106
- parser (~> 3.0)
107
- reverse_markdown (>= 1.0.5, < 3)
108
- rubocop (>= 0.52)
109
- thor (~> 1.0)
110
- tilt (~> 2.0)
111
- yard (~> 0.9, >= 0.9.24)
112
67
  strings (0.2.1)
113
68
  strings-ansi (~> 0.2)
114
69
  unicode-display_width (>= 1.5, < 3.0)
115
70
  unicode_utils (~> 1.4)
116
71
  strings-ansi (0.2.0)
117
- thor (1.2.1)
118
- tilt (2.1.0)
119
72
  tty-box (0.7.0)
120
73
  pastel (~> 0.8)
121
74
  strings (~> 0.2.0)
@@ -147,12 +100,10 @@ GEM
147
100
  unf_ext (0.0.8.2)
148
101
  unicode-display_width (2.4.2)
149
102
  unicode_utils (1.4.0)
150
- webrick (1.7.0)
151
103
  wisper (2.0.1)
152
- yard (0.9.28)
153
- webrick (~> 1.7.0)
154
104
 
155
105
  PLATFORMS
106
+ ruby
156
107
  x86_64-darwin-22
157
108
 
158
109
  DEPENDENCIES
@@ -160,7 +111,6 @@ DEPENDENCIES
160
111
  monadic-chat!
161
112
  rake
162
113
  rspec
163
- solargraph
164
114
 
165
115
  BUNDLED WITH
166
- 2.4.1
116
+ 2.4.8
data/README.md CHANGED
@@ -3,14 +3,20 @@
3
3
  <p align="center"><b>Highly configurable CLI client app for OpenAI chat/text-completion API</b></p>
4
4
 
5
5
  <p align="center">
6
- <img src="https://user-images.githubusercontent.com/18207/224493072-9720b341-c70d-43b9-b996-ba7e9a7a6806.gif" width="900" />
6
+ <kbd><img src="https://user-images.githubusercontent.com/18207/224493072-9720b341-c70d-43b9-b996-ba7e9a7a6806.gif" width="800" /></kbd>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <kbd><img src="https://user-images.githubusercontent.com/18207/225505520-53e6f2c4-84a8-4128-a005-3fe980ec2449.gif" width="800" /></kbd>
7
11
  </p>
8
12
 
9
13
  > **Warning**
10
14
  > This software is ***under active development***. It may be unstable, and the latest version may behave slightly differently than this document. Also, specifications may change in the future.
11
15
 
12
- ** Change Log**
16
+ **Change Log**
13
17
 
18
+ - [March 21, 2023] GPT-4 models supported (experimental)
19
+ - [March 20, 2023] Text and figure in "How the research mode workds" section updated
14
20
  - [March 13, 2023] Text on the architecture of the `research` mode updated in accordance with Version 0.2.0
15
21
 
16
22
  ## Table of Contents
@@ -42,8 +48,8 @@
42
48
  * [Creating New App](#creating-new-app)
43
49
  * [File Structure](#file-structure)
44
50
  * [Reducer Code](#reducer-code)
45
- * [Template for `Normal` Mode](#template-for-normal-mode)
46
- * [Template for `Research` Mode](#template-for-research-mode)
51
+ * [Monadic Chat Template](#monadic-chat-template)
52
+ * [Extra Template for `Research` Mode](#extra-template-for-research-mode)
47
53
  * [What is Monadic about Monadic Chat?](#what-is-monadic-about-monadic-chat)
48
54
  * [Unit, Map, and Join](#unit-map-and-join)
49
55
  * [Discourse Management Object](#discourse-management-object)
@@ -58,11 +64,11 @@
58
64
 
59
65
  ## Introduction
60
66
 
61
- **Monadic Chat** is a command-line client application program that uses OpenAI's Text Completion API and Chat API to enable chat-style conversations with OpenAI's artificial intelligence system in a ChatGPT-like style.
67
+ **Monadic Chat** is a user-friendly command-line client application that utilizes OpenAIs Text Completion API and Chat API to facilitate ChatGPT-style conversations with OpenAIs large language models (LLM) on any terminal application of your choice.
62
68
 
63
- The conversation with the AI can be saved in a JSON file, and the saved JSON file can be loaded later to continue the conversation. The conversation data can also be converted to HTML and displayed in a web browser.
69
+ The conversation history can be saved in a JSON file, which can be loaded later to continue the conversation. Additionally, the conversation data can be converted to HTML and viewed in a web browser for easy accessibility.
64
70
 
65
- Monadic Chat comes with four apps (`Chat`, `Code`, `Novel`, and `Translate`). Each can generate a different kind of text through interactive conversation between the user and OpenAI's large-scale language model. Users can also create new apps.
71
+ Monadic Chat includes four pre-built apps (`Chat`, `Code`, `Novel`, and `Translate`) that are designed to generate different types of discourse through interactive conversation with the LLM. Users also have the option to create their own apps by writing new templates.
66
72
 
67
73
  ## Dependencies
68
74
 
@@ -132,7 +138,7 @@ When you start Monadic Chat with the `monadic-chat` command for the first time,
132
138
 
133
139
  <br />
134
140
 
135
- <kbd><img src="./doc/img/input-acess-token.png" width="700px" style="border: thin solid darkgray;"/></kbd>
141
+ <kbd><img src="./doc/img/input-acess-token.png" width="700px" /></kbd>
136
142
 
137
143
  <br />
138
144
 
@@ -150,7 +156,7 @@ Selecting `readme` will take you to the README on the GitHub repository (the doc
150
156
 
151
157
  <br />
152
158
 
153
- <kbd><img src="./doc/img/select-app-menu.png" width="700px" style="border: thin solid darkgray;"/></kbd>
159
+ <kbd><img src="./doc/img/select-app-menu.png" width="700px" /></kbd>
154
160
 
155
161
  <br />
156
162
 
@@ -170,7 +176,7 @@ You can call up the function menu anytime. To invoke the function menu, type `he
170
176
 
171
177
  <br />
172
178
 
173
- <kbd><img src="./doc/img/select-feature-menu.png" width="700px" style="border: thin solid darkgray;"/></kbd>
179
+ <kbd><img src="./doc/img/select-feature-menu.png" width="700px" /></kbd>
174
180
 
175
181
  <br />
176
182
 
@@ -335,15 +341,6 @@ The following is a schematic of the process flow in the `research` mode.
335
341
 
336
342
  <br />
337
343
 
338
- Terms in bold in it may require more explanation.
339
-
340
- - **Input** is a string entered by the user on the command line. The input is filled in the `{{NEW PROMPT}}` placeholder in the template and is sent to the API.
341
- - The **template** contains conversation data in JSON format and instructions on how the text-completion API should update this data. More details are given in the [Creating New Apps]("#creating-new-apps") section below.
342
- - The term **prompt** can be used in two ways: in one sense, it means text input from the user. In the figure above, however, "prompt" refers to the contents of the template as a whole, which is sent to the API.
343
- - The response to the user’s input is referred to as **output**. Input and output are in the returned JSON object, structured according to the instruction specified in the template.
344
- - The JSON object contains a list of the conversation history, referred to as the **accum** (accumulator) in the figure. Each turn of the conversation increases the messages stored in the accumulator.
345
- - A Monadic Chat app must define a **reducer** to prevent the accumulator from growing excessively.
346
-
347
344
  ### Accumulator
348
345
 
349
346
  `Normal` mode uses OpenAI's chat API, where the following basic structure is used for conversation history management.
@@ -400,7 +397,8 @@ The specifications for Monadic Chat's command-line user interface for this app a
400
397
 
401
398
  > **Note**
402
399
  > The use of square brackets (instead of parentheses) in the notation of syntactic analysis here is to conform to the format of [RSyntaxTree](https://yohasebe.com/rsyntaxtree), a tree-drawing program for linguistic research developed by the author of Monadic Chat.
403
- > <img src="./doc/img/syntree-sample.png" width="300px" />
400
+ >
401
+ > <img src="./doc/img/syntree-sample.png" width="280px" />
404
402
 
405
403
  The sample app we create in this section is stored in the [`sample_app`](https://github.com/yohasebe/monadic-chat/tree/main/sample_app) folder in the repository.
406
404
 
@@ -408,7 +406,7 @@ Below is a sample HTML displaying the conversation (sentence and its syntactic s
408
406
 
409
407
  <br />
410
408
 
411
- <kbd><img src="./doc/img/linguistic-html.png" width="700px" style="border: thin solid darkgray;"/></kbd>
409
+ <kbd><img src="./doc/img/linguistic-html.png" width="700px" /></kbd>
412
410
 
413
411
  <br />
414
412
 
@@ -460,7 +458,7 @@ Template files with a name beginning with `_` are also ignored. If a folder has
460
458
 
461
459
  We do not need to make the reducer do anything special for the current purposes. So, let's copy the code from the default `chat` app and make a minor modification, such as changing the class name and the app name so that it matches the app name. We save it as `apps/linguistic/linguistic.rb`.
462
460
 
463
- ### Template for `Normal` Mode
461
+ ### Monadic Chat Template
464
462
 
465
463
  In `normal` mode, achieving all the necessary functions shown earlier is impossible or very tough, to say the least. All we do here is display the results of syntactic analysis and define a user interface. Create a JSON file `apps/linguistic/linguistic.rb` and save it with the following contents:
466
464
 
@@ -479,9 +477,11 @@ In `normal` mode, achieving all the necessary functions shown earlier is impossi
479
477
 
480
478
  The data structure here is no different from that specified in [OpenAI Chat API](https://platform.openai.com/docs/guides/chat). The `normal` mode of Monadic Chat is just a client application that uses this API to achieve ChatGPT-like functionality on the command line.
481
479
 
482
- ### Template for `Research` Mode
480
+ ### Extra Template for `Research` Mode
481
+
482
+ In the `research` mode, you can obtain metadata at each turn as you progress through an interactive conversation with GPT. Compressing and modifying the conversation history based on the metadata (or any other data) is also possible. However, you must create an extra template besides the `normal` mode JSON template.
483
483
 
484
- The template in `research` mode is a Markdown file consisting of five sections. The role and content of each section are shown in the following figure.
484
+ This extra template for `research` mode is a Markdown file comprising six sections. The role and content of each section are shown in the following figure.
485
485
 
486
486
  <br />
487
487
 
@@ -537,18 +537,11 @@ This is the core of the `research` mode template.
537
537
 
538
538
  Note that the entire `research` mode template is written in Markdown format, so the above JSON object is actually separated from the rest of the template by a code fence, as shown below.
539
539
 
540
- ```json
541
- ```json
542
- {
543
- "prompt": ...
544
- "response": ...
545
- "mode": ...
546
- "tokens": ...
547
- "turns": ...
548
- ...
549
- }
550
- ```
551
- ```
540
+ <br />
541
+
542
+ <kbd><img src="./doc/img/extra-template-json.png" width="900px" /></kbd>
543
+
544
+ <br />
552
545
 
553
546
  The required properties of this JSON object are `prompt`, `response`, `mode`, and `tokens`. Other properties are optional. The `mode` property is used to check the app name when saving the conversation data or loading from an external file. The `tokens` property is used in the reducer mechanism to check the approximate size of the current JSON object. The `turns` property is also used in the reducer mechanism.
554
547
 
data/apps/chat/chat.rb CHANGED
@@ -22,10 +22,10 @@ class Chat < MonadicApp
22
22
  }
23
23
  method = OpenAI.model_to_method(params["model"])
24
24
  case method
25
- when "completions"
25
+ when RESEARCH_MODE
26
26
  tjson = TEMPLATES["normal/chat"]
27
27
  tmarkdown = TEMPLATES["research/chat"]
28
- when "chat/completions"
28
+ when NORMAL_MODE
29
29
  tjson = TEMPLATES["normal/chat"]
30
30
  tmarkdown = nil
31
31
  end
@@ -37,7 +37,7 @@ class Chat < MonadicApp
37
37
  prop_newdata: "response",
38
38
  update_proc: proc do
39
39
  case method
40
- when "completions"
40
+ when RESEARCH_MODE
41
41
  ############################################################
42
42
  # Research mode reduder defined here #
43
43
  # @messages: messages to this point #
@@ -51,7 +51,7 @@ class Chat < MonadicApp
51
51
 
52
52
  @metadata["turns"] = @metadata["turns"].to_i - 1 if conditions.all?
53
53
 
54
- when "chat/completions"
54
+ when NORMAL_MODE
55
55
  ############################################################
56
56
  # Normal mode recuder defined here #
57
57
  # @messages: messages to this point #
data/apps/code/code.rb CHANGED
@@ -22,10 +22,10 @@ class Code < MonadicApp
22
22
  }
23
23
  method = OpenAI.model_to_method(params["model"])
24
24
  case method
25
- when "completions"
25
+ when RESEARCH_MODE
26
26
  tjson = TEMPLATES["normal/code"]
27
27
  tmarkdown = TEMPLATES["research/code"]
28
- when "chat/completions"
28
+ when NORMAL_MODE
29
29
  tjson = TEMPLATES["normal/code"]
30
30
  tmarkdown = nil
31
31
  end
@@ -37,7 +37,7 @@ class Code < MonadicApp
37
37
  prop_newdata: "response",
38
38
  update_proc: proc do
39
39
  case method
40
- when "completions"
40
+ when RESEARCH_MODE
41
41
  ############################################################
42
42
  # Research mode reduder defined here #
43
43
  # @messages: messages to this point #
@@ -51,7 +51,7 @@ class Code < MonadicApp
51
51
 
52
52
  @metadata["turns"] = @metadata["turns"].to_i - 1 if conditions.all?
53
53
 
54
- when "chat/completions"
54
+ when NORMAL_MODE
55
55
  ############################################################
56
56
  # Normal mode recuder defined here #
57
57
  # @messages: messages to this point #
@@ -3,7 +3,7 @@
3
3
  require_relative "../../lib/monadic_app"
4
4
 
5
5
  class Linguistic < MonadicApp
6
- DESC = "Syntatic/Semantic/Pragmatic Analyzer"
6
+ DESC = "Linguistic Analysis App (experimental)"
7
7
  COLOR = "red"
8
8
 
9
9
  attr_accessor :template, :config, :params, :completion
@@ -22,10 +22,10 @@ class Linguistic < MonadicApp
22
22
  }
23
23
  method = OpenAI.model_to_method(params["model"])
24
24
  case method
25
- when "completions"
25
+ when RESEARCH_MODE
26
26
  tjson = TEMPLATES["normal/linguistic"]
27
27
  tmarkdown = TEMPLATES["research/linguistic"]
28
- when "chat/completions"
28
+ when NORMAL_MODE
29
29
  tjson = TEMPLATES["normal/linguistic"]
30
30
  tmarkdown = nil
31
31
  end
@@ -37,7 +37,7 @@ class Linguistic < MonadicApp
37
37
  prop_newdata: "response",
38
38
  update_proc: proc do
39
39
  case method
40
- when "completions"
40
+ when RESEARCH_MODE
41
41
  ############################################################
42
42
  # Research mode reduder defined here #
43
43
  # @messages: messages to this point #
@@ -51,7 +51,7 @@ class Linguistic < MonadicApp
51
51
 
52
52
  @metadata["turns"] = @metadata["turns"].to_i - 1 if conditions.all?
53
53
 
54
- when "chat/completions"
54
+ when NORMAL_MODE
55
55
  ############################################################
56
56
  # Normal mode recuder defined here #
57
57
  # @messages: messages to this point #
data/apps/novel/novel.rb CHANGED
@@ -22,10 +22,10 @@ class Novel < MonadicApp
22
22
  }
23
23
  method = OpenAI.model_to_method(params["model"])
24
24
  case method
25
- when "completions"
25
+ when RESEARCH_MODE
26
26
  tjson = TEMPLATES["normal/novel"]
27
27
  tmarkdown = TEMPLATES["research/novel"]
28
- when "chat/completions"
28
+ when NORMAL_MODE
29
29
  tjson = TEMPLATES["normal/novel"]
30
30
  tmarkdown = nil
31
31
  end
@@ -37,7 +37,7 @@ class Novel < MonadicApp
37
37
  prop_newdata: "response",
38
38
  update_proc: proc do
39
39
  case method
40
- when "completions"
40
+ when RESEARCH_MODE
41
41
  ############################################################
42
42
  # Research mode reduder defined here #
43
43
  # @messages: messages to this point #
@@ -51,7 +51,7 @@ class Novel < MonadicApp
51
51
 
52
52
  @metadata["turns"] = @metadata["turns"].to_i - 1 if conditions.all?
53
53
 
54
- when "chat/completions"
54
+ when NORMAL_MODE
55
55
  ############################################################
56
56
  # Normal mode recuder defined here #
57
57
  # @messages: messages to this point #
@@ -26,10 +26,10 @@ class Translate < MonadicApp
26
26
  }
27
27
  method = OpenAI.model_to_method(params["model"])
28
28
  case method
29
- when "completions"
29
+ when RESEARCH_MODE
30
30
  tjson = TEMPLATES["normal/translate"]
31
31
  tmarkdown = TEMPLATES["research/translate"]
32
- when "chat/completions"
32
+ when NORMAL_MODE
33
33
  tjson = TEMPLATES["normal/translate"]
34
34
  tmarkdown = nil
35
35
  end
@@ -41,7 +41,7 @@ class Translate < MonadicApp
41
41
  prop_newdata: "response",
42
42
  update_proc: proc do
43
43
  case method
44
- when "completions"
44
+ when RESEARCH_MODE
45
45
  ############################################################
46
46
  # Research mode reduder defined here #
47
47
  # @messages: messages to this point #
@@ -55,7 +55,7 @@ class Translate < MonadicApp
55
55
 
56
56
  @metadata["turns"] = @metadata["turns"].to_i - 1 if conditions.all?
57
57
 
58
- when "chat/completions"
58
+ when NORMAL_MODE
59
59
  ############################################################
60
60
  # Normal mode recuder defined here #
61
61
  # @messages: messages to this point #
Binary file