monadic-chat 0.2.1 → 0.3.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: c6c1eec7b2ccb702d089ea8c9a149598d9849ed65b6cc86bd973eb7b89f9ccc0
4
- data.tar.gz: df870526831d8585a4dba437e0258626eafc1046e128866e6d32858455b4867a
3
+ metadata.gz: 6c5b298beeb897c7fbab5cac0862f0fbd1ff52f25c67c811857b187660af9444
4
+ data.tar.gz: fe9cce3bd397b0e0cfb029d234c08f5596bc0b5293d0171ac51a6d4748299150
5
5
  SHA512:
6
- metadata.gz: a8d55eaae3d54fa3278d10d0690336854c1c3b014f73e4a55816ff23e0e2c6e60cc7c26e2f9cde10351d70a430dbe5df26aaf182f5713953b1e3578eeee8637d
7
- data.tar.gz: 0f6435e95973154d0afbd97414701b0e3d0b743d2dc375b91e333d1d41e2f2d1cfda48b8343dfb62791bf2d59ccc2d357453cfb4dc31304a9a479dda04ae7a2a
6
+ metadata.gz: 92a9880abdf278f37d8d5cd729f4d44776654c41eb7973928d9c5b6adcba4a06b4249308ce74d0913696d67317c029710d95bae9f1392ee60277ea03f590bf3b
7
+ data.tar.gz: 617fc1e61cff05f3d8461e87b1b3916b986fefc9f44b0c647e1adae80326f9176032872557cea521b8524e5e2c0a91a8066ab3bbc8df271627b893ab34b71229
data/CHANGELOG.md CHANGED
@@ -16,4 +16,4 @@
16
16
 
17
17
  ## [0.2.1] - 2023-03-21
18
18
 
19
- - GPT-4 models supported (experimental)
19
+ - GPT-4 models supported (in `normal` mode)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monadic-chat (0.2.1)
4
+ monadic-chat (0.3.0)
5
5
  http
6
6
  kramdown
7
7
  launchy
@@ -15,6 +15,7 @@ PATH
15
15
  tty-progressbar
16
16
  tty-prompt
17
17
  tty-screen
18
+ tty-spinner
18
19
 
19
20
  GEM
20
21
  remote: https://rubygems.org/
@@ -95,6 +96,8 @@ GEM
95
96
  tty-screen (~> 0.8)
96
97
  wisper (~> 2.0)
97
98
  tty-screen (0.8.1)
99
+ tty-spinner (0.9.3)
100
+ tty-cursor (~> 0.7)
98
101
  unf (0.1.4)
99
102
  unf_ext
100
103
  unf_ext (0.0.8.2)
data/README.md CHANGED
@@ -3,72 +3,73 @@
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
- <kbd><img src="https://user-images.githubusercontent.com/18207/224493072-9720b341-c70d-43b9-b996-ba7e9a7a6806.gif" width="800" /></kbd>
6
+ <kbd><img src="https://user-images.githubusercontent.com/18207/224493072-9720b341-c70d-43b9-b996-ba7e9a7a6806.gif" width="100%" /></kbd>
7
7
  </p>
8
8
 
9
9
  <p align="center">
10
- <kbd><img src="https://user-images.githubusercontent.com/18207/225505520-53e6f2c4-84a8-4128-a005-3fe980ec2449.gif" width="800" /></kbd>
10
+ <kbd><img src="https://user-images.githubusercontent.com/18207/225505520-53e6f2c4-84a8-4128-a005-3fe980ec2449.gif" width="100%" /></kbd>
11
11
  </p>
12
12
 
13
- > **Warning**
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.
13
+ > **Warning**
14
+ > This software is **work in progress** and **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.
15
15
 
16
16
  **Change Log**
17
17
 
18
- - [March 21, 2023] GPT-4 models supported (experimental)
18
+ - [March 24, 2023] README has revised to reflect the change to version 0.3.0.
19
+ - [March 21, 2023] GPT-4 models supported (in `normal` mode)
19
20
  - [March 20, 2023] Text and figure in "How the research mode workds" section updated
20
21
  - [March 13, 2023] Text on the architecture of the `research` mode updated in accordance with Version 0.2.0
21
22
 
22
23
  ## Table of Contents
23
24
 
24
- <!-- vim-markdown-toc GFM -->
25
-
26
- * [Introduction](#introduction)
27
- * [Dependencies](#dependencies)
28
- * [Installation](#installation)
29
- * [Using RubyGems](#using-rubygems)
30
- * [Clone the GitHub Repository](#clone-the-github-repository)
31
- * [Usage](#usage)
32
- * [Authentication](#authentication)
33
- * [Select Main Menu Item](#select-main-menu-item)
34
- * [Roles](#roles)
35
- * [System-Wide Functions](#system-wide-functions)
36
- * [Apps](#apps)
37
- * [Chat](#chat)
38
- * [Code](#code)
39
- * [Novel](#novel)
40
- * [Translate](#translate)
41
- * [Modes](#modes)
42
- * [Normal Mode](#normal-mode)
43
- * [Research Mode](#research-mode)
44
- * [What is Research Mode?](#what-is-research-mode)
45
- * [How Research Mode Works](#how-research-mode-works)
46
- * [Accumulator](#accumulator)
47
- * [Reducer](#reducer)
48
- * [Creating New App](#creating-new-app)
49
- * [File Structure](#file-structure)
50
- * [Reducer Code](#reducer-code)
51
- * [Monadic Chat Template](#monadic-chat-template)
52
- * [Extra Template for `Research` Mode](#extra-template-for-research-mode)
53
- * [What is Monadic about Monadic Chat?](#what-is-monadic-about-monadic-chat)
54
- * [Unit, Map, and Join](#unit-map-and-join)
55
- * [Discourse Management Object](#discourse-management-object)
56
- * [Future Plans](#future-plans)
57
- * [Bibliographical Data](#bibliographical-data)
58
- * [Acknowledgments](#acknowledgments)
59
- * [Contributing](#contributing)
60
- * [Author](#author)
61
- * [License](#license)
62
-
63
- <!-- vim-markdown-toc -->
25
+ ## TOC
26
+
27
+ - [Table of Contents](#table-of-contents)
28
+ - [TOC](#toc)
29
+ - [Introduction](#introduction)
30
+ - [Dependencies](#dependencies)
31
+ - [Installation](#installation)
32
+ - [Using RubyGems](#using-rubygems)
33
+ - [Clone the GitHub Repository](#clone-the-github-repository)
34
+ - [Usage](#usage)
35
+ - [Authentication](#authentication)
36
+ - [Select Main Menu Item](#select-main-menu-item)
37
+ - [Roles](#roles)
38
+ - [System-Wide Functions](#system-wide-functions)
39
+ - [Apps](#apps)
40
+ - [Chat](#chat)
41
+ - [Code](#code)
42
+ - [Novel](#novel)
43
+ - [Translate](#translate)
44
+ - [Modes](#modes)
45
+ - [Normal Mode](#normal-mode)
46
+ - [Research Mode](#research-mode)
47
+ - [What is Research Mode?](#what-is-research-mode)
48
+ - [How Research Mode Works](#how-research-mode-works)
49
+ - [Accumulator](#accumulator)
50
+ - [Reducer](#reducer)
51
+ - [Creating New App](#creating-new-app)
52
+ - [File Structure](#file-structure)
53
+ - [Reducer Code](#reducer-code)
54
+ - [Monadic Chat Template](#monadic-chat-template)
55
+ - [Extra Template for `Research` Mode](#extra-template-for-research-mode)
56
+ - [What is Monadic about Monadic Chat?](#what-is-monadic-about-monadic-chat)
57
+ - [Unit, Map, and Join](#unit-map-and-join)
58
+ - [Discourse Management Object](#discourse-management-object)
59
+ - [Future Plans](#future-plans)
60
+ - [Bibliographical Data](#bibliographical-data)
61
+ - [Acknowledgments](#acknowledgments)
62
+ - [Contributing](#contributing)
63
+ - [Author](#author)
64
+ - [License](#license)
64
65
 
65
66
  ## Introduction
66
67
 
67
68
  **Monadic Chat** is a user-friendly command-line client application that utilizes OpenAI’s Text Completion API and Chat API to facilitate ChatGPT-style conversations with OpenAI’s large language models (LLM) on any terminal application of your choice.
68
69
 
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.
70
+ 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 better readability.
70
71
 
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.
72
+ Monadic Chat includes four pre-built apps (`Chat`, `Code`, `Novel`, and `Translate`) that are designed for different types of discourse through interactive conversation with the LLM. Users also have the option to create their own apps by writing new templates.
72
73
 
73
74
  ## Dependencies
74
75
 
@@ -199,7 +200,7 @@ For detailed information on each parameter, please refer to OpenAI's [API Docume
199
200
 
200
201
  In `normal` mode, this function only displays the conversation history between User and GPT. In `research` mode, metadata (e.g., topics, language being used, number of turns) values are presented.
201
202
 
202
- In `research` mode, it may take a while (usually several seconds) after the `data/context` command is executed before the data is displayed. This is because in `research` mode, even after displaying a direct response to user input, there may be a process running in the background that retrieves the context data and reconstructs it.
203
+ Program code in the conversation history will be syntax highlighted (if possible). The same applies to output via the `html` command available from the function menu.
203
204
 
204
205
  **html**
205
206
 
@@ -207,8 +208,6 @@ All the information retrievable by running the `data/context` function can be pr
207
208
 
208
209
  The generated HTML will be saved in the user’s home directory (`$HOME`) with the file `monadic_chat.html`. Once the `html` command is executed, the file contents will continue to be updated until you `reset` or quit the running app. Reload the browser tab or rerun the `html` command to show the latest data. HTML data is written to this file regardless of the app.
209
210
 
210
- In `research` mode, it may take several seconds to several minutes after the `html` command is executed before the acutual HTML is displayed. This is because in `research` mode, even after displaying a direct response to user input, there may be a process running in the background that retrieves and reconstructs the context data, requiring the system to wait for it to finish.
211
-
212
211
  **reset**
213
212
 
214
213
  You can reset all the conversation history (messages by both User and GPT). Note that API parameter settings will be reset to default as well.
@@ -243,10 +242,10 @@ Monadic Chat's `chat` app is the most basic and generic app among others offered
243
242
 
244
243
  <br />
245
244
 
246
- In the `chat` app, OpenAI's large-scale language model acts as a competent assistant that can do anything. It can write computer code, create fiction and poetry texts, and translate texts from one language into another. Of course, it can also engage in casual or academic discussions on specific topics. As with ChatGPT, there can be many variations in the content of the conversation.
245
+ In the `chat` app, OpenAI's large-scale language model acts as a competent assistant that can do anything. It can write computer code, create fiction and poetry texts, and translate texts from one language into another. Of course, it can also engage in casual or academic discussions on specific topics.
247
246
 
248
- - [`normal` mode template for `chat` app in JSON](https://github.com/yohasebe/monadic-chat/blob/main/apps/chat/chat.json)
249
- - [`research` mode template for `chat` app in Markdown](https://github.com/yohasebe/monadic-chat/blob/main/apps/chat/chat.md)
247
+ - [basic template for `chat`](https://github.com/yohasebe/monadic-chat/blob/main/apps/chat/chat.json)
248
+ - [extra template for `chat` in `research` mode](https://github.com/yohasebe/monadic-chat/blob/main/apps/chat/chat.md)
250
249
 
251
250
 
252
251
  ### Code
@@ -261,23 +260,23 @@ Monadic Chat's `code` is designed to be an app that can write computer code for
261
260
 
262
261
  <br />
263
262
 
264
- In the `code` app, OpenAI's GPT behaves as a competent software engineer. The main difference from the `chat` app is that the `temperature` parameter is set to `0.0` so that as less randomness as possible is introduced to the responses. Syntax highlighting is applied (where possible) to the program code in the result message. The same applies to the output via the `html` command available from the functions menu.
263
+ In the `code` app, OpenAI's GPT behaves as a competent software engineer. The main difference from the `chat` app is that the `temperature` parameter is set to `0.0` so that as less randomness as possible is introduced to the responses.
265
264
 
266
- - [`normal` mode template for `code` app in JSON](https://github.com/yohasebe/monadic-chat/blob/main/apps/code/code.json)
267
- - [`research` mode template for `code` app in Markdown](https://github.com/yohasebe/monadic-chat/blob/main/apps/code/code.md)
265
+ - [basic template for `code`](https://github.com/yohasebe/monadic-chat/blob/main/apps/code/code.json)
266
+ - [extra template for `code` in `research` mode](https://github.com/yohasebe/monadic-chat/blob/main/apps/code/code.md)
268
267
 
269
268
  ### Novel
270
269
 
271
270
  Monadic Chat's `novel` is designed to help you develop novel plots; the app instructs OpenAI's GPT model to write text based on a topic, theme, or brief description of an event indicated in the user prompt. Each new response is based on what was generated in previous responses. The interactive nature of the app allows the user to control the plot development rather than having an AI agent create a new novel all at once.
272
271
 
273
- - [`normal` mode template for `novel` app in JSON](https://github.com/yohasebe/monadic-chat/blob/main/apps/novel/novel.json)
274
- - [`research` mode template for `novel` app in Markdown](https://github.com/yohasebe/monadic-chat/blob/main/apps/novel/novel.md)
272
+ - [basic template for `novel`](https://github.com/yohasebe/monadic-chat/blob/main/apps/novel/novel.json)
273
+ - [extra template for `novel` in `research` mode](https://github.com/yohasebe/monadic-chat/blob/main/apps/novel/novel.md)
275
274
 
276
275
  ### Translate
277
276
 
278
277
  Monadic Chat's `translate` is an app that helps translate text written in one language into another. Rather than translating the entire text simultaneously, the app allows users to work sentence by sentence or paragraph by paragraph.
279
278
 
280
- The preferred translation for a given expression is specified in a pair of parentheses ( ) right after the original expression in question in a pair of brackets [ ] in the source text.
279
+ The preferred translation for a given expression can be specified in a pair of parentheses ( ) right after the original expression in the source text.
281
280
 
282
281
  <br />
283
282
 
@@ -287,31 +286,28 @@ The preferred translation for a given expression is specified in a pair of paren
287
286
 
288
287
  Sometimes, however, problematic translations are created. The user can "save" the set of source and target texts and make any necessary corrections. The same unwanted expressions can be prevented or avoided later by providing the corrected translation data to the app.
289
288
 
290
- - [`normal` mode template for `translate` app in JSON](https://github.com/yohasebe/monadic-chat/blob/main/apps/translate/translate.json)
291
- - [`research` mode template for `translate` app in Markdown](https://github.com/yohasebe/monadic-chat/blob/main/apps/translate/translate.md)
289
+ - [basic template for `translate` ](https://github.com/yohasebe/monadic-chat/blob/main/apps/translate/translate.json)
290
+ - [extra template for `translate` in `research` mode](https://github.com/yohasebe/monadic-chat/blob/main/apps/translate/translate.md)
292
291
 
293
292
  ## Modes
294
293
 
295
- Monadic Chat has two modes. The `normal` mode utilizes OpenAI's chat API to achieve ChatGPT-like functionality. It is suitable for using a large language model as a competent companion for various pragmatic purposes. On the other hand, the `research` mode utilizes OpenAI's text-completion API. This mode allows for acquiring **metadata** in the background while receiving the primary response at each conversation turn. It may be especially useful for researchers exploring the possibilities of large-scale language models and their applications.
294
+ Monadic Chat has two modes. The `normal` mode utilizes OpenAI's chat API to achieve ChatGPT-like functionality. It is suitable for using a large language model as a competent companion for various pragmatic purposes. On the other hand, the `research` mode supports OpenAI's both chat API and text-completion (instruction) API. This mode allows for acquiring **metadata** in the background while receiving the primary response at each conversation turn. It may be especially useful for researchers exploring the possibilities of large-scale language models and their applications.
296
295
 
297
296
  ### Normal Mode
298
297
 
299
- The default language model for `normal` mode is `gpt-3.5-turbo`.
298
+ The current default language model for `normal` mode is `gpt-3.5-turbo`.
300
299
 
301
300
  In the default configuration, the dialogue messages are reduced after ten turns by deleting the oldest ones (but not the messages that the `system` role has given as instructions).
302
301
 
303
302
  ### Research Mode
304
303
 
305
- The default language model for `research` mode is `text-davinci-003`.
306
-
307
- Although the text-completion API is not a system optimized for chat-style dialogue, it can be used to realize a dialogue system with a mechanism that keeps track of the conversation history in a monadic structure. By default, when the number of tokens in the response from the GPT (which increases with each iteration because of the conversation history) reaches a specific value, the oldest message is deleted. Such a mechanism also has the advantage of retrieving metadata at each dialogue turn.
304
+ The current default language model for `research` mode is `gpt-3.5-turbo`.
308
305
 
309
- By default, when the number of tokens in the response from the GPT (which increases with each iteration because of the conversation history) reaches a specific value, the oldest message is deleted.
306
+ In `research` mode, the conversation between the user and the large-scale language model is accomplished by a special mechanism that tracks the conversation history in a monadic structure. By default, when the number of tokens in the response from the GPT (which increases with each iteration because of the conversation history) reaches a certain value, the oldest message is deleted.
310
307
 
311
308
  If you wish to specify how the conversation history is handled as the interaction with the GPT model unfolds, you can write a `Proc` object containing Ruby code. Since various metadata are available in this mode, finer-grained control is possible.
312
309
 
313
- > **Warning**
314
- > The `research` mode is not intended for general use but for research purposes. You may not get the expected results depending on the template design, parameter settings, and reducer settings. Adjustments in such cases require technical knowledge of OpenAI's text completion API or Ruby.
310
+ See the next section for more details a bout `research` mode
315
311
 
316
312
  ## What is Research Mode?
317
313
 
@@ -323,11 +319,10 @@ Monadic Chat's `research` mode has the following advantages:
323
319
 
324
320
  There are some drawbacks, however:
325
321
 
326
- - It uses OpenAI's `text-davinci-003` model. The response text from this model is less detailed than in the `normal` mode that uses `gpt-3.5-turbo`.
327
- - After displaying a response message from GPT, contextual information is processed in the background, which can cause lag when displaying conversation history in the command line screen or HTML output.
328
322
  - Templates for `research` mode are larger and more complex, requiring more effort to create and fine-tune.
329
323
  - `Research` mode requires more extensive input/output data and consumes more tokens than `normal` mode.
330
- - The text-completion API used in `research` mode is more expensive than the chat API used in `normal` mode.
324
+ - In `research` mode, responses are returned in JSON with metadata. This may make it somewhat unsuitable casual conversation.
325
+ - In `research` mode, the response is returned in JSON with metadata. This may seem a bit visually complex.
331
326
 
332
327
  For these reasons, `normal` mode is recommended for casual use as an alternative CLI to ChatGPT. Nevertheless, as described below, the research mode makes Monadic Chat definitively different from other GPT client applications.
333
328
 
@@ -355,7 +350,7 @@ The following is a schematic of the process flow in the `research` mode.
355
350
 
356
351
  The accumulator in `research` mode also looks like this.
357
352
 
358
- The conversation history is kept entirely in memory until the running app is terminated or reset. The part of the conversation history sent through the API along with new input sentences is referred to here as the accumulator.
353
+ The conversation history is kept entirely in memory until the reducer mechanism modifies it (or the running app is terminated or reset by the user).
359
354
 
360
355
  ### Reducer
361
356
 
@@ -364,14 +359,14 @@ The reducer mechanism must be implemented in Ruby code for each application. In
364
359
  **Example 1**
365
360
 
366
361
  - Retrieve the current conversation topic as metadata at each turn and delete old exchanges if the conversation topic has changed.
367
- - The metadata about the conversation topic is retained in list form even if old messages are deleted.
362
+ - The metadata about the conversation topic can be retained in list form even if old messages are deleted.
368
363
 
369
364
  **Example 2**
370
365
 
371
366
  - After a certain number of turns, the reducer writes the history of the conversation up to that point to an external file and deletes it from the accumulator.
372
367
  - A summary of the deleted content is returned to the accumulator as an annotation message by the `system`, and the conversation continues with that summary information as context.
373
368
 
374
- The Ruby implementation of the "reducer" mechanism for each default app can be found below:
369
+ A sample Ruby implementation of the "reducer" mechanism for each default app can be found below:
375
370
 
376
371
  - [`apps/chat/chat.rb`](https://github.com/yohasebe/monadic-chat/blob/main/apps/chat/chat.rb)
377
372
  - [`apps/code/code.rb`](https://github.com/yohasebe/monadic-chat/blob/main/apps/code/code.rb)
@@ -391,18 +386,16 @@ As an example, let us create an app named `linguistic`. It will do the following
391
386
 
392
387
  The specifications for Monadic Chat's command-line user interface for this app are as follows.
393
388
 
394
- - The text to be parsed must be enclosed in double quotes to prevent the GPT model from misinterpreting it as some instruction.
389
+ - The syntax structure corresponding to the user input is returned as a response.
395
390
  - Parsed data will be formatted in Penn Treebank format. However, square brackets [ ] are used instead of parentheses ( ).
396
- - The parsed data is returned as Markdown inline code enclosed in backticks (` `).
391
+ - The parsed data is returned as Markdown inline code enclosed in backticks \` \`.
397
392
 
398
393
  > **Note**
399
394
  > 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.
400
395
  >
401
396
  > <img src="./doc/img/syntree-sample.png" width="280px" />
402
397
 
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.
404
-
405
- Below is a sample HTML displaying the conversation (sentence and its syntactic structure notation pairs) and metadata.
398
+ Below is a sample HTML displaying the conversation (paris of an input sentence and its syntactic structure) and metadata.
406
399
 
407
400
  <br />
408
401
 
@@ -449,23 +442,21 @@ apps
449
442
  The purpose of each file is as follows.
450
443
 
451
444
  - `linguistic.rb`: Ruby code to define the "reducer"
452
- - `linguistic.json`: JSON template describing GPT behavior in `normal` and `research` modes
453
- - `linguistic.md`: Markdown template describing GPT behavior in addition to the `json` file above in `research` mode
454
-
455
- Template files with a name beginning with `_` are also ignored. If a folder has a name beginning with `_`, all its contents are ignored.
445
+ - `linguistic.json`: JSON template describing GPT's basic behavior in `normal` and `research` modes
446
+ - `linguistic.md`: Markdown template describing the specifications of the "metadata" to be captured in research mode.
456
447
 
457
448
  ### Reducer Code
458
449
 
459
450
  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`.
460
451
 
461
- ### Monadic Chat Template
452
+ ### Basic Template
462
453
 
463
454
  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:
464
455
 
465
456
  ```json
466
457
  {"messages": [
467
458
  {"role": "system",
468
- "content": "You are a syntactic parser for natural languages. Analyze the given input sentence from the user 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."},
459
+ "content": "You are a syntactic parser for natural languages. Analyze the given input sentence from the user 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."},
469
460
  {"role": "user", "content": "\"We saw a beautiful sunset.\""},
470
461
  {"role": "assistant",
471
462
  "content": "`[S [NP He] [VP [V saw] [NP [det a] [N' [Adj beautiful] [N sunset] ] ] ] ]`"},
@@ -489,17 +480,15 @@ This extra template for `research` mode is a Markdown file comprising six sectio
489
480
 
490
481
  <br />
491
482
 
492
- Below we will look at the `research` mode template for the `linguistic` app, section by section.
483
+ Below we will look at this extra template for `research` mode of the `linguistic` app, section by section.
493
484
 
494
485
  **Main Section**
495
486
 
496
- <div style="highlight highlight-source-gfm"><pre style="white-space : pre-wrap !important;">{{SYSTEM}
497
-
498
- All prompts by "user" in the "messages" property are continuous in 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. Let the user know if parsing the sentence is difficult or the input must be enclosed in double quotes.
487
+ <div style="highlight highlight-source-gfm"><pre style="white-space : pre-wrap !important;">{{SYSTEM}}
499
488
 
500
489
  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>
501
490
 
502
- Some of the text here is the same as the text of the directive message by `system` in the template in `normal` mode; Monadic Chat automatically replaces `{{SYSTEM}}} with the `system` directive text 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.
491
+ 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.
503
492
 
504
493
  **New Prompt**
505
494
 
@@ -516,7 +505,7 @@ PAST MESSAGES:
516
505
  {{MESSAGES}}
517
506
  ```
518
507
 
519
- Monadic Chat replaces `{{MESSAGES}}` with messages from past conversations when sending the template. Note that not all the past messages have to be copied here: the reducer mechanism could select, modify, or even "generate" messages and include them instead.
508
+ Monadic Chat replaces `{{MESSAGES}}` with messages from past conversations when sending the template. Note that not all the past messages always have to be copied here: the reducer mechanism could select, modify, or even "generate" messages and include them instead.
520
509
 
521
510
  **JSON Object**
522
511
 
@@ -533,19 +522,13 @@ Monadic Chat replaces `{{MESSAGES}}` with messages from past conversations when
533
522
  }
534
523
  ```
535
524
 
536
- This is the core of the `research` mode template.
537
-
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
-
540
- <br />
541
-
542
- <kbd><img src="./doc/img/extra-template-json.png" width="900px" /></kbd>
525
+ This is the core of the extra template for `research` mode.
543
526
 
544
- <br />
527
+ 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).
545
528
 
546
529
  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.
547
530
 
548
- 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 (so the data is not pretty printed). Modifying its content does not affect the processes carried out by the app.
531
+ 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.
549
532
 
550
533
  **Content Requirements**
551
534
 
@@ -562,7 +545,7 @@ Make sure the following content requirements are all fulfilled:
562
545
  - increment the value of "turns" by 1
563
546
  ```
564
547
 
565
- Note that all the properties of the JSON object above are mentioned so that GPT can update them accordingly.
548
+ Note that all the properties of the JSON object are mentioned here so that GPT can update them accordingly.
566
549
 
567
550
  **Formal Requirements**
568
551
 
@@ -573,27 +556,22 @@ Make sure the following formal requirements are all fulfilled:
573
556
  - escape double quotes and other special characters in the text values in the resulting JSON object
574
557
  - check the validity of the generated JSON object and correct any possible parsing problems before returning it
575
558
 
576
- Add "\n\n###\n\n" at the end of the "response" value.
577
-
578
559
  Wrap the JSON object with "<JSON>\n" and "\n</JSON>".
579
560
  ```
580
561
 
581
562
  This section details the format of the response returned through the API. JSON is essentially text data, and some characters must be escaped appropriately.
582
563
 
583
- Due to their importance, two formal requirements are described as independent sentences rather than in list form. It is necessary since the language model available in OpenAI’s text-completion API is subject to some indeterminacy (even when the `temperature` parameter is `0.0`).
584
-
585
- - To ensure that a valid JSON object is retrieved, Monadic Chat requires `< JSON>... </JSON>` tags to enclose the whole JSON data.
586
- - Monadic Chat requires that the primary response from GPT end with the string `\n\n####\n\n`. This is part of the mechanism to detect when the response string has reached the end so that it can be displayed on the terminal as soon as possible.
564
+ To ensure that a valid JSON object is retrieved, Monadic Chat requires `<JSON>...</JSON>` tags to enclose the whole JSON data. Due to its importance, this formal requirement is described as an independent sentence rather than in list form.
587
565
 
588
566
  ## What is Monadic about Monadic Chat?
589
567
 
590
568
  A monad is a type of data structure in functional programming (leaving aside for the moment the notion of the monad in mathematical category theory). An element with a monadic structure can be manipulated in a certain way to change its internal data. However, no matter how much the internal data changes, the external structure of the monadic process remains the same and can be manipulated in the same way as it was at first.
591
569
 
592
- Many such monadic processes surround us, and natural language discourse is one of them. A "chat" between a human user and an AI agent can be thought of as a form of natural language discourse, which is monadic in nature. If so, an application that provides an interactive interface to a large-scale language model, such as ChatGPT, would most naturally be designed in a "functional" way, considering the monadic nature of natural language discourse.
570
+ Many such monadic processes surround us, and natural language discourse is one of them. A "chat" between a human user and an AI agent can be thought of as a form of natural language discourse. If so, an application that provides an interactive interface to a large-scale language model would most naturally be designed with the monadic nature of natural language discourse in mind.
593
571
 
594
572
  ### Unit, Map, and Join
595
573
 
596
- Many “functional” programming languages, such as Haskell, have monads as a core feature. However, Monadic Chat is developed using the Ruby programming language, which does not. This is because, with Ruby, it will be easier for users to write their apps. Ruby is not classified as a "functional language" per se. Still, Monadic Chat has the following three features required of a monad, and in this sense, it can be considered "monadic."
574
+ Many “functional” programming languages, such as Haskell, have monads as a core feature. However, Monadic Chat is developed using the Ruby programming language, which does not. This is because, with Ruby, it will be easier for users to write their apps. Ruby is not classified as a "functional language" per se. Still, Monadic Chat has the following three features required of a monad, and in this sense, this program can be considered "monadic."
597
575
 
598
576
  - **unit**: a monadic process has a means of taking data and enclosing it in a monadic structure
599
577
  - **map**: a monadic process has a means of performing some operation on the data inside a monadic structure and returning the result in a monadic structure
@@ -605,16 +583,14 @@ In Monadic Chat's `research` mode, the discourse management object described in
605
583
 
606
584
  The interaction between the user and the AI can be interpreted as an operation on the *discourse world* built in the previous conversational exchanges. Monadic Chat updates the discourse world by retrieving the conversation history embedded in the template and performing operations responding to user input (***map***).
607
585
 
608
- Responses from OpenAI's language model APIs (chat API and text-completion API) are also returned in the same JSON format. The main conversational response content is wrapped within this environment. If the whole object were treated as the conversational response to the user input, the discourse management object would involve a nested structure, which could continue inifinitely. Therefore, Monadic Chat extracts only the necessary values from the response object and reassembles the (single-layered) discourse management object using them (***join***).
609
-
586
+ In Monadic Chat, responses from OpenAI's language model APIs (chat API and text completion API) are also returned in the same JSON format. The main response content of the conversation is wrapped within this environment. If the entire JSON object were treated as a conversational response to user input, the discourse management object would become a large nested structure with many layers. Therefore, Monadic Chat extracts only the necessary values from the response object and reconstructs the (single-layer) discourse management object using them (***join***).
610
587
  <br />
611
588
 
612
589
  <img src="./doc/img/state-monad.svg" width="700px" />
613
590
 
614
591
  <br />
615
592
 
616
- The architecture of the `research` mode of Monadic Chat--with its capability of generating and managing metadata properties inside a monadic structure--is parallel to the architecture of natural language discourse in general: They both can be seen as a kind of "state monad" (Hasebe 2021).
617
-
593
+ 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).
618
594
  ## Future Plans
619
595
 
620
596
  - More test cases to verify command line user interaction behavior
@@ -624,7 +600,7 @@ The architecture of the `research` mode of Monadic Chat--with its capability of
624
600
 
625
601
  ## Bibliographical Data
626
602
 
627
- Please use one of the following Bibtex entries when referring to Monadic Chat or the underlying concepts.
603
+ When referring to monadic chat and its underlying concepts, please refer to one of the following entries
628
604
 
629
605
  ```
630
606
  @inproceedings{hasebe_2023j,
data/apps/chat/chat.json CHANGED
@@ -1,4 +1,8 @@
1
1
  {"messages": [
2
2
  {"role": "system",
3
- "content": "You are a friendly but professional consultant who answers various questions, writes computer program code, makes decent suggestions, and gives helpful advice in response to a prompt from the user. If the prompt is not clear enough, ask the user to rephrase it. You are able to empathize with the user; insert an emoji (displayable on the terminal screen) that you deem appropriate for the user's input at the beginning of your response. If the user input is sentimentally neutral, pick up any emoji that matches the topic."}
3
+ "content": "You are a friendly but professional consultant who answers various questions, writes computer program code, makes decent suggestions, and gives helpful advice in response to a prompt from the user. If the prompt is not clear enough, ask the user to rephrase it. You are able to empathize with the user; insert an emoji (displayable on the terminal screen) that you deem appropriate for the user's input at the beginning of your response. If the user input is sentimentally neutral, pick up any emoji that matches the topic."},
4
+ {"role": "user",
5
+ "content": "Can I ask something?"},
6
+ {"role": "assistant",
7
+ "content": "Sure!"}
4
8
  ]}
data/apps/chat/chat.md CHANGED
@@ -13,9 +13,9 @@ JSON:
13
13
  ```json
14
14
  {
15
15
  "prompt": "Can I ask something?",
16
- "response": "Sure!\n\n###\n\n",
16
+ "response": "Sure!",
17
17
  "mode": "chat",
18
- "turns": 0,
18
+ "turns": 1,
19
19
  "language": "English",
20
20
  "topics": [],
21
21
  "tokens": 109
@@ -39,7 +39,6 @@ Make sure the following formal requirements are all fulfilled:
39
39
  - do not use invalid characters in the JSON object
40
40
  - escape double quotes and other special characters in the text values in the resulting JSON object
41
41
  - increment the value of "turns" by 1
42
- - check the validity of the generated JSON object and correct any possible parsing problems before returning it
43
- Add "\n\n###\n\n" at the end of the "response" value.
42
+ - check the validity of the generated JSON object and correct any possible parsing problems before returning it
44
43
 
45
- Wrap the JSON object with "<JSON>\n" and "\n</JSON>".
44
+ Return your response consisting solely of the JSON object wrapped in "<JSON>\n" and "\n</JSON>" tags.
data/apps/chat/chat.rb CHANGED
@@ -8,36 +8,31 @@ class Chat < MonadicApp
8
8
 
9
9
  attr_accessor :template, :config, :params, :completion
10
10
 
11
- def initialize(openai_completion, research_mode: false, stream: true)
11
+ def initialize(openai_completion, research_mode: false, stream: true, params: {})
12
12
  @num_retained_turns = 10
13
13
  params = {
14
14
  "temperature" => 0.3,
15
15
  "top_p" => 1.0,
16
16
  "presence_penalty" => 0.2,
17
17
  "frequency_penalty" => 0.2,
18
- "model" => OpenAI.model_name(research_mode: research_mode),
18
+ "model" => openai_completion.model_name(research_mode: research_mode),
19
19
  "max_tokens" => 2000,
20
20
  "stream" => stream,
21
21
  "stop" => nil
22
- }
23
- method = OpenAI.model_to_method(params["model"])
24
- case method
25
- when RESEARCH_MODE
26
- tjson = TEMPLATES["normal/chat"]
27
- tmarkdown = TEMPLATES["research/chat"]
28
- when NORMAL_MODE
29
- tjson = TEMPLATES["normal/chat"]
30
- tmarkdown = nil
31
- end
32
- super(params: params,
33
- tjson: tjson,
34
- tmarkdown: tmarkdown,
22
+ }.merge(params)
23
+ mode = research_mode ? :research : :normal
24
+ template_json = TEMPLATES["normal/chat"]
25
+ template_md = TEMPLATES["research/chat"]
26
+ super(mode: mode,
27
+ params: params,
28
+ template_json: template_json,
29
+ template_md: template_md,
35
30
  placeholders: {},
36
31
  prop_accumulator: "messages",
37
32
  prop_newdata: "response",
38
33
  update_proc: proc do
39
- case method
40
- when RESEARCH_MODE
34
+ case mode
35
+ when :research
41
36
  ############################################################
42
37
  # Research mode reduder defined here #
43
38
  # @messages: messages to this point #
@@ -51,7 +46,7 @@ class Chat < MonadicApp
51
46
 
52
47
  @metadata["turns"] = @metadata["turns"].to_i - 1 if conditions.all?
53
48
 
54
- when NORMAL_MODE
49
+ when :normal
55
50
  ############################################################
56
51
  # Normal mode recuder defined here #
57
52
  # @messages: messages to this point #
data/apps/code/code.md CHANGED
@@ -12,7 +12,7 @@ JSON:
12
12
  ```json
13
13
  {
14
14
  "prompt": "Can I ask something?",
15
- "response": "Sure!\n\n###\n\n",
15
+ "response": "Sure!",
16
16
  "mode": "chat",
17
17
  "turns": 1,
18
18
  "language": "English",
@@ -40,6 +40,4 @@ Make sure the following formal requirements are all fulfilled:
40
40
  - increment the value of "turns" by 1
41
41
  - check the validity of the generated JSON object and correct any possible parsing problems before returning it
42
42
 
43
- Add "\n\n###\n\n" at the end of the "response" value.
44
-
45
- Wrap the JSON object with "<JSON>\n" and "\n</JSON>".
43
+ Return your response consisting solely of the JSON object wrapped in "<JSON>\n" and "\n</JSON>" tags.