monadic-chat 0.3.4 → 0.3.5

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: f86c68d3d48502db6f77c5081b1ce95478bc499519decf793701fbf0e42d59ac
4
- data.tar.gz: 995f7f6581a2fc35710321405e29f1bdcbe3b3b4e00a5e2d6a543539d21d3a23
3
+ metadata.gz: b894910f03beb26737b61d52bbe8dccde3afe592ca7366f32d7fd23a04ab5f01
4
+ data.tar.gz: bc1c6f2f7f6623081fa163a3b8ad285afe67179f4b140d303e46482fcf15faea
5
5
  SHA512:
6
- metadata.gz: cbbe3b7be1cfbbf2d7144fb1e1bf92602f8a0a1d573541b4e2832c2bc7badfe9a0cd6d35efe390c41bdc6f43d3d65cd765680a1455263215c1b9d24ac5d70aa4
7
- data.tar.gz: 0eed2c83c5b67545942b20a07e7096e4328b71a6acbd6f573a07f2013996dac786cce043d97cab34a6b376c284aaed59a269c45d0988e6bb0e2fe3e9528407c9
6
+ metadata.gz: 8c725e1764e683da1adbe8131ea70b67c66babeba8ab51a09d29ba056728120c61aa874510b7f5a599938770f86d136a063c538165ec6edcc9a5847c47af22d3
7
+ data.tar.gz: 127ad0699ea96e9adf647dfb52564d9ecfc4a32749883bf1e8df6c9b97a125df88b1469270254405bbdecfd63b160c035746990d374972c171a867edcf12174f
data/CHANGELOG.md CHANGED
@@ -24,8 +24,13 @@
24
24
 
25
25
  ## [0.3.3] - 2023-03-26
26
26
 
27
- - Command line options to directly run individual apps
27
+ - Command line options to directly run individual apps
28
28
 
29
- ## [0.3.4] - 2023-03-30
29
+ ## [0.3.4] - 2023-04-02
30
30
 
31
- - `Chat` app now supports web searches and allows users to talk about recent events
31
+ - Architecture refined here and there
32
+
33
+ ## [0.3.5] - 2023-04-05
34
+
35
+ - `Wikipedia` app added (experimental, requires GPT-4)
36
+ - `monadic-chat new/del app_name` command added
data/Gemfile.lock CHANGED
@@ -16,12 +16,11 @@ PATH
16
16
  tty-prompt
17
17
  tty-screen
18
18
  tty-spinner
19
- wikipedia-client
20
19
 
21
20
  GEM
22
21
  remote: https://rubygems.org/
23
22
  specs:
24
- addressable (2.8.1)
23
+ addressable (2.8.2)
25
24
  public_suffix (>= 2.0.2, < 6.0)
26
25
  blingfire (0.1.8)
27
26
  diff-lcs (1.5.0)
@@ -104,12 +103,9 @@ GEM
104
103
  unf_ext (0.0.8.2)
105
104
  unicode-display_width (2.4.2)
106
105
  unicode_utils (1.4.0)
107
- wikipedia-client (1.17.0)
108
- addressable (~> 2.7)
109
106
  wisper (2.0.1)
110
107
 
111
108
  PLATFORMS
112
- ruby
113
109
  x86_64-darwin-22
114
110
 
115
111
  DEPENDENCIES
@@ -119,4 +115,4 @@ DEPENDENCIES
119
115
  rspec
120
116
 
121
117
  BUNDLED WITH
122
- 2.4.9
118
+ 2.4.10
data/README.md CHANGED
@@ -15,7 +15,9 @@
15
15
 
16
16
  **Change Log**
17
17
 
18
- - [March 30, 2023] `Chat` app now supports web searches and allows users to talk about recent events
18
+ - [April 05, 2023] `Wikipedia` app added (experimental, requires GPT-4)
19
+ - [April 05, 2023] `monadic-chat new/del app_name` command
20
+ - [April 02, 2023] Architecture refined here and there
19
21
  - [March 26, 2023] Command line options to directly run individual apps
20
22
  - [March 24, 2023] `Research` mode now supports chat API in addition to text-completion API
21
23
  - [March 21, 2023] GPT-4 models supported (in `normal` mode)
@@ -73,7 +75,7 @@ gem update monadic-chat
73
75
 
74
76
  ### Clone the GitHub Repository
75
77
 
76
- Alternatively, clone the code from the GitHub repository and follow the steps below. At this time, you must take this option to create a new app for Monadic Chat.
78
+ Alternatively, clone the code from the GitHub repository and follow the steps below.
77
79
 
78
80
  1. Clone the repo
79
81
 
@@ -397,39 +399,39 @@ Below is a sample HTML displaying the conversation (paris of an input sentence a
397
399
 
398
400
  ### File Structure
399
401
 
400
- New Monadic Chat apps must be placed inside the `apps` folder. The folders and files for default apps `chat`, `code`, `novel`, and `translate` are also in this folder.
402
+ New Monadic Chat apps must be placed inside the `user_apps` folder. Experimental apps `wikipedia` and `linguistic` are also in this folder. `boilerplates` folder and its contents do not constitute an app; these files are copied when a new app is created.
401
403
 
402
404
  ```text
403
- apps
404
- ├── chat
405
- │ ├── chat.json
406
- │ ├── chat.md
407
- │ └── chat.rb
408
- ├── code
409
- │ ├── code.json
410
- │ ├── code.md
411
- │ └── code.rb
412
- ├── novel
413
- │ ├── novel.json
414
- │ ├── novel.md
415
- │ └── novel.rb
416
- └─── translate
417
- ├── translate.json
418
- ├── translate.md
419
- └── translate.rb
420
- ```
421
-
422
- Notice in the figure above that three files with the same name but different extensions (`.rb`, `.json`, and `.md`) are stored under each of the four default app folders. Similarly, when creating a new app, you create these three types of files under a folder with the same name as the app name.
423
-
424
- ```text
425
- apps
405
+ user_apps
406
+ ├── boilerplates
407
+ │ ├── boilerplate.json
408
+ │ ├── boilerplate.md
409
+ │ └── boilerplate.rb
410
+ ├── wikipedia
411
+ │ ├── wikipedia.json
412
+ │ ├── wikipedia.md
413
+ │ └── wikipedia.rb
426
414
  └─── linguistic
427
415
  ├── linguistic.json
428
416
  ├── linguistic.md
429
417
  └── linguistic.rb
430
418
  ```
431
419
 
432
- The purpose of each file is as follows.
420
+ Notice in the figure above that three files with the same name but different extensions (`.rb`, `.json`, and `.md`) are stored under each of the four default app folders.
421
+
422
+ The following command will create a new folder and the three files within it using this naming convention.
423
+
424
+ ```
425
+ monadic-chat new app_name
426
+ ```
427
+
428
+ If you feel like removing an app that you have created before, run:
429
+
430
+ ```
431
+ monadic-chat del app_name
432
+ ```
433
+
434
+ Let's assume we are creating a new application `linguistic`. In fact, an app with the same name already exists, so this is just for illustrative purposes. Anyway, running `monadic-chat new linguistic` generates the following three files inside `linguistic` folder.
433
435
 
434
436
  - `linguistic.rb`: Ruby code to define the "reducer"
435
437
  - `linguistic.json`: JSON template describing GPT's basic behavior in `normal` and `research` modes
@@ -476,22 +478,21 @@ Below we will look at this extra template for `research` mode of the `linguistic
476
478
 
477
479
  <div style="highlight highlight-source-gfm"><pre style="white-space : pre-wrap !important;">{{SYSTEM}}
478
480
 
479
- Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. The preceding conversation is stored in "PAST MESSAGES". In "PAST MESSAGES", "assistant" refers to you.</pre></div>
481
+ Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. The preceding conversation is stored in "MESSAGES". In "MESSAGES", "assistant" refers to you.</pre></div>
480
482
 
481
483
  Monadic Chat automatically replaces `{{SYSTEM}}} with the message from the `system` role when the template is sent via API. However, the above text also includes a few additional paragpraphs, including the one instructing the response from GPT to be presented as a JSON object.
482
484
 
483
485
  **New Prompt**
484
486
 
485
487
  ```markdown
486
- NEW PROMPT: {{PROMPT}}
488
+ {{PROMPT}}
487
489
  ```
488
490
 
489
491
  Monadic Chat replaces `{{PROMPT}}` with input from the user when sending the template through the API.
490
492
 
491
- **Past Messages**
493
+ **Messages**
492
494
 
493
495
  ```markdown
494
- PAST MESSAGES:
495
496
  {{MESSAGES}}
496
497
  ```
497
498
 
@@ -501,10 +502,8 @@ Monadic Chat replaces `{{MESSAGES}}` with messages from past conversations when
501
502
 
502
503
  ```json
503
504
  {
504
- "prompt": "\"We didn't have a camera.\"",
505
- "response": "`[S [NP We] [VP [V didn't] [VP [V have] [NP [Det a] [N camera] ] ] ] ] ]`\n\n###\n\n",
506
505
  "mode": "linguistic",
507
- "turns": 3,
506
+ "response": "`[S [NP We] [VP [V didn't] [VP [V have] [NP [Det a] [N camera] ] ] ] ] ]`\n\n###\n\n",
508
507
  "sentence_type": ["declarative"],
509
508
  "sentiment": ["sad"],
510
509
  "summary": "The user saw a beautiful sunset, but did not take a picture because the user did not have a camera.",
@@ -515,7 +514,7 @@ This is the core of the extra template for `research` mode.
515
514
 
516
515
  Note that the extra template is written in Markdown format, so the above JSON object is actually separated from the rest of the template as a [fenced code block](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks).
517
516
 
518
- The required properties of this JSON object are `prompt`, `response`, and `mode`. 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 `turns` property is also used in the reducer mechanism.
517
+ The required properties of this JSON object are `mode` and `response`. 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.
519
518
 
520
519
  The JSON object in the `research` mode template is saved in the user’s home directory (`$HOME`) with the file `monadic_chat.json`. The content is overwritten every time the JSON object is updated. Note that this JSON file is created for logging purposes . Modifying its content does not affect the processes carried out by the app.
521
520
 
@@ -526,7 +525,7 @@ Make sure the following content requirements are all fulfilled:
526
525
 
527
526
  - keep the value of the "mode" property at "linguistic"
528
527
  - set the new prompt to the "prompt" property
529
- - create your response to the new prompt based on "PAST MESSAGES" and set it to "response"
528
+ - create your response to the new prompt based on "MESSAGES" and set it to "response"
530
529
  - 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
531
530
  - 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
532
531
  - 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", and "so" to show the logical connection between the events.
@@ -581,6 +580,7 @@ In Monadic Chat, responses from OpenAI's language model APIs (chat API and text
581
580
  Thus, the architecture of the `research` mode of Monad Chat, with its ability to generate and manage metadata properties inside the monadic structure, is parallel to the architecture of natural language discourse in general: both can be seen as a kind of "state monad" (Hasebe 2021).
582
581
  ## Future Plans
583
582
 
583
+ - Refactoring the current implementation code into `unit`, `map`, and `flatten`
584
584
  - More test cases to verify command line user interaction behavior
585
585
  - Improved error handling mechanism to catch incorrect responses from GPT
586
586
  - Develop a DSL to define templates in a more efficient and systematic manner
data/apps/chat/chat.md CHANGED
@@ -1,12 +1,11 @@
1
1
  {{SYSTEM}}
2
2
 
3
- Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object below. The preceding conversation is stored in "PAST MESSAGES".
3
+ Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object below. The preceding conversation is stored in "MESSAGES".
4
4
 
5
- The preceding conversation is stored in "PAST MESSAGES". In "PAST MESSAGES", "assistant" refers to you. Make your response as detailed as possible.
5
+ The preceding conversation is stored in "MESSAGES". In "MESSAGES", "assistant" refers to you. Make your response as detailed as possible.
6
6
 
7
- NEW PROMPT: {{PROMPT}}
7
+ {{PROMPT}}
8
8
 
9
- PAST MESSAGES:
10
9
  {{MESSAGES}}
11
10
 
12
11
  JSON:
@@ -23,23 +22,23 @@ JSON:
23
22
  }
24
23
  ```
25
24
 
26
- Make sure the following content requirements are all fulfilled:
27
-
25
+ Make sure the following content requirements are all fulfilled: ###
28
26
  - keep the value of the "mode" property at "chat"
29
- - create your response to the new prompt based on the PAST MESSAGES and set it to "response"
27
+ - create your response to the new prompt based on the MESSAGES and set it to "response"
30
28
  - if the new prompt is in a language other than the current value of "language", set the name of the new prompt language to "language" and make sure that "response" is in that language
31
29
  - make your response in the same language as the new prompt
32
30
  - analyze the topic of the new prompt and insert it at the end of the value list of the "topics" property
33
31
  - summarize the user's messages so far and update the "summary" property with a text of fewer than 100 words
34
32
  - update the value of the "confidence" property based on the factuality of your response, ranging from 0.00 (not at all confident) to 1.00 (fully confident)
35
33
  - update the value of the "ambiguity" property based on the clarity of the user input, ranging from 0.00 (not at all ambiguous, clearly stated) to 1.00 (fully ambiguous, nonsensical)
36
- - avoid giving a response that is the same or similar to one of the previous responses in PAST MESSAGES
34
+ - avoid giving a response that is the same or similar to one of the previous responses in MESSAGES
37
35
  - program code in the response must be embedded in a code block in the markdown text
36
+ ###
38
37
 
39
- Make sure the following formal requirements are all fulfilled:
40
-
38
+ Make sure the following formal requirements are all fulfilled: ###
41
39
  - do not use invalid characters in the JSON object
42
40
  - escape double quotes and other special characters in the text values in the resulting JSON object
43
41
  - check the validity of the generated JSON object and correct any possible parsing problems before returning it
42
+ ###
44
43
 
45
44
  Return your response consisting solely of the JSON object wrapped in "<JSON>\n" and "\n</JSON>" tags.
data/apps/code/code.md CHANGED
@@ -1,10 +1,9 @@
1
1
  {{SYSTEM}}
2
2
 
3
- Create a response "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. In "PAST MESSAGES", "assistant" refers to you. Make your response as detailed as possible.
3
+ Create a response "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. In "MESSAGES", "assistant" refers to you. Make your response as detailed as possible.
4
4
 
5
- NEW PROMPT: {{PROMPT}}
5
+ {{PROMPT}}
6
6
 
7
- PAST MESSAGES:
8
7
  {{MESSAGES}}
9
8
 
10
9
  JSON:
@@ -19,21 +18,21 @@ JSON:
19
18
  }
20
19
  ```
21
20
 
22
- Make sure the following content requirements are all fulfilled:
23
-
21
+ Make sure the following content requirements are all fulfilled: ###
24
22
  - keep the value of the "mode" property at "chat"
25
- - create your response to the new prompt based on "PAST MESSAGES" and set it to "response"
23
+ - create your response to the new prompt based on "MESSAGES" and set it to "response"
26
24
  - if the prompt is in a language other than the current value of "language", set the name of the new prompt language to "language" and make sure that "response" is in that language
27
25
  - make your response in the same language as the new prompt
28
26
  - analyze the topic of the new prompt and insert it at the end of the value list of the "topics" property
29
27
  - summarize the user's messages so far and update the "summary" property with a text of fewer than 100 words
30
- - avoid giving a response that is the same or similar to one of the previous responses in "PAST MESSAGES"
28
+ - avoid giving a response that is the same or similar to one of the previous responses in "MESSAGES"
31
29
  - program code in the response must be embedded in a code block in the markdown text
30
+ ###
32
31
 
33
- Make sure the following formal requirements are all fulfilled:
34
-
32
+ Make sure the following formal requirements are all fulfilled: ###
35
33
  - do not use invalid characters in the JSON object
36
34
  - escape double quotes and other special characters in the text values in the resulting JSON object
37
35
  - check the validity of the generated JSON object and correct any possible parsing problems before returning it
36
+ ###
38
37
 
39
38
  Return your response consisting solely of the JSON object wrapped in "<JSON>\n" and "\n</JSON>" tags.
data/apps/novel/novel.md CHANGED
@@ -1,10 +1,9 @@
1
1
  {{SYSTEM}}
2
2
 
3
- Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. The preceding conversation is stored in "PAST MESSAGES". In "PAST MESSAGES", "assistant" refers to you.
3
+ Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. The preceding conversation is stored in "MESSAGES". In "MESSAGES", "assistant" refers to you.
4
4
 
5
- NEW PROMPT: {{PROMPT}}
5
+ {{PROMPT}}
6
6
 
7
- PAST MESSAGES:
8
7
  {{MESSAGES}}
9
8
 
10
9
  JSON:
@@ -17,18 +16,18 @@ JSON:
17
16
  }
18
17
  ```
19
18
 
20
- Make sure the following content requirements are all fulfilled:
21
-
19
+ Make sure the following content requirements are all fulfilled: ###
22
20
  - keep the value of the "mode" property at "novel"
23
21
  - create your new paragraph in response to the new prompt and set it to "response"
24
- - do not repeat in your response what is already told in "PAST MESSAGES"
22
+ - do not repeat in your response what is already told in "MESSAGES"
25
23
  - make your response as detailed as possible within the maximum limit of 200 words
26
24
  - summarize the user's messages so far and update the "summary" property with a text of fewer than 100 words
25
+ ###
27
26
 
28
- Make sure the following formal requirements are all fulfilled:
29
-
27
+ Make sure the following formal requirements are all fulfilled: ###
30
28
  - do not use invalid characters in the JSON object
31
29
  - escape double quotes and other special characters in the text values in the resulting JSON object
32
30
  - check the validity of the generated JSON object and correct any possible parsing problems before returning it
31
+ ###
33
32
 
34
33
  Return your response consisting solely of the JSON object wrapped in "<JSON>\n" and "\n</JSON>" tags.
@@ -1,10 +1,9 @@
1
1
  {{SYSTEM}}
2
2
 
3
- Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. The preceding conversation is stored in "PAST MESSAGES". In "PAST MESSAGES", "assistant" refers to you. Make your response as detailed as possible.
3
+ Create a response to "NEW PROMPT" from the user and set your response to the "response" property of the JSON object shown below. The preceding conversation is stored in "MESSAGES". In "MESSAGES", "assistant" refers to you. Make your response as detailed as possible.
4
4
 
5
- NEW PROMPT: {{PROMPT}}
5
+ {{PROMPT}}
6
6
 
7
- PAST MESSAGES:
8
7
  {{MESSAGES}}
9
8
 
10
9
  JSON:
@@ -18,17 +17,17 @@ JSON:
18
17
  }
19
18
  ```
20
19
 
21
- Make sure the following requirements are all fulfilled:
22
-
20
+ Make sure the following requirements are all fulfilled: ###
23
21
  - keep the value of the "mode" property at "translate"
24
22
  - translate the new prompt text to the language specified in the "target_lang" set it to "response" and set the translation to the "response" property
25
23
  - update the "dictionary" property with translation suggested by the user (using parentheses) for specific expressions
26
24
  - add user-suggested translations (translations in parentheses) to the "dictionary" property
25
+ ###
27
26
 
28
- Make sure the following formal requirements are all fulfilled:
29
-
27
+ Make sure the following formal requirements are all fulfilled: ###
30
28
  - do not use invalid characters in the JSON object
31
29
  - escape double quotes and other special characters in the text values in the resulting JSON object
32
30
  - check the validity of the generated JSON object and correct any possible parsing problems before returning it
31
+ ###
33
32
 
34
33
  Return your response consisting solely of the JSON object wrapped in "<JSON>\n" and "\n</JSON>" tags.
data/bin/monadic-chat CHANGED
@@ -130,7 +130,7 @@ when 1
130
130
  when "readme", "-h"
131
131
  MonadicChat.open_readme
132
132
  when "version", "-v"
133
- puts MonadicChat::VERSION
133
+ print MonadicChat::PROMPT_SYSTEM.prefix, MonadicChat::VERSION, "\n"
134
134
  else
135
135
  MonadicChat::APPS.each do |app|
136
136
  next unless app == ARGV[0]
@@ -139,16 +139,30 @@ when 1
139
139
  eval(app.capitalize, binding, __FILE__, __LINE__).new(openai_completion, research_mode: false).run
140
140
  exit
141
141
  end
142
- puts "Unknown command"
142
+ print MonadicChat::PROMPT_SYSTEM.prefix, "Unknown command", "\n"
143
143
  end
144
144
  else
145
- MonadicChat::APPS.each do |app|
146
- next unless app == ARGV[0]
145
+ if ARGV[0] == "new"
146
+ if ARGV[1].to_s != "" && !MonadicChat::APPS.include?(ARGV[1])
147
+ MonadicChat.create_app(ARGV[1])
148
+ else
149
+ print MonadicChat::PROMPT_SYSTEM.prefix, "Invalid app name (must be unique)", "\n"
150
+ end
151
+ elsif ARGV[0] == "delete" || ARGV[0] == "del" || ARGV[0] == "remove"
152
+ if MonadicChat::APPS.include?(ARGV[1])
153
+ MonadicChat.delete_app(ARGV[1])
154
+ else
155
+ print MonadicChat::PROMPT_SYSTEM.prefix, "Invalid app name (must exist)", "\n"
156
+ end
157
+ else
158
+ MonadicChat::APPS.each do |app|
159
+ next unless app == ARGV[0]
147
160
 
148
- openai_completion ||= MonadicChat.authenticate(message: false)
149
- app_obj = eval(app.capitalize, binding, __FILE__, __LINE__).new(openai_completion, research_mode: false, params: { "model" => "gpt-4" })
150
- app_obj.bind(ARGV[1..].join(" "), num_retry: 2)
151
- exit
161
+ openai_completion ||= MonadicChat.authenticate(message: false)
162
+ app_obj = eval(app.capitalize, binding, __FILE__, __LINE__).new(openai_completion, research_mode: false, params: { "model" => "gpt-4" })
163
+ app_obj.bind(ARGV[1..].join(" "), num_retrials: 2)
164
+ exit
165
+ end
166
+ print MonadicChat::PROMPT_SYSTEM.prefix, "Unknown command", "\n"
152
167
  end
153
- puts "Unknown command"
154
168
  end