ctod 0.1.4 → 0.2.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.
package/README-TW.md CHANGED
@@ -49,6 +49,8 @@ yarn add ctod
49
49
 
50
50
  > 關於型態定義,這裡有個有趣的議題,必須將 input 與 output 優先宣告才能讓型態正常運作。
51
51
 
52
+ > ChatGPT4 的用法與 ChatGPT35 完全一致。
53
+
52
54
  ```ts
53
55
  import { ChatGPT35Broker, templates } from 'ctod'
54
56
 
@@ -209,6 +211,15 @@ const broker = new ChatGPT35Broker({
209
211
 
210
212
  ## Version History
211
213
 
214
+ ### 0.2.0
215
+
216
+ * Add ChatGPT 4
217
+
218
+ ### 0.1.3
219
+
220
+ * 移除: max_token
221
+ * 新增: model add 16k
222
+
212
223
  ### 0.1.x
213
224
 
214
225
  我們對 plugin 做了比較大的異動,主要是為了能夠實行資料交換。
@@ -232,8 +243,3 @@ const broker = new ChatGPT35Broker({
232
243
  ##### change: assembly => question
233
244
 
234
245
  為了讓使用者更容易理解,我們將 assembly 改名為 question。
235
-
236
- ### 0.1.3
237
-
238
- * 移除: max_token
239
- * 新增: model add 16k
package/README.md CHANGED
@@ -49,6 +49,8 @@ This example demonstrates how to pass drug indices and customer requirements to
49
49
 
50
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.
51
51
 
52
+ > The usage of ChatGPT4 is exactly the same as ChatGPT35.
53
+
52
54
  ```ts
53
55
  import { ChatGPT35Broker, templates } from 'ctod'
54
56
 
@@ -211,6 +213,15 @@ Here are some application examples that you can refer to when designing your AI
211
213
 
212
214
  ## Version History
213
215
 
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
+
214
225
  ### 0.1.x
215
226
 
216
227
  We made significant changes to the plugin to facilitate data exchange.
@@ -234,8 +245,3 @@ Modified the binding behavior. Now, the binding of the Broker takes priority ove
234
245
  ##### change: assembly => question
235
246
 
236
247
  To make it easier for users to understand, we renamed "assembly" to "question".
237
-
238
- ### 0.1.3
239
-
240
- * Remove: max_token
241
- * Add: model add 16k
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,p,h,d=this;return a(this,(function(a){switch(a.label){case 0:if(s>=10)return[2,c()];for(p 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(p);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(h=a.sent()).isParserError?[4,this.hook.notify("parseFailed",{id:e,error:h.error,count:s,response:o,parserFails:h.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(),h;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),p=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,p,h=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(p in o=d.sent(),l=[{role:"user",content:o.prompt}],f=function(t){r[t]={send:function(n){return h.plugins[t].send({id:e,data:n})}}},this.plugins)f(p);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(h,void 0,void 0,(function(){var r,i,s,c,f,p;return a(this,(function(a){switch(a.label){case 0:if(o>=10)return[2,u()];r=null,i="",s=!1,c=(null===(p=l.filter((function(t){return"user"===t.role})).slice(-1)[0])||void 0===p?void 0:p.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(r.text)];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=p},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.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},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,p,h;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(),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)(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.Broker35Plugin=e.Broker3Plugin=e.ChatGPT35Broker=e.ChatGPT3Broker=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),p=n(655),h=n(336),d=n(215),y=n(283);e.TextParser=l.TextParser,e.Translator=c.Translator,e.ChatGPT3=f.ChatGPT3,e.ChatGPT35=p.ChatGPT35,e.ChatGPT3Broker=h.ChatGPT3Broker,e.ChatGPT35Broker=d.ChatGPT35Broker,e.Broker3Plugin=a.Broker3Plugin,e.Broker35Plugin=a.Broker35Plugin,e.ImagesGenerations=y.ImagesGenerations,e.plugins=u,e.templates=s,e.ctod={plugins:e.plugins,templates:e.templates,ChatGPT3:e.ChatGPT3,ChatGPT35:e.ChatGPT35,Translator:e.Translator,TextParser:e.TextParser,Broker3Plugin:e.Broker3Plugin,Broker35Plugin:e.Broker35Plugin,ChatGPT3Broker:e.ChatGPT3Broker,ChatGPT35Broker:e.ChatGPT35Broker,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())}))}))]}))}))}))}})}},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]}))}))}))}})}},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]}))}))}))}})}},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]}))}))}))}})}},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},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(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)})()));
@@ -7,7 +7,7 @@ import { definedOutputDir, getKey } from '../utils'
7
7
  import { ChatGPT35Broker, plugins, templates } from '../../lib/index'
8
8
 
9
9
  /**
10
- * @invoke npx ts-node ./examples/applications/bcc-news-reader.ts
10
+ * @invoke npx ts-node ./examples/applications/bbc-news-reader.ts
11
11
  */
12
12
 
13
13
  const genImage = async (params: {
@@ -1,13 +1,13 @@
1
1
  import { flow } from 'power-helper'
2
2
  import { getKey } from '../utils'
3
3
  import { prompt } from 'inquirer'
4
- import { ChatGPT35Broker, plugins, Broker35Plugin, templates } from '../../lib/index'
4
+ import { ChatGPT4Broker, plugins, Broker4Plugin, templates } from '../../lib/index'
5
5
 
6
6
  /**
7
7
  * @invoke npx ts-node ./examples/applications/cosplay.ts
8
8
  */
9
9
 
10
- const characterPlugin = new Broker35Plugin({
10
+ const characterPlugin = new Broker4Plugin({
11
11
  name: 'character',
12
12
  params: () => {
13
13
  return {}
@@ -57,7 +57,7 @@ flow.run(async () => {
57
57
  }
58
58
  ])
59
59
  const apiKey = await getKey()
60
- const broker = new ChatGPT35Broker({
60
+ const broker = new ChatGPT4Broker({
61
61
  input: yup => {
62
62
  return {
63
63
  action: yup.string().required(),
@@ -76,6 +76,9 @@ flow.run(async () => {
76
76
  character: characterPlugin.use({})
77
77
  },
78
78
  install: ({ bot, attach }) => {
79
+ bot.setConfig({
80
+ model: 'gpt-4-32k'
81
+ })
79
82
  bot.setConfiguration(apiKey)
80
83
  attach('talkFirst', async({ data, plugins }) => {
81
84
  plugins.character.send({
@@ -1,7 +1,7 @@
1
1
  import { flow, array } from 'power-helper'
2
2
  import { ImagesGenerations } from '../../lib/service/images-generations'
3
3
  import { definedOutputDir, getKey } from '../utils'
4
- import { ChatGPT35Broker, plugins, templates } from '../../lib/index'
4
+ import { ChatGPT4Broker, plugins, templates } from '../../lib/index'
5
5
 
6
6
  /**
7
7
  * @invoke npx ts-node ./examples/applications/story-generations.ts
@@ -31,7 +31,7 @@ const genStory = async (params: {
31
31
  style: string
32
32
  ending: string
33
33
  }) => {
34
- const broker = new ChatGPT35Broker({
34
+ const broker = new ChatGPT4Broker({
35
35
  input: yup => {
36
36
  return {
37
37
  ending: yup.string().required(),
package/lib/broker/3.ts CHANGED
@@ -10,7 +10,7 @@ export class ChatGPT3Broker<
10
10
  O extends ValidateCallback<any>,
11
11
  P extends Broker3Plugin<any, any>,
12
12
  PS extends Record<string, ReturnType<P['use']>>
13
- > extends BaseBroker<S, O, P, PS, {
13
+ > extends BaseBroker<ChatGPT3, S, O, P, PS, {
14
14
 
15
15
  /**
16
16
  * @zh 發送聊天訊息給機器人前觸發
package/lib/broker/35.ts CHANGED
@@ -10,7 +10,7 @@ export class ChatGPT35Broker<
10
10
  O extends ValidateCallback<any>,
11
11
  P extends Broker35Plugin<any, any>,
12
12
  PS extends Record<string, ReturnType<P['use']>>
13
- > extends BaseBroker<S, O, P, PS, {
13
+ > extends BaseBroker<ChatGPT35, S, O, P, PS, {
14
14
 
15
15
  /**
16
16
  * @zh 第一次聊天的時候觸發
@@ -167,7 +167,7 @@ export class ChatGPT35Broker<
167
167
  }
168
168
  })
169
169
  messages = response.newMessages
170
- output = (await this.translator.parse(response.text)).output
170
+ output = (await this.translator.parse(parseText)).output
171
171
  await this.hook.notify('succeeded', {
172
172
  id,
173
173
  output
@@ -0,0 +1,207 @@
1
+ import { flow } from 'power-helper'
2
+ import { BaseBroker } from './index'
3
+ import { Translator } from '../core/translator'
4
+ import { Broker4Plugin } from '../core/plugin'
5
+ import { ValidateCallback, ValidateCallbackOutputs } from '../utils/validate'
6
+ import { ChatGPT4, ChatGPT4Message, ChatGPT4TalkResponse } from '../service/chatgpt4'
7
+
8
+ export class ChatGPT4Broker<
9
+ S extends ValidateCallback<any>,
10
+ O extends ValidateCallback<any>,
11
+ P extends Broker4Plugin<any, any>,
12
+ PS extends Record<string, ReturnType<P['use']>>
13
+ > extends BaseBroker<ChatGPT4, S, O, P, PS, {
14
+
15
+ /**
16
+ * @zh 第一次聊天的時候觸發
17
+ * @en Triggered when chatting for the first time
18
+ */
19
+
20
+ talkFirst: {
21
+ id: string
22
+ data: ValidateCallbackOutputs<S>
23
+ plugins: {
24
+ [K in keyof PS]: {
25
+ send: (data: PS[K]['__receiveData']) => void
26
+ }
27
+ }
28
+ messages: ChatGPT4Message[]
29
+ setPreMessages: (messages: ChatGPT4Message[]) => void
30
+ changeMessages: (messages: ChatGPT4Message[]) => void
31
+ }
32
+
33
+ /**
34
+ * @zh 發送聊天訊息給機器人前觸發
35
+ * @en Triggered before sending chat message to bot
36
+ */
37
+
38
+ talkBefore: {
39
+ id: string
40
+ data: ValidateCallbackOutputs<S>
41
+ messages: ChatGPT4Message[]
42
+ lastUserMessage: string
43
+ }
44
+
45
+ /**
46
+ * @zh 當聊天機器人回傳資料的時候觸發
47
+ * @en Triggered when the chatbot returns data
48
+ */
49
+
50
+ talkAfter: {
51
+ id: string
52
+ data: ValidateCallbackOutputs<S>
53
+ response: ChatGPT4TalkResponse
54
+ messages: ChatGPT4Message[]
55
+ parseText: string
56
+ lastUserMessage: string
57
+ changeParseText: (text: string) => void
58
+ }
59
+
60
+ /**
61
+ * @zh 當回傳資料符合規格時觸發
62
+ * @en Triggered when the returned data meets the specifications
63
+ */
64
+
65
+ succeeded: {
66
+ id: string
67
+ output: ValidateCallbackOutputs<O>
68
+ }
69
+
70
+ /**
71
+ * @zh 當回傳資料不符合規格,或是解析錯誤時觸發
72
+ * @en Triggered when the returned data does not meet the specifications or parsing errors
73
+ */
74
+
75
+ parseFailed: {
76
+ id: string
77
+ error: any
78
+ retry: () => void
79
+ count: number
80
+ response: ChatGPT4TalkResponse
81
+ parserFails: { name: string, error: any }[]
82
+ messages: ChatGPT4Message[]
83
+ lastUserMessage: string
84
+ changeMessages: (messages: ChatGPT4Message[]) => void
85
+ }
86
+
87
+ /**
88
+ * @zh 不論成功失敗,執行結束的時候會執行。
89
+ * @en It will be executed when the execution is completed, regardless of success or failure.
90
+ */
91
+
92
+ done: {
93
+ id: string
94
+ }
95
+ }> {
96
+ bot: ChatGPT4 = new ChatGPT4()
97
+
98
+ /**
99
+ * @zh 將請求發出至聊天機器人。
100
+ * @en Send request to chatbot.
101
+ */
102
+
103
+ async request<T extends Translator<S, O>>(data: T['__schemeType']): Promise<T['__outputType']> {
104
+ this._install()
105
+ let id = flow.createUuid()
106
+ let output: any = null
107
+ let plugins = {} as any
108
+ let question = await this.translator.compile(data)
109
+ let messages: ChatGPT4Message[] = [
110
+ {
111
+ role: 'user',
112
+ content: question.prompt
113
+ }
114
+ ]
115
+ for (let key in this.plugins) {
116
+ plugins[key] = {
117
+ send: (data: any) => this.plugins[key].send({
118
+ id,
119
+ data
120
+ })
121
+ }
122
+ }
123
+ await this.hook.notify('talkFirst', {
124
+ id,
125
+ data,
126
+ plugins,
127
+ messages,
128
+ setPreMessages: ms => {
129
+ messages = [
130
+ ...ms,
131
+ {
132
+ role: 'user',
133
+ content: question.prompt
134
+ }
135
+ ]
136
+ },
137
+ changeMessages: ms => {
138
+ messages = ms
139
+ }
140
+ })
141
+ await flow.asyncWhile(async ({ count, doBreak }) => {
142
+ if (count >= 10) {
143
+ return doBreak()
144
+ }
145
+ let response: ChatGPT4TalkResponse = null as any
146
+ let parseText = ''
147
+ let retryFlag = false
148
+ let lastUserMessage = messages.filter(e => e.role === 'user').slice(-1)[0]?.content || ''
149
+ try {
150
+ await this.hook.notify('talkBefore', {
151
+ id,
152
+ data,
153
+ messages,
154
+ lastUserMessage
155
+ })
156
+ response = await this.bot.talk(messages)
157
+ parseText = response.text
158
+ await this.hook.notify('talkAfter', {
159
+ id,
160
+ data,
161
+ response,
162
+ parseText,
163
+ messages: response.newMessages,
164
+ lastUserMessage,
165
+ changeParseText: text => {
166
+ parseText = text
167
+ }
168
+ })
169
+ messages = response.newMessages
170
+ output = (await this.translator.parse(parseText)).output
171
+ await this.hook.notify('succeeded', {
172
+ id,
173
+ output
174
+ })
175
+ await this.hook.notify('done', { id })
176
+ doBreak()
177
+ } catch (error: any) {
178
+ // 如果解析錯誤,可以選擇是否重新解讀
179
+ if (error.isParserError) {
180
+ await this.hook.notify('parseFailed', {
181
+ id,
182
+ error: error.error,
183
+ count,
184
+ response,
185
+ messages,
186
+ lastUserMessage,
187
+ parserFails: error.parserFails,
188
+ retry: () => {
189
+ retryFlag = true
190
+ },
191
+ changeMessages: ms => {
192
+ messages = ms
193
+ }
194
+ })
195
+ if (retryFlag === false) {
196
+ await this.hook.notify('done', { id })
197
+ throw error
198
+ }
199
+ } else {
200
+ await this.hook.notify('done', { id })
201
+ throw error
202
+ }
203
+ }
204
+ })
205
+ return output
206
+ }
207
+ }