ctod 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +65 -111
  2. package/dist/index.js +1 -1
  3. package/examples/chat-demo.ts +70 -0
  4. package/examples/{applications/cosplay.ts → plugin-demo.ts} +20 -16
  5. package/lib/broker/chat.ts +277 -0
  6. package/lib/core/plugin.ts +9 -102
  7. package/lib/index.ts +13 -35
  8. package/lib/plugins/index.ts +6 -1
  9. package/lib/plugins/limiter.ts +4 -56
  10. package/lib/plugins/print-log.ts +31 -111
  11. package/lib/plugins/retry.ts +22 -58
  12. package/lib/plugins/role.ts +26 -62
  13. package/lib/service/{chatgpt35.ts → openai/chat.ts} +16 -31
  14. package/lib/service/{chatgpt3.ts → openai/completion.ts} +12 -27
  15. package/lib/service/{images-generations.ts → openai/images-generation.ts} +7 -22
  16. package/lib/service/openai/index.ts +43 -0
  17. package/package.json +2 -2
  18. package/types/lib/broker/{35.d.ts → chat.d.ts} +42 -17
  19. package/types/lib/core/plugin.d.ts +9 -73
  20. package/types/lib/index.d.ts +12 -35
  21. package/types/lib/plugins/index.d.ts +17 -30
  22. package/types/lib/plugins/limiter.d.ts +4 -9
  23. package/types/lib/plugins/print-log.d.ts +4 -22
  24. package/types/lib/plugins/retry.d.ts +5 -19
  25. package/types/lib/plugins/role.d.ts +4 -17
  26. package/types/lib/service/{chatgpt35.d.ts → openai/chat.d.ts} +13 -23
  27. package/types/lib/service/{chatgpt3.d.ts → openai/completion.d.ts} +9 -19
  28. package/types/lib/service/{images-generations.d.ts → openai/images-generation.d.ts} +4 -14
  29. package/types/lib/service/openai/index.d.ts +22 -0
  30. package/README-TW.md +0 -245
  31. package/TODO +0 -6
  32. package/examples/applications/bbc-news-reader.ts +0 -224
  33. package/examples/applications/story-generations.ts +0 -131
  34. package/examples/applications/talk-generations.ts +0 -257
  35. package/examples/chatgpt3.5-broker.ts +0 -79
  36. package/examples/chatgpt3.5.ts +0 -42
  37. package/examples/utils/index.ts +0 -56
  38. package/lib/broker/3.ts +0 -160
  39. package/lib/broker/35.ts +0 -207
  40. package/lib/broker/4.ts +0 -207
  41. package/lib/broker/index.ts +0 -86
  42. package/lib/service/chatgpt4.ts +0 -137
  43. package/types/lib/broker/3.d.ts +0 -71
  44. package/types/lib/broker/4.d.ts +0 -86
  45. package/types/lib/broker/index.d.ts +0 -31
  46. package/types/lib/service/chatgpt4.d.ts +0 -89
package/README.md CHANGED
@@ -15,21 +15,19 @@
15
15
 
16
16
  <br>
17
17
 
18
- [繁體中文說明](./README-TW.md)
19
-
20
18
  ## Online Playground
21
19
 
22
- [Chat Of Requirement(織語)](https://cor.metalsheep.com/) is a display tool built for CtoD. You can use this tool to construct and adjust your templates.
20
+ [Chat Of Requirement(織語)](https://cor.metalsheep.com/) 是為了 CtoD 建構的展示工具,你可以在這個工具中建構你與調適你的模板。
23
21
 
24
- ## Summary
22
+ ## 摘要
25
23
 
26
- This tool utilizes the natural language processing capability of chatbots to deliver our requirements and data in a conversational manner and request a response in a serializable format, such as JSON.
24
+ 本工具是利用聊天機器人能夠讀懂自然語言的特性,將我們的需求與資料透過口語化的方式交付給他處理,並要求回應可序列化格式,例如:JSON
27
25
 
28
- During the conversation, [yup](https://github.com/jquense/yup) is used to validate whether the request and response data meet expectations to ensure consistency. As long as this interaction mode is maintained, it can be used in API integration or automation systems.
26
+ 在對話過程中,本工具採用 [yup](https://github.com/jquense/yup) 來驗證請求與回復資料是否符合預期,以確保一致性,只要保持這個互動模式,就可以利用在 API 串接或是自動化系統上。
29
27
 
30
- We also provide some basic integration solutions for chatbots. Currently, ChatGPT3 and ChatGPT3.5 are supported.
28
+ 我們還附帶支援 `OpenAI` 的相關服務。
31
29
 
32
- ## Installation
30
+ ## 安裝
33
31
 
34
32
  npm:
35
33
 
@@ -43,27 +41,24 @@ yarn:
43
41
  yarn add ctod
44
42
  ```
45
43
 
46
- ## Quick Start
47
-
48
- This example demonstrates how to pass drug indices and customer requirements to a chatbot and return the most suitable result. Developers can use the index results to search the database for the most suitable drug for the consumer:
44
+ ## 快速開始
49
45
 
50
- > Regarding type definitions, there is an interesting issue here: the input and output must be declared first in order for the types to function properly.
46
+ 這個例子示範如何將藥物索引與客戶需求傳遞給聊天機器人,並返回最適合的結果,開發人員可以利用索引結果去資料庫搜尋最適合的藥物給消費者:
51
47
 
52
- > The usage of ChatGPT4 is exactly the same as ChatGPT35.
48
+ > 關於型態定義,這裡有個有趣的議題,必須將 input output 優先宣告才能讓型態正常運作。
53
49
 
54
50
  ```ts
55
- import { ChatGPT35Broker, templates } from 'ctod'
51
+ import { ChatBroker, OpenAI, templates } from 'ctod'
56
52
 
57
- const API_KEY = 'openai api key'
58
- const broker = new ChatGPT35Broker({
59
- /** Validate input data */
53
+ const broker = new ChatBroker({
54
+ /** 驗證輸入資料 */
60
55
  input: yup => {
61
56
  return {
62
57
  indexs: yup.array(yup.string()).required(),
63
58
  question: yup.string().required()
64
59
  }
65
60
  },
66
- /** Validate output data */
61
+ /** 驗證輸出資料 */
67
62
  output: yup => {
68
63
  return {
69
64
  indexs: yup.array(yup.object({
@@ -72,24 +67,29 @@ const broker = new ChatGPT35Broker({
72
67
  })).required()
73
68
  }
74
69
  },
75
- /** Initialize the system, usually by embedding or hooking into the life cycle */
76
- install: ({ bot }) => {
77
- bot.setConfiguration(API_KEY)
78
- },
79
- /** Assemble and define the request we want to send to the bot */
70
+ /** 初始化系統,通常來植入或掛鉤生命週期 */
71
+ install: () => {},
72
+ /** 定義發送請求的接口 */
73
+ request: async(messages) => {
74
+ const openai = new OpenAI(API_KEY)
75
+ const chat = openai.createChat()
76
+ const { text } = await chat.talk(messages)
77
+ return text
78
+ }
79
+ /** 組裝與定義我們要向機器人發出的請求 */
80
80
  question: async({ indexs, question }) => {
81
81
  return templates.requireJsonResponse([
82
- 'I have the following indices',
82
+ '我有以下索引',
83
83
  `${JSON.stringify(indexs)}`,
84
- `Please help me parse "${question}" to which index it might belong`,
85
- 'and sort by relevance from high to low, giving a score of 0 to 1.'
84
+ `請幫我解析"${question}"可能是哪個索引`,
85
+ '且相關性由高到低排序並給予分數,分數由 0 ~ 1'
86
86
  ], {
87
87
  indexs: {
88
- desc: 'Indices sorted in descending order',
88
+ desc: '由高到低排序的索引',
89
89
  example: [
90
90
  {
91
- name: 'Index name',
92
- score: 'Evaluation score displayed as a number'
91
+ name: '索引名稱',
92
+ score: '評比分數,數字顯示'
93
93
  }
94
94
  ]
95
95
  }
@@ -97,20 +97,19 @@ const broker = new ChatGPT35Broker({
97
97
  }
98
98
  })
99
99
 
100
-
101
100
  broker.request({
102
- indexs: ['stomach-ache', 'back-pain', 'headache', 'sore-throat', 'limb-pain'],
103
- question: 'drinking coffee, eating sweets, gastroesophageal reflux'
101
+ indexs: ['胃痛', '腰痛', '頭痛', '喉嚨痛', '四肢疼痛'],
102
+ question: '喝咖啡,吃甜食,胃食道逆流'
104
103
  }).then(e => {
105
- console.log('output result:', e.indexs)
104
+ console.log('輸出結果:', e.indexs)
106
105
  /*
107
106
  [
108
107
  {
109
- name: 'stomach-ache',
108
+ name: '胃痛',
110
109
  score: 1
111
110
  },
112
111
  {
113
- name: 'sore-throat',
112
+ name: '喉嚨痛',
114
113
  score: 0.7
115
114
  },
116
115
  ...
@@ -119,33 +118,26 @@ broker.request({
119
118
  })
120
119
  ```
121
120
 
122
- ### Examples
123
-
124
- 1. [How to continue the conversation with ChatGPT35 chatbot](./examples/chatgpt3.5.ts)
125
-
126
- 2. [How to integrate machine responses using ChatGPT35Broker](./examples/chatgpt3.5-broker.ts)
121
+ ## Plugin
127
122
 
128
- ## Plugin
123
+ 雖然 Broker 本身已經能夠處理大部分的事務,但透過 Plugin 可以協助改善複雜的流程,幫助專案工程化。
129
124
 
130
- Although the Broker itself is capable of handling most tasks, plugins can help improve complex processes and facilitate project engineering.
125
+ 每次發送請求時,Broker 會觸發一系列的生命週期,你可以從[原始碼](./lib/broker/chat.ts)中了解每個生命週期的參數與行為,並對其行為進行加工。
131
126
 
132
- Each time a request is sent, the Broker triggers a series of lifecycles. You can understand the parameters and behaviors of each lifecycle from the [source code](./lib/broker/35.ts) and modify its behavior.
133
-
134
- Now, let's say we want to design a plugin that backs up messages to a server every time a conversation ends:
127
+ 現在,假設我們想要設計一個插件,它會在每次對話結束時將訊息備份到伺服器上:
135
128
 
136
129
  ```ts
137
130
  import axios from 'axios'
138
- import { ChatGPT35Broker, Broker35Plugin } from 'ctod'
139
-
140
- const backupPlugin = new Broker35Plugin({
131
+ import { ChatBroker, ChatBrokerPlugin } from 'ctod'
132
+ const backupPlugin = new ChatBrokerPlugin({
141
133
  name: 'backup-plugin',
142
- // Define the 'sendUrl' parameter
134
+ // 定義參數為 sendUrl
143
135
  params: yup => {
144
136
  return {
145
137
  sendUrl: yup.string().required()
146
138
  }
147
139
  },
148
- // Define the structure of received data
140
+ // 現階段你可以在執行過程中接收到資訊,資訊結構由這裡定義。
149
141
  receiveData: yup => {
150
142
  return {
151
143
  character: yup.string().required()
@@ -153,23 +145,23 @@ const backupPlugin = new Broker35Plugin({
153
145
  },
154
146
  onInstall({ params, attach, receive }) {
155
147
  const store = new Map()
156
- // If there are more custom information to be passed, you can use plugins[key].send({ ... }) during the execution process
157
- // You can refer to the case of Role-playing as a Chatbot in the Applications section
148
+ // 假設我們有更多的自訂義資訊需要被傳遞進來,可以在 start 階段透過 plugins[key].send({ ... }) 傳遞
149
+ // 可以從 Applications 分類中的 請機器人角色扮演 觀看案例
158
150
  receive(({ id, context }) => {
159
151
  store.get(id).context = context
160
152
  })
161
- // Initialize data for the first conversation
162
- attach('talkFirst', async({ id }) => {
153
+ // 第一次對話的時候初始化資料
154
+ attach('start', async({ id }) => {
163
155
  store.set(id, {
164
156
  messages: [],
165
157
  context: null
166
158
  })
167
159
  })
168
- // Store the conversation after each conversation
160
+ // 每次對話完畢後把對話存入狀態
169
161
  attach('talkAfter', async({ id, lastUserMessage }) => {
170
162
  store.get(id).messages.push(lastUserMessage)
171
163
  })
172
- // Backup data after the conversation ends
164
+ // 結束對話後備份資料
173
165
  attach('done', async({ id }) => {
174
166
  await axios.post(params.sendUrl, store.get(id))
175
167
  store.delete(id)
@@ -177,71 +169,33 @@ const backupPlugin = new Broker35Plugin({
177
169
  }
178
170
  })
179
171
 
180
- const broker = new ChatGPT35Broker({
172
+ const broker = new ChatBroker({
181
173
  // ...
182
- plugins: [
183
- backupPlugin.use({
174
+ plugins: {
175
+ backup: backupPlugin.use({
184
176
  sendUrl: 'https://api/backup'
185
177
  })
186
- ],
187
- // Alternatively, you can use the following approach
188
- // plugins: () => [
189
- // backupPlugin.use({
190
- // sendUrl: 'https://api/backup'
191
- // })
192
- // ],
178
+ },
179
+ // 以下方案也可以運行
180
+ // plugins: () => {
181
+ // return {
182
+ // backup: backupPlugin.use({
183
+ // sendUrl: 'https://api/backup'
184
+ // })
185
+ // }
186
+ // },
193
187
  // ...
194
188
  })
195
189
  ```
196
190
 
197
- ### Examples
198
-
199
- 1. Print the execution flow: [Print Log Plugin](./lib/plugins/print-log.ts)
200
- 2. Limit the sending rate: [Limiter Plugin](./lib/plugins/limiter.ts)
201
- 3. Retry on failure: [Retry Plugin](./lib/plugins/retry.ts)
191
+ ## Examples
202
192
 
203
- ### Applications
193
+ [基礎用法 - 藥物查詢功能](./examples/chat-demo.ts)
204
194
 
205
- Here are some application examples that you can refer to when designing your AI system.
206
-
207
- > You can clone this project, add a .key file in the root directory, and paste your OpenAI Dev Key to quickly try out these examples.
208
-
209
- [Interpret BBC News](./examples/applications/bbc-news-reader.ts)
210
- [Role-playing as a Chatbot](./examples/applications/cosplay.ts)
211
- [Story and Cover Generator]('./examples/applications/story-generations.ts')
212
- [Conversation Generator]('./examples/applications/talk-generations.ts')
195
+ [進階用法 - AI COSPLAY](./examples//plugin-demo.ts)
213
196
 
214
197
  ## Version History
215
198
 
216
- ### 0.2.0
217
-
218
- * Add ChatGPT 4
219
-
220
- ### 0.1.3
221
-
222
- * Remove: max_token
223
- * Add: model add 16k
224
-
225
- ### 0.1.x
226
-
227
- We made significant changes to the plugin to facilitate data exchange.
228
-
229
- #### ChatGPT35 Service
230
-
231
- ##### remove: getJailbrokenMessages
232
-
233
- This approach is deprecated.
234
-
235
- #### Broker
236
-
237
- ##### add: setPreMessages
238
-
239
- Allows users to enter some messages before the conversation starts, ensuring that the primary question is included.
240
-
241
- ##### fix: hook
242
-
243
- Modified the binding behavior. Now, the binding of the Broker takes priority over plugins.
244
-
245
- ##### change: assembly => question
199
+ ### 0.3.0
246
200
 
247
- To make it easier for users to understand, we renamed "assembly" to "question".
201
+ 為了支援更多平台與自建服務,我們捨棄了完全為了 ChatGPT 客制化的接口,這樣也能完整保持 Broker Plugin 的一致性。
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ctod=e():t.ctod=e()}(this||("undefined"!=typeof window?window:global),(()=>(()=>{"use strict";var t={336:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPT3Broker=void 0;var u=n(470),s=n(550),c=n(860),l=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.bot=new c.ChatGPT3,e}return o(e,t),e.prototype.request=function(t){return i(this,void 0,void 0,(function(){var e,n,r,o=this;return a(this,(function(s){switch(s.label){case 0:return this._install(),e=u.flow.createUuid(),n=null,[4,this.translator.compile(t)];case 1:return r=s.sent(),[4,u.flow.asyncWhile((function(u){var s=u.count,c=u.doBreak;return i(o,void 0,void 0,(function(){var o,i,u,l,f,h,p,d=this;return a(this,(function(a){switch(a.label){case 0:if(s>=10)return[2,c()];for(h in o=null,i="",u=!1,l={},f=function(t){l[t]={send:function(n){return d.plugins[t].send({id:e,data:n})}}},this.plugins)f(h);a.label=1;case 1:return a.trys.push([1,8,,12]),[4,this.hook.notify("talkBefore",{id:e,data:t,plugins:l,prompt:r.prompt})];case 2:return a.sent(),[4,this.bot.talk(r.prompt)];case 3:return o=a.sent(),i=o.text,[4,this.hook.notify("talkAfter",{id:e,data:t,prompt:r.prompt,response:o,parseText:i,changeParseText:function(t){i=t}})];case 4:return a.sent(),[4,this.translator.parse(i)];case 5:return n=a.sent().output,[4,this.hook.notify("succeeded",{id:e,output:n})];case 6:return a.sent(),[4,this.hook.notify("done",{id:e})];case 7:return a.sent(),c(),[3,12];case 8:return(p=a.sent()).isParserError?[4,this.hook.notify("parseFailed",{id:e,error:p.error,count:s,response:o,parserFails:p.parserFails,retry:function(){u=!0},changePrompt:function(t){r.prompt=t}})]:[3,10];case 9:if(a.sent(),!1===u)return[2,c()];a.label=10;case 10:return[4,this.hook.notify("done",{id:e})];case 11:throw a.sent(),p;case 12:return[2]}}))}))}))];case 2:return s.sent(),[2,n]}}))}))},e}(s.BaseBroker);e.ChatGPT3Broker=l},215:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},u=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},s=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPT35Broker=void 0;var c=n(470),l=n(550),f=n(655),h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.bot=new f.ChatGPT35,e}return o(e,t),e.prototype.request=function(t){return i(this,void 0,void 0,(function(){var e,n,r,o,l,f,h,p=this;return a(this,(function(d){switch(d.label){case 0:return this._install(),e=c.flow.createUuid(),n=null,r={},[4,this.translator.compile(t)];case 1:for(h in o=d.sent(),l=[{role:"user",content:o.prompt}],f=function(t){r[t]={send:function(n){return p.plugins[t].send({id:e,data:n})}}},this.plugins)f(h);return[4,this.hook.notify("talkFirst",{id:e,data:t,plugins:r,messages:l,setPreMessages:function(t){l=s(s([],u(t),!1),[{role:"user",content:o.prompt}],!1)},changeMessages:function(t){l=t}})];case 2:return d.sent(),[4,c.flow.asyncWhile((function(r){var o=r.count,u=r.doBreak;return i(p,void 0,void 0,(function(){var r,i,s,c,f,h;return a(this,(function(a){switch(a.label){case 0:if(o>=10)return[2,u()];r=null,i="",s=!1,c=(null===(h=l.filter((function(t){return"user"===t.role})).slice(-1)[0])||void 0===h?void 0:h.content)||"",a.label=1;case 1:return a.trys.push([1,8,,15]),[4,this.hook.notify("talkBefore",{id:e,data:t,messages:l,lastUserMessage:c})];case 2:return a.sent(),[4,this.bot.talk(l)];case 3:return r=a.sent(),i=r.text,[4,this.hook.notify("talkAfter",{id:e,data:t,response:r,parseText:i,messages:r.newMessages,lastUserMessage:c,changeParseText:function(t){i=t}})];case 4:return a.sent(),l=r.newMessages,[4,this.translator.parse(i)];case 5:return n=a.sent().output,[4,this.hook.notify("succeeded",{id:e,output:n})];case 6:return a.sent(),[4,this.hook.notify("done",{id:e})];case 7:return a.sent(),u(),[3,15];case 8:return(f=a.sent()).isParserError?[4,this.hook.notify("parseFailed",{id:e,error:f.error,count:o,response:r,messages:l,lastUserMessage:c,parserFails:f.parserFails,retry:function(){s=!0},changeMessages:function(t){l=t}})]:[3,12];case 9:return a.sent(),!1!==s?[3,11]:[4,this.hook.notify("done",{id:e})];case 10:throw a.sent(),f;case 11:return[3,14];case 12:return[4,this.hook.notify("done",{id:e})];case 13:throw a.sent(),f;case 14:return[3,15];case 15:return[2]}}))}))}))];case 3:return d.sent(),[2,n]}}))}))},e}(l.BaseBroker);e.ChatGPT35Broker=h},634:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},u=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},s=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPT4Broker=void 0;var c=n(470),l=n(550),f=n(516),h=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.bot=new f.ChatGPT4,e}return o(e,t),e.prototype.request=function(t){return i(this,void 0,void 0,(function(){var e,n,r,o,l,f,h,p=this;return a(this,(function(d){switch(d.label){case 0:return this._install(),e=c.flow.createUuid(),n=null,r={},[4,this.translator.compile(t)];case 1:for(h in o=d.sent(),l=[{role:"user",content:o.prompt}],f=function(t){r[t]={send:function(n){return p.plugins[t].send({id:e,data:n})}}},this.plugins)f(h);return[4,this.hook.notify("talkFirst",{id:e,data:t,plugins:r,messages:l,setPreMessages:function(t){l=s(s([],u(t),!1),[{role:"user",content:o.prompt}],!1)},changeMessages:function(t){l=t}})];case 2:return d.sent(),[4,c.flow.asyncWhile((function(r){var o=r.count,u=r.doBreak;return i(p,void 0,void 0,(function(){var r,i,s,c,f,h;return a(this,(function(a){switch(a.label){case 0:if(o>=10)return[2,u()];r=null,i="",s=!1,c=(null===(h=l.filter((function(t){return"user"===t.role})).slice(-1)[0])||void 0===h?void 0:h.content)||"",a.label=1;case 1:return a.trys.push([1,8,,15]),[4,this.hook.notify("talkBefore",{id:e,data:t,messages:l,lastUserMessage:c})];case 2:return a.sent(),[4,this.bot.talk(l)];case 3:return r=a.sent(),i=r.text,[4,this.hook.notify("talkAfter",{id:e,data:t,response:r,parseText:i,messages:r.newMessages,lastUserMessage:c,changeParseText:function(t){i=t}})];case 4:return a.sent(),l=r.newMessages,[4,this.translator.parse(i)];case 5:return n=a.sent().output,[4,this.hook.notify("succeeded",{id:e,output:n})];case 6:return a.sent(),[4,this.hook.notify("done",{id:e})];case 7:return a.sent(),u(),[3,15];case 8:return(f=a.sent()).isParserError?[4,this.hook.notify("parseFailed",{id:e,error:f.error,count:o,response:r,messages:l,lastUserMessage:c,parserFails:f.parserFails,retry:function(){s=!0},changeMessages:function(t){l=t}})]:[3,12];case 9:return a.sent(),!1!==s?[3,11]:[4,this.hook.notify("done",{id:e})];case 10:throw a.sent(),f;case 11:return[3,14];case 12:return[4,this.hook.notify("done",{id:e})];case 13:throw a.sent(),f;case 14:return[3,15];case 15:return[2]}}))}))}))];case 3:return d.sent(),[2,n]}}))}))},e}(l.BaseBroker);e.ChatGPT4Broker=h},550:function(t,e,n){var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.BaseBroker=void 0;var o=n(470),i=n(15),a=n(87),u=function(){function t(t){var e;this.hook=new o.Hook,this.plugins={},this.installed=!1,this.log=new o.Log(null!==(e=t.name)&&void 0!==e?e:"no name"),this.params=t,this.translator=new a.Translator(r(r({},t),{parsers:[i.TextParser.JsonMessage()]}))}return t.prototype._install=function(){if(!1===this.installed&&(this.installed=!0,this.bot)){var t={bot:this.bot,log:this.log,attach:this.hook.attach.bind(this.hook),attachAfter:this.hook.attachAfter.bind(this.hook),translator:this.translator};if(this.params.install(t),this.params.plugins)for(var e in this.plugins="function"==typeof this.params.plugins?this.params.plugins():this.params.plugins,this.plugins)this.plugins[e].instance._params.onInstall(r(r({},t),{params:this.plugins[e].params,receive:this.plugins[e].receive}))}},t.prototype.request=function(t){throw Error("DON'T CALL THIS!")},t}();e.BaseBroker=u},15:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.TextParser=void 0;var a=i(n(959)),u=function(){function t(t){this.params=t}return t.JsonMessage=function(){var e=this;return new t({name:"JsonMessage",handler:function(t){return r(e,void 0,void 0,(function(){var e,n,r;return o(this,(function(o){return e=/{(?:[^{}]|(?:{[^{}]*}))*}/,n=(null===(r=t.match(e))||void 0===r?void 0:r[0])||"",[2,a.default.parse(n)]}))}))}})},Object.defineProperty(t.prototype,"name",{get:function(){return this.params.name},enumerable:!1,configurable:!0}),t.prototype.read=function(t){return r(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.params.handler(t)];case 1:return[2,e.sent()]}}))}))},t}();e.TextParser=u},241:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Broker4Plugin=e.Broker35Plugin=e.Broker3Plugin=void 0;var r=n(470),o=function(){function t(t){this._event=new r.Event,this._params=t}return t.prototype.use=function(t){var e=this;return{instance:this,params:t,send:function(t){e._event.emit("receive",t)},receive:function(t){e._event.on("receive",t)},__receiveData:null}},t}();e.Broker3Plugin=o;var i=function(){function t(t){this._event=new r.Event,this._params=t}return t.prototype.use=function(t){var e=this;return{instance:this,params:t,send:function(t){e._event.emit("receive",t)},receive:function(t){e._event.on("receive",t)},__receiveData:null}},t}();e.Broker35Plugin=i;var a=function(){function t(t){this._event=new r.Event,this._params=t}return t.prototype.use=function(t){var e=this;return{instance:this,params:t,send:function(t){e._event.emit("receive",t)},receive:function(t){e._event.on("receive",t)},__receiveData:null}},t}();e.Broker4Plugin=a},87:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0}),e.Translator=void 0;var a=n(293),u=function(){function t(t){this.params=t}return Object.defineProperty(t.prototype,"__schemeType",{get:function(){return null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"__outputType",{get:function(){return null},enumerable:!1,configurable:!0}),t.prototype.compile=function(t){return r(this,void 0,void 0,(function(){var e,n;return o(this,(function(r){switch(r.label){case 0:return e=(0,a.validate)(t,this.params.input),[4,this.params.question(e)];case 1:return n=r.sent(),[2,{scheme:e,prompt:n}]}}))}))},t.prototype.parse=function(t){return r(this,void 0,void 0,(function(){var e,n,r,u,s,c,l,f,h,p;return o(this,(function(o){switch(o.label){case 0:e=void 0,n="",r=[],o.label=1;case 1:o.trys.push([1,8,9,10]),u=i(this.params.parsers),s=u.next(),o.label=2;case 2:if(s.done)return[3,7];c=s.value,o.label=3;case 3:return o.trys.push([3,5,,6]),[4,c.read(t)];case 4:return e=o.sent(),n=c.name,[3,6];case 5:return l=o.sent(),e=void 0,r.push({name:c.name,error:l}),[3,6];case 6:return s=u.next(),[3,2];case 7:return[3,10];case 8:return f=o.sent(),h={error:f},[3,10];case 9:try{s&&!s.done&&(p=u.return)&&p.call(u)}finally{if(h)throw h.error}return[7];case 10:try{return[2,{output:(0,a.validate)(e,this.params.output),parserName:n,parserFails:r}]}catch(t){throw{isParserError:!0,error:t,parserFails:r}}return[2]}}))}))},t}();e.Translator=u},620:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return o(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.ctod=e.templates=e.plugins=e.ImagesGenerations=e.Broker4Plugin=e.Broker35Plugin=e.Broker3Plugin=e.ChatGPT4Broker=e.ChatGPT35Broker=e.ChatGPT3Broker=e.ChatGPT4=e.ChatGPT35=e.ChatGPT3=e.Translator=e.TextParser=void 0;var a=i(n(241)),u=i(n(218)),s=i(n(298)),c=i(n(87)),l=n(15),f=n(860),h=n(655),p=n(516),d=n(336),v=n(215),y=n(634),b=n(283);e.TextParser=l.TextParser,e.Translator=c.Translator,e.ChatGPT3=f.ChatGPT3,e.ChatGPT35=h.ChatGPT35,e.ChatGPT4=p.ChatGPT4,e.ChatGPT3Broker=d.ChatGPT3Broker,e.ChatGPT35Broker=v.ChatGPT35Broker,e.ChatGPT4Broker=y.ChatGPT4Broker,e.Broker3Plugin=a.Broker3Plugin,e.Broker35Plugin=a.Broker35Plugin,e.Broker4Plugin=a.Broker35Plugin,e.ImagesGenerations=b.ImagesGenerations,e.plugins=u,e.templates=s,e.ctod={plugins:e.plugins,templates:e.templates,ChatGPT3:e.ChatGPT3,ChatGPT35:e.ChatGPT35,ChatGPT4:e.ChatGPT4,Translator:e.Translator,TextParser:e.TextParser,Broker3Plugin:e.Broker3Plugin,Broker35Plugin:e.Broker35Plugin,Broker4Plugin:e.Broker4Plugin,ChatGPT3Broker:e.ChatGPT3Broker,ChatGPT35Broker:e.ChatGPT35Broker,ChatGPT4Broker:e.ChatGPT4Broker,ImagesGenerations:e.ImagesGenerations},t.exports=e.ctod,t.exports.ctod=e.ctod,e.default=e.ctod},218:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.RolePlugin=e.LimiterPlugin=e.RetryPlugin=e.PrintLogPlugin=void 0;var o=r(n(894)),i=r(n(829)),a=r(n(626)),u=r(n(1));e.PrintLogPlugin=i.default,e.RetryPlugin=o.default,e.LimiterPlugin=a.default,e.RolePlugin=u.default},626:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(241),a=n(470),u={limit:3,interval:6e4},s={event:new a.Event,schedule:null,waitTimes:[],waitQueue:[]};e.default={event:s.event,config:u,closeSchedule:function(){s.schedule&&(s.schedule.close(),s.schedule=null)},ver35:new i.Broker35Plugin({name:"limiter",params:function(){return{}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.attach;null==s.schedule&&(s.schedule=new a.Schedule,s.schedule.add("calc queue",1e3,(function(){return r(e,void 0,void 0,(function(){var t,e;return o(this,(function(n){return t=Date.now(),s.waitTimes=s.waitTimes.filter((function(e){return t-e<u.interval})),s.waitTimes.length!==u.limit?(e=s.waitQueue.shift())&&(s.waitTimes.push(Date.now()),s.event.emit("run",{id:e})):s.waitTimes[0]&&s.event.emit("waitTimeChange",{waitTime:Math.floor(60-(t-s.waitTimes[0])/1e3)}),[2]}))}))})),s.schedule.play()),n("talkBefore",(function(){return r(e,void 0,void 0,(function(){var t;return o(this,(function(e){return t=a.flow.createUuid(),s.waitQueue.push(t),[2,new Promise((function(e){s.event.on("run",(function(n,r){var o=n.id,i=r.off;o===t&&(i(),e())}))}))]}))}))}))}}),ver4:new i.Broker4Plugin({name:"limiter",params:function(){return{}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.attach;null==s.schedule&&(s.schedule=new a.Schedule,s.schedule.add("calc queue",1e3,(function(){return r(e,void 0,void 0,(function(){var t,e;return o(this,(function(n){return t=Date.now(),s.waitTimes=s.waitTimes.filter((function(e){return t-e<u.interval})),s.waitTimes.length!==u.limit?(e=s.waitQueue.shift())&&(s.waitTimes.push(Date.now()),s.event.emit("run",{id:e})):s.waitTimes[0]&&s.event.emit("waitTimeChange",{waitTime:Math.floor(60-(t-s.waitTimes[0])/1e3)}),[2]}))}))})),s.schedule.play()),n("talkBefore",(function(){return r(e,void 0,void 0,(function(){var t;return o(this,(function(e){return t=a.flow.createUuid(),s.waitQueue.push(t),[2,new Promise((function(e){s.event.on("run",(function(n,r){var o=n.id,i=r.off;o===t&&(i(),e())}))}))]}))}))}))}})}},829:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(241);e.default={ver3:new i.Broker3Plugin({name:"print-log",params:function(){return{}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.log,i=t.attach;i("talkBefore",(function(t){var i=t.prompt;return r(e,void 0,void 0,(function(){return o(this,(function(t){return n.print("Send:",{color:"green"}),n.print(i),[2]}))}))})),i("talkAfter",(function(t){var i=t.parseText;return r(e,void 0,void 0,(function(){return o(this,(function(t){return n.print("Receive:",{color:"red"}),n.print(i),[2]}))}))})),i("succeeded",(function(t){var i=t.output;return r(e,void 0,void 0,(function(){return o(this,(function(t){n.print("Output:",{color:"yellow"});try{n.print("\n"+JSON.stringify(i,null,4))}catch(t){n.print("\n"+i)}return[2]}))}))}))}}),ver35:new i.Broker35Plugin({name:"print-log",params:function(t){return{detail:t.boolean().required().default(!1)}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.params,i=t.log,a=t.attach;a("talkBefore",(function(t){var a=t.lastUserMessage,u=t.messages;return r(e,void 0,void 0,(function(){return o(this,(function(t){return i.print("Send:",{color:"green"}),n.detail?i.print("\n"+JSON.stringify(u,null,4)):i.print("\n"+a),[2]}))}))})),a("talkAfter",(function(t){var n=t.parseText;return r(e,void 0,void 0,(function(){return o(this,(function(t){return i.print("Receive:",{color:"cyan"}),i.print("\n"+n),[2]}))}))})),a("succeeded",(function(t){var n=t.output;return r(e,void 0,void 0,(function(){return o(this,(function(t){i.print("Output:",{color:"yellow"});try{i.print("\n"+JSON.stringify(n,null,4))}catch(t){i.print("\n"+n)}return[2]}))}))}))}}),ver4:new i.Broker4Plugin({name:"print-log",params:function(t){return{detail:t.boolean().required().default(!1)}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.params,i=t.log,a=t.attach;a("talkBefore",(function(t){var a=t.lastUserMessage,u=t.messages;return r(e,void 0,void 0,(function(){return o(this,(function(t){return i.print("Send:",{color:"green"}),n.detail?i.print("\n"+JSON.stringify(u,null,4)):i.print("\n"+a),[2]}))}))})),a("talkAfter",(function(t){var n=t.parseText;return r(e,void 0,void 0,(function(){return o(this,(function(t){return i.print("Receive:",{color:"cyan"}),i.print("\n"+n),[2]}))}))})),a("succeeded",(function(t){var n=t.output;return r(e,void 0,void 0,(function(){return o(this,(function(t){i.print("Output:",{color:"yellow"});try{i.print("\n"+JSON.stringify(n,null,4))}catch(t){i.print("\n"+n)}return[2]}))}))}))}})}},894:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(241);e.default={ver35:new i.Broker35Plugin({name:"retry",params:function(t){return{retry:t.number().required().default(1),printWarn:t.boolean().required().default(!0)}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.log,i=t.attach,a=t.params;i("parseFailed",(function(t){var i=t.count,u=t.retry,s=t.response,c=t.changeMessages;return r(e,void 0,void 0,(function(){return o(this,(function(t){return i<=a.retry&&(a.printWarn&&n.print("Is Failed, Retry ".concat(i," times.")),c(s.newMessages.slice(0,-1)),u()),[2]}))}))}))}}),ver4:new i.Broker4Plugin({name:"retry",params:function(t){return{retry:t.number().required().default(1),printWarn:t.boolean().required().default(!0)}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.log,i=t.attach,a=t.params;i("parseFailed",(function(t){var i=t.count,u=t.retry,s=t.response,c=t.changeMessages;return r(e,void 0,void 0,(function(){return o(this,(function(t){return i<=a.retry&&(a.printWarn&&n.print("Is Failed, Retry ".concat(i," times.")),c(s.newMessages.slice(0,-1)),u()),[2]}))}))}))}})}},1:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},a=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0});var u=n(241);e.default={ver35:new u.Broker35Plugin({name:"role",params:function(t){return{role:t.string().required()}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.attach,u=t.params;n("talkFirst",(function(t){var n=t.messages,s=t.changeMessages;return r(e,void 0,void 0,(function(){return o(this,(function(t){return s(a([{role:"user",content:"你現在是".concat(u.role,"。")},{role:"assistant",content:"沒問題,我現在是".concat(u.role,",有什麼可以幫你的嗎?")}],i(n),!1)),[2]}))}))}))}}),ver4:new u.Broker4Plugin({name:"role",params:function(t){return{role:t.string().required()}},receiveData:function(){return{}},onInstall:function(t){var e=this,n=t.attach,u=t.params;n("talkFirst",(function(t){var n=t.messages,s=t.changeMessages;return r(e,void 0,void 0,(function(){return o(this,(function(t){return s(a([{role:"user",content:"你現在是".concat(u.role,"。")},{role:"assistant",content:"沒問題,我現在是".concat(u.role,",有什麼可以幫你的嗎?")}],i(n),!1)),[2]}))}))}))}})}},860:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPT3=void 0;var a=i(n(167)),u=function(){function t(){this.axios=a.default.create(),this.apiKey="",this.config={n:1,maxTokens:2048,temperature:1}}return t.prototype.setAxios=function(t){this.axios=t},t.prototype.setConfiguration=function(t){this.apiKey=t},t.prototype.setConfig=function(t){Object.assign(this.config,t)},t.prototype.talk=function(t){var e,n;return r(this,void 0,void 0,(function(){var r,i;return o(this,(function(o){switch(o.label){case 0:return[4,this.axios.post("https://api.openai.com/v1/completions",{model:"text-davinci-003",n:this.config.n,prompt:Array.isArray(t)?t.join("\n"):t,max_tokens:this.config.maxTokens,temperature:this.config.temperature},{headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.apiKey)}})];case 1:return r=o.sent(),i=r.data.choices||[],[2,{id:r.data.id,text:(null===(e=i[0])||void 0===e?void 0:e.text)||"",isDone:"stop"===(null===(n=i[0])||void 0===n?void 0:n.finish_reason),apiReseponse:r.data}]}}))}))},t}();e.ChatGPT3=u},655:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},a=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPT35=void 0;var s=u(n(167)),c=n(470),l=function(){function t(){this.axios=s.default.create(),this.apiKey="",this.config={n:1,model:"gpt-3.5-turbo",temperature:1}}return t.prototype.setAxios=function(t){this.axios=t},t.prototype.setConfiguration=function(t){this.apiKey=t},t.prototype.setConfig=function(t){Object.assign(this.config,t)},t.prototype.talk=function(t){var e,n;return void 0===t&&(t=[]),r(this,void 0,void 0,(function(){var r,i,a,u;return o(this,(function(o){switch(o.label){case 0:return r=c.json.jpjs(t),[4,this.axios.post("https://api.openai.com/v1/chat/completions",{model:this.config.model,n:this.config.n,messages:r,temperature:this.config.temperature},{headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.apiKey)}})];case 1:return i=o.sent(),a=i.data.choices||[],u=(null===(e=a[0])||void 0===e?void 0:e.message)||{role:"assistant",content:""},r.push(u),[2,{id:null==i?void 0:i.data.id,text:u.content,isDone:"stop"===(null===(n=a[0])||void 0===n?void 0:n.finish_reason),newMessages:r,apiReseponse:i.data}]}}))}))},t.prototype.chat=function(t,e){return void 0===e&&(e=[]),r(this,void 0,void 0,(function(){var n,r=this;return o(this,(function(o){switch(o.label){case 0:return[4,this.talk(a(a([],i(e),!1),[{role:"user",content:Array.isArray(t)?t.join("\n"):t}],!1))];case 1:return[2,{result:n=o.sent(),nextTalk:function(t){return r.chat(t,n.newMessages)}}]}}))}))},t}();e.ChatGPT35=l},516:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},a=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPT4=void 0;var s=u(n(167)),c=n(470),l=function(){function t(){this.axios=s.default.create(),this.apiKey="",this.config={n:1,model:"gpt-4",temperature:1}}return t.prototype.setAxios=function(t){this.axios=t},t.prototype.setConfiguration=function(t){this.apiKey=t},t.prototype.setConfig=function(t){Object.assign(this.config,t)},t.prototype.talk=function(t){var e,n;return void 0===t&&(t=[]),r(this,void 0,void 0,(function(){var r,i,a,u;return o(this,(function(o){switch(o.label){case 0:return r=c.json.jpjs(t),[4,this.axios.post("https://api.openai.com/v1/chat/completions",{model:this.config.model,n:this.config.n,messages:r,temperature:this.config.temperature},{headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.apiKey)}})];case 1:return i=o.sent(),a=i.data.choices||[],u=(null===(e=a[0])||void 0===e?void 0:e.message)||{role:"assistant",content:""},r.push(u),[2,{id:null==i?void 0:i.data.id,text:u.content,isDone:"stop"===(null===(n=a[0])||void 0===n?void 0:n.finish_reason),newMessages:r,apiReseponse:i.data}]}}))}))},t.prototype.chat=function(t,e){return void 0===e&&(e=[]),r(this,void 0,void 0,(function(){var n,r=this;return o(this,(function(o){switch(o.label){case 0:return[4,this.talk(a(a([],i(e),!1),[{role:"user",content:Array.isArray(t)?t.join("\n"):t}],!1))];case 1:return[2,{result:n=o.sent(),nextTalk:function(t){return r.chat(t,n.newMessages)}}]}}))}))},t}();e.ChatGPT4=l},283:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,u)}s((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.ImagesGenerations=void 0;var a=i(n(167)),u=function(){function t(){this.axios=a.default.create(),this.apiKey="",this.config={n:1,size:"1024x1024"}}return t.prototype.setAxios=function(t){this.axios=t},t.prototype.setConfiguration=function(t){this.apiKey=t},t.prototype.setConfig=function(t){Object.assign(this.config,t)},t.prototype.create=function(t){return r(this,void 0,void 0,(function(){return o(this,(function(e){switch(e.label){case 0:return[4,this.axios.post("https://api.openai.com/v1/images/generations",{prompt:t,n:this.config.n,size:this.config.size,response_format:"b64_json"},{timeout:3e5,headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.apiKey)}})];case 1:return[2,e.sent().data]}}))}))},t}();e.ImagesGenerations=u},298:function(t,e,n){var r=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.requireJsonResponseWithHandlebars=e.requireJsonResponse=void 0;var a=i(n(97)),u=n(470);e.requireJsonResponse=function(t,e){return o(o([],r(Array.isArray(t)?t:[t]),!1),["Please respond using the following JSON format and minify the JSON without including any explanation: ","{",Object.entries(e).map((function(t){var e=r(t,2),n=e[0],o=e[1];return["/* ".concat(o.desc," */"),'"'.concat(n,'": ').concat(JSON.stringify(o.example))].join("\n")})).join(",\n"),"}"],!1).join("\n")},e.requireJsonResponseWithHandlebars=function(t,n,r){var o=a.default.create();return o.registerHelper("DATA",(function(t){return JSON.stringify(t)})),o.registerHelper("ENV",(function(t){return this.__envs&&t?this.__envs[t]:""})),o.registerHelper("INPUT",(function(){return JSON.stringify(u.record.omit(this,["__envs"]))})),o.registerHelper("JOIN",(function(t){return Array.isArray(t)?t.join():JSON.stringify(t)})),o.compile((0,e.requireJsonResponse)(n,r))(t)}},293:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return o(e,t),e};Object.defineProperty(e,"__esModule",{value:!0}),e.validate=e.definedValidateSchema=void 0;var a=i(n(609));e.definedValidateSchema=function(t){return t},e.validate=function(t,e){return a.object(e(a)).required().validateSync(t||{})}},167:t=>{t.exports=require("axios")},97:t=>{t.exports=require("handlebars")},959:t=>{t.exports=require("json5")},470:t=>{t.exports=require("power-helper")},609:t=>{t.exports=require("yup")}},e={};return function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}(620)})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ctod=t():e.ctod=t()}(this||("undefined"!=typeof window?window:global),(()=>(()=>{"use strict";var e={37:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},a=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},u=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.ChatBroker=void 0;var s=n(15),l=n(470),c=n(87),f=function(){function e(e){var t;this.hook=new l.Hook,this.plugins={},this.installed=!1,this.log=new l.Log(null!==(t=e.name)&&void 0!==t?t:"no name"),this.params=e,this.translator=new c.Translator(r(r({},e),{parsers:[s.TextParser.JsonMessage()]}))}return e.prototype._install=function(){if(!1===this.installed){this.installed=!0;var e={log:this.log,attach:this.hook.attach.bind(this.hook),attachAfter:this.hook.attachAfter.bind(this.hook),translator:this.translator};if(this.params.install(e),this.params.plugins)for(var t in this.plugins="function"==typeof this.params.plugins?this.params.plugins():this.params.plugins,this.plugins)this.plugins[t].instance._params.onInstall(r(r({},e),{params:this.plugins[t].params,receive:this.plugins[t].receive}))}},e.prototype.request=function(e){return o(this,void 0,void 0,(function(){var t,n,r,s,c,f,p,h=this;return i(this,(function(d){switch(d.label){case 0:return this._install(),t=l.flow.createUuid(),n=null,r={},[4,this.translator.compile(e)];case 1:for(p in s=d.sent(),c=[{role:"user",content:s.prompt}],f=function(e){r[e]={send:function(n){return h.plugins[e].send({id:t,data:n})}}},this.plugins)f(p);return[4,this.hook.notify("start",{id:t,data:e,plugins:r,messages:c,setPreMessages:function(e){c=u(u([],a(e),!1),[{role:"user",content:s.prompt}],!1)},changeMessages:function(e){c=e}})];case 2:return d.sent(),[4,l.flow.asyncWhile((function(r){var a=r.count,u=r.doBreak;return o(h,void 0,void 0,(function(){var r,o,s,l,f,p;return i(this,(function(i){switch(i.label){case 0:if(a>=10)return[2,u()];r="",o="",s=!1,l=(null===(p=c.filter((function(e){return"user"===e.role})).slice(-1)[0])||void 0===p?void 0:p.content)||"",i.label=1;case 1:return i.trys.push([1,8,,15]),[4,this.hook.notify("talkBefore",{id:t,data:e,messages:c,lastUserMessage:l})];case 2:return i.sent(),[4,this.params.request(c)];case 3:return r=i.sent(),o=r,[4,this.hook.notify("talkAfter",{id:t,data:e,response:r,messages:c,parseText:o,lastUserMessage:l,changeParseText:function(e){o=e}})];case 4:return i.sent(),[4,this.translator.parse(o)];case 5:return n=i.sent().output,[4,this.hook.notify("succeeded",{id:t,output:n})];case 6:return i.sent(),[4,this.hook.notify("done",{id:t})];case 7:return i.sent(),u(),[3,15];case 8:return(f=i.sent()).isParserError?[4,this.hook.notify("parseFailed",{id:t,error:f.error,count:a,response:r,messages:c,lastUserMessage:l,parserFails:f.parserFails,retry:function(){s=!0},changeMessages:function(e){c=e}})]:[3,12];case 9:return i.sent(),!1!==s?[3,11]:[4,this.hook.notify("done",{id:t})];case 10:throw i.sent(),f;case 11:return[3,14];case 12:return[4,this.hook.notify("done",{id:t})];case 13:throw i.sent(),f;case 14:return[3,15];case 15:return[2]}}))}))}))];case 3:return d.sent(),[2,n]}}))}))},e}();t.ChatBroker=f},15:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.TextParser=void 0;var a=i(n(959)),u=function(){function e(e){this.params=e}return e.JsonMessage=function(){var t=this;return new e({name:"JsonMessage",handler:function(e){return r(t,void 0,void 0,(function(){var t,n,r;return o(this,(function(o){return t=/{(?:[^{}]|(?:{[^{}]*}))*}/,n=(null===(r=e.match(t))||void 0===r?void 0:r[0])||"",[2,a.default.parse(n)]}))}))}})},Object.defineProperty(e.prototype,"name",{get:function(){return this.params.name},enumerable:!1,configurable:!0}),e.prototype.read=function(e){return r(this,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return[4,this.params.handler(e)];case 1:return[2,t.sent()]}}))}))},e}();t.TextParser=u},241:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChatBrokerPlugin=void 0;var r=n(470),o=function(){function e(e){this._event=new r.Event,this._params=e}return e.prototype.use=function(e){var t=this;return{instance:this,params:e,send:function(e){t._event.emit("receive",e)},receive:function(e){t._event.on("receive",e)},__receiveData:null}},e}();t.ChatBrokerPlugin=o},87:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0}),t.Translator=void 0;var a=n(293),u=function(){function e(e){this.params=e}return Object.defineProperty(e.prototype,"__schemeType",{get:function(){return null},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"__outputType",{get:function(){return null},enumerable:!1,configurable:!0}),e.prototype.compile=function(e){return r(this,void 0,void 0,(function(){var t,n;return o(this,(function(r){switch(r.label){case 0:return t=(0,a.validate)(e,this.params.input),[4,this.params.question(t)];case 1:return n=r.sent(),[2,{scheme:t,prompt:n}]}}))}))},e.prototype.parse=function(e){return r(this,void 0,void 0,(function(){var t,n,r,u,s,l,c,f,p,h;return o(this,(function(o){switch(o.label){case 0:t=void 0,n="",r=[],o.label=1;case 1:o.trys.push([1,8,9,10]),u=i(this.params.parsers),s=u.next(),o.label=2;case 2:if(s.done)return[3,7];l=s.value,o.label=3;case 3:return o.trys.push([3,5,,6]),[4,l.read(e)];case 4:return t=o.sent(),n=l.name,[3,6];case 5:return c=o.sent(),t=void 0,r.push({name:l.name,error:c}),[3,6];case 6:return s=u.next(),[3,2];case 7:return[3,10];case 8:return f=o.sent(),p={error:f},[3,10];case 9:try{s&&!s.done&&(h=u.return)&&h.call(u)}finally{if(p)throw p.error}return[7];case 10:try{return[2,{output:(0,a.validate)(t,this.params.output),parserName:n,parserFails:r}]}catch(e){throw{isParserError:!0,error:e,parserFails:r}}return[2]}}))}))},e}();t.Translator=u},620:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.ctod=t.templates=t.plugins=t.ChatBrokerPlugin=t.ChatBroker=t.Translator=t.TextParser=t.OpenAI=void 0;var a=i(n(218)),u=i(n(298)),s=i(n(87)),l=n(616),c=n(15),f=n(37),p=n(241);t.OpenAI=l.OpenAI,t.TextParser=c.TextParser,t.Translator=s.Translator,t.ChatBroker=f.ChatBroker,t.ChatBrokerPlugin=p.ChatBrokerPlugin,t.plugins=a,t.templates=u,t.ctod={OpenAI:t.OpenAI,plugins:t.plugins,templates:t.templates,ChatBroker:t.ChatBroker,Translator:t.Translator,TextParser:t.TextParser,ChatBrokerPlugin:t.ChatBrokerPlugin},e.exports=t.ctod,e.exports.ctod=t.ctod,t.default=t.ctod},218:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.RolePlugin=t.LimiterPluginGlobState=t.LimiterPlugin=t.RetryPlugin=t.PrintLogPlugin=void 0;var o=r(n(894)),i=r(n(829)),a=r(n(626)),u=r(n(1));t.PrintLogPlugin=i.default,t.RetryPlugin=o.default,t.LimiterPlugin=a.default.plugin,t.LimiterPluginGlobState=a.default,t.RolePlugin=u.default},626:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0});var i=n(241),a=n(470),u={limit:3,interval:6e4},s={event:new a.Event,schedule:null,waitTimes:[],waitQueue:[]};t.default={event:s.event,config:u,closeSchedule:function(){s.schedule&&(s.schedule.close(),s.schedule=null)},plugin:new i.ChatBrokerPlugin({name:"limiter",params:function(){return{}},receiveData:function(){return{}},onInstall:function(e){var t=this,n=e.attach;null==s.schedule&&(s.schedule=new a.Schedule,s.schedule.add("calc queue",1e3,(function(){return r(t,void 0,void 0,(function(){var e,t;return o(this,(function(n){return e=Date.now(),s.waitTimes=s.waitTimes.filter((function(t){return e-t<u.interval})),s.waitTimes.length!==u.limit?(t=s.waitQueue.shift())&&(s.waitTimes.push(Date.now()),s.event.emit("run",{id:t})):s.waitTimes[0]&&s.event.emit("waitTimeChange",{waitTime:Math.floor(60-(e-s.waitTimes[0])/1e3)}),[2]}))}))})),s.schedule.play()),n("talkBefore",(function(){return r(t,void 0,void 0,(function(){var e;return o(this,(function(t){return e=a.flow.createUuid(),s.waitQueue.push(e),[2,new Promise((function(t){s.event.on("run",(function(n,r){var o=n.id,i=r.off;o===e&&(i(),t())}))}))]}))}))}))}})}},829:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0});var i=n(241);t.default=new i.ChatBrokerPlugin({name:"print-log",params:function(e){return{detail:e.boolean().required().default(!1)}},receiveData:function(){return{}},onInstall:function(e){var t=this,n=e.params,i=e.log,a=e.attach;a("talkBefore",(function(e){var a=e.lastUserMessage,u=e.messages;return r(t,void 0,void 0,(function(){return o(this,(function(e){return i.print("Send:",{color:"green"}),n.detail?i.print("\n"+JSON.stringify(u,null,4)):i.print("\n"+a),[2]}))}))})),a("talkAfter",(function(e){var n=e.parseText;return r(t,void 0,void 0,(function(){return o(this,(function(e){return i.print("Receive:",{color:"cyan"}),i.print("\n"+n),[2]}))}))})),a("succeeded",(function(e){var n=e.output;return r(t,void 0,void 0,(function(){return o(this,(function(e){i.print("Output:",{color:"yellow"});try{i.print("\n"+JSON.stringify(n,null,4))}catch(e){i.print("\n"+n)}return[2]}))}))}))}})},894:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0});var i=n(241);t.default=new i.ChatBrokerPlugin({name:"retry",params:function(e){return{retry:e.number().required().default(1),printWarn:e.boolean().required().default(!0)}},receiveData:function(){return{}},onInstall:function(e){var t=this,n=e.log,i=e.attach,a=e.params;i("parseFailed",(function(e){var i=e.count,u=e.retry,s=e.response,l=e.changeMessages;return r(t,void 0,void 0,(function(){return o(this,(function(e){return i<=a.retry&&(a.printWarn&&n.print("Is Failed, Retry ".concat(i," times.")),l(s.newMessages.slice(0,-1)),u()),[2]}))}))}))}})},1:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},a=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0});var u=n(241);t.default=new u.ChatBrokerPlugin({name:"role",params:function(e){return{role:e.string().required()}},receiveData:function(){return{}},onInstall:function(e){var t=this,n=e.attach,u=e.params;n("start",(function(e){var n=e.messages,s=e.changeMessages;return r(t,void 0,void 0,(function(){return o(this,(function(e){return s(a([{role:"user",content:"你現在是".concat(u.role,"。")},{role:"assistant",content:"沒問題,我現在是".concat(u.role,",有什麼可以幫你的嗎?")}],i(n),!1)),[2]}))}))}))}})},203:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},i=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},a=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.OpenAIChat=void 0;var u=n(470),s=function(){function e(e){this.config={n:1,model:"gpt-3.5-turbo",temperature:1},this.openai=e}return e.prototype.setConfig=function(e){Object.assign(this.config,e)},e.prototype.talk=function(e){var t,n;return void 0===e&&(e=[]),r(this,void 0,void 0,(function(){var r,i,a,s;return o(this,(function(o){switch(o.label){case 0:return r=u.json.jpjs(e),[4,this.openai._axios.post("https://api.openai.com/v1/chat/completions",{model:this.config.model,n:this.config.n,messages:r,temperature:this.config.temperature},{headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.openai._apiKey)}})];case 1:return i=o.sent(),a=i.data.choices||[],s=(null===(t=a[0])||void 0===t?void 0:t.message)||{role:"assistant",content:""},r.push(s),[2,{id:null==i?void 0:i.data.id,text:s.content,newMessages:r,isDone:"stop"===(null===(n=a[0])||void 0===n?void 0:n.finish_reason),apiReseponse:i.data}]}}))}))},e.prototype.keepTalk=function(e,t){return void 0===t&&(t=[]),r(this,void 0,void 0,(function(){var n,r=this;return o(this,(function(o){switch(o.label){case 0:return[4,this.talk(a(a([],i(t),!1),[{role:"user",content:Array.isArray(e)?e.join("\n"):e}],!1))];case 1:return[2,{result:n=o.sent(),nextTalk:function(e){return r.keepTalk(e,n.newMessages)}}]}}))}))},e}();t.OpenAIChat=s},919:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.OpenAICompletion=void 0;var o=function(){function e(e){this.config={n:1,maxTokens:2048,temperature:1},this.openai=e}return e.prototype.setConfig=function(e){Object.assign(this.config,e)},e.prototype.run=function(e){var t,o;return n(this,void 0,void 0,(function(){var n,i;return r(this,(function(r){switch(r.label){case 0:return[4,this.openai._axios.post("https://api.openai.com/v1/completions",{model:"text-davinci-003",n:this.config.n,prompt:Array.isArray(e)?e.join("\n"):e,max_tokens:this.config.maxTokens,temperature:this.config.temperature},{headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.openai._apiKey)}})];case 1:return n=r.sent(),i=n.data.choices||[],[2,{id:n.data.id,text:(null===(t=i[0])||void 0===t?void 0:t.text)||"",isDone:"stop"===(null===(o=i[0])||void 0===o?void 0:o.finish_reason),apiReseponse:n.data}]}}))}))},e}();t.OpenAICompletion=o},725:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}s((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.OpenAIImagesGeneration=void 0;var o=function(){function e(e){this.config={n:1,size:"1024x1024"},this.openai=e}return e.prototype.setConfig=function(e){Object.assign(this.config,e)},e.prototype.create=function(e){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.openai._axios.post("https://api.openai.com/v1/images/generations",{prompt:e,n:this.config.n,size:this.config.size,response_format:"b64_json"},{timeout:3e5,headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(this.openai._apiKey)}})];case 1:return[2,t.sent().data]}}))}))},e}();t.OpenAIImagesGeneration=o},616:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.OpenAI=void 0;var o=n(203),i=n(919),a=n(725),u=r(n(167)),s=function(){function e(e){void 0===e&&(e=""),this._axios=u.default.create(),this._apiKey="",this._apiKey=e}return e.prototype.setAxios=function(e){this._axios=e},e.prototype.setConfiguration=function(e){this._apiKey=e},e.prototype.createChat=function(){return new o.OpenAIChat(this)},e.prototype.createCompletion=function(){return new i.OpenAICompletion(this)},e.prototype.createImagesGeneration=function(){return new a.OpenAIImagesGeneration(this)},e}();t.OpenAI=s},298:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.requireJsonResponseWithHandlebars=t.requireJsonResponse=void 0;var a=i(n(97)),u=n(470);t.requireJsonResponse=function(e,t){return o(o([],r(Array.isArray(e)?e:[e]),!1),["Please respond using the following JSON format and minify the JSON without including any explanation: ","{",Object.entries(t).map((function(e){var t=r(e,2),n=t[0],o=t[1];return["/* ".concat(o.desc," */"),'"'.concat(n,'": ').concat(JSON.stringify(o.example))].join("\n")})).join(",\n"),"}"],!1).join("\n")},t.requireJsonResponseWithHandlebars=function(e,n,r){var o=a.default.create();return o.registerHelper("DATA",(function(e){return JSON.stringify(e)})),o.registerHelper("ENV",(function(e){return this.__envs&&e?this.__envs[e]:""})),o.registerHelper("INPUT",(function(){return JSON.stringify(u.record.omit(this,["__envs"]))})),o.registerHelper("JOIN",(function(e){return Array.isArray(e)?e.join():JSON.stringify(e)})),o.compile((0,t.requireJsonResponse)(n,r))(e)}},293:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.validate=t.definedValidateSchema=void 0;var a=i(n(609));t.definedValidateSchema=function(e){return e},t.validate=function(e,t){return a.object(t(a)).required().validateSync(e||{})}},167:e=>{e.exports=require("axios")},97:e=>{e.exports=require("handlebars")},959:e=>{e.exports=require("json5")},470:e=>{e.exports=require("power-helper")},609:e=>{e.exports=require("yup")}},t={};return function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(620)})()));
@@ -0,0 +1,70 @@
1
+ import { ChatBroker, OpenAI, templates } from '../lib/index'
2
+
3
+ /**
4
+ * @test npx ts-node ./examples/chat-demo.ts
5
+ */
6
+
7
+ const API_KEY = ''
8
+ const broker = new ChatBroker({
9
+ input: yup => {
10
+ return {
11
+ indexs: yup.array(yup.string()).required(),
12
+ question: yup.string().required()
13
+ }
14
+ },
15
+ output: yup => {
16
+ return {
17
+ indexs: yup.array(yup.object({
18
+ name: yup.string().required(),
19
+ score: yup.number().required()
20
+ })).required()
21
+ }
22
+ },
23
+ install: () => null,
24
+ request: async(messages) => {
25
+ const openai = new OpenAI(API_KEY)
26
+ const chat = openai.createChat()
27
+ const { text } = await chat.talk(messages)
28
+ return text
29
+ },
30
+ question: async({ indexs, question }) => {
31
+ return templates.requireJsonResponse([
32
+ '我有以下索引',
33
+ `${JSON.stringify(indexs)}`,
34
+ `請幫我解析"${question}"可能是哪個索引`,
35
+ '且相關性由高到低排序並給予分數,分數由 0 ~ 1'
36
+ ], {
37
+ indexs: {
38
+ desc: '由高到低排序的索引',
39
+ example: [
40
+ {
41
+ name: '索引名稱',
42
+ score: '評比分數,數字顯示'
43
+ }
44
+ ]
45
+ }
46
+ })
47
+ }
48
+ })
49
+
50
+ broker.request({
51
+ indexs: ['胃痛', '腰痛', '頭痛', '喉嚨痛', '四肢疼痛'],
52
+ question: '喝咖啡,吃甜食,胃食道逆流'
53
+ }).then(e => {
54
+ console.log('輸出結果:', e.indexs)
55
+ /*
56
+ [
57
+ {
58
+ name: '胃痛',
59
+ score: 1
60
+ },
61
+ {
62
+ name: '喉嚨痛',
63
+ score: 0.7
64
+ },
65
+ ...
66
+ ]
67
+ */
68
+ }).catch(error => {
69
+ console.error('Error:', error?.response?.data?.error?.message ?? error)
70
+ })