aotrautils-srv 0.0.1028 → 0.0.1030

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (25/06/2024-03:01:31)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (02/09/2024-03:11:36)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5185,7 +5185,7 @@ JSON.recycle=function recycle($){
5185
5185
 
5186
5186
 
5187
5187
 
5188
-
5188
+ // CAUTION : TODO : FIXME WILL ERROR IF THERE IS A NON-ESCAPED SINGLE QUOTE ("'") IN RAW STRING !!!
5189
5189
  // JSON parsing management :
5190
5190
  window.parseJSON=function(strParam){
5191
5191
 
@@ -5251,13 +5251,57 @@ window.stringifyObject=function(objectToStringify){
5251
5251
 
5252
5252
 
5253
5253
 
5254
+ // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
5255
+
5256
+ AOTRAUTILS_LIB_IS_LOADED=true;
5257
+
5258
+
5259
+
5260
+
5261
+
5262
+ /*utils AI library associated with aotra version : «1_29072022-2359 (02/09/2024-03:11:36)»*/
5263
+ /*-----------------------------------------------------------------------------*/
5264
+
5265
+
5266
+ /* ## Utility AI methods in a javascript, console (nodejs) server, or vanilla javascript with no browser environment.
5267
+ *
5268
+ * This set of methods gathers utility generic-purpose methods usable in any JS project.
5269
+ * Several authors of snippets published freely on the Internet contributed to this library.
5270
+ * Feel free to use/modify-enhance/publish them under the terms of its license.
5271
+ *
5272
+ * # Library name : «aotrautils»
5273
+ * # Library license : HGPL(Help Burma) (see aotra README information for details : https://alqemia.com/aotra.js )
5274
+ * # Author name : Jérémie Ratomposon (massively helped by his native country free education system)
5275
+ * # Author email : info@alqemia.com
5276
+ * # Organization name : Alqemia
5277
+ * # Organization email : admin@alqemia.com
5278
+ * # Organization website : https://alqemia.com
5279
+ *
5280
+ *
5281
+ */
5282
+
5283
+
5284
+
5285
+ // COMPATIBILITY browser javascript / nodejs environment :
5286
+ if(typeof(window)==="undefined") window=global;
5287
+
5288
+
5289
+
5290
+ //=========================================================================
5291
+ // GLOBAL CONSTANTS :
5292
+
5293
+ //=========================================================================
5294
+
5295
+
5296
+
5297
+
5254
5298
  // AI management :
5255
5299
 
5256
5300
 
5257
5301
 
5258
5302
  class OpenAIAPIClient{
5259
5303
 
5260
- constructor(modelName, apiURL, agentRole, prompt){
5304
+ constructor(modelName, apiURL, agentRole, defaultPrompt){
5261
5305
 
5262
5306
  //DBG
5263
5307
  lognow(">>>>>>>>>>>>>>>>!!!!!!apiURL:",apiURL);
@@ -5266,15 +5310,23 @@ class OpenAIAPIClient{
5266
5310
  this.modelName=modelName;
5267
5311
  this.apiURL=apiURL;
5268
5312
  this.agentRole=agentRole;
5269
- this.prompt=prompt;
5313
+ this.defaultPrompt=defaultPrompt;
5270
5314
  }
5271
5315
 
5272
- async getAnswer(AIAPIKey, additionalPrompt){
5316
+ async getAnswer(AIAPIKey, additionalPrompt, defaultPromptParameters={}){
5317
+
5318
+ const PARAMETERS_DELIMITERS=["<",">"];
5319
+
5320
+ let newDefaultPrompt=this.defaultPrompt;
5321
+ foreach(defaultPromptParameters, (value,key)=>{
5322
+ const regexp=new RegExp(PARAMETERS_DELIMITERS[0]+key+newDefaultPrompt[1] ,"gim");
5323
+ newDefaultPrompt=newDefaultPrompt.replace(regexp,value);
5324
+ });
5273
5325
 
5274
5326
  const self=this;
5275
5327
  const messages = [
5276
5328
  { role: "system", content: this.agentRole },
5277
- { role: "user", content: (this.prompt + additionalPrompt) },
5329
+ { role: "user", content: (newDefaultPrompt+ "\n" + additionalPrompt) },
5278
5330
  ];
5279
5331
 
5280
5332
  //DBG
@@ -5343,23 +5395,15 @@ class OpenAIAPIClient{
5343
5395
 
5344
5396
 
5345
5397
  // Nodejs compatibility :
5346
- getOpenAIAPIClient=(modelName, apiURL, agentRole, prompt)=>{
5347
- return new OpenAIAPIClient(modelName, apiURL, agentRole, prompt);
5398
+ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
5399
+ return new OpenAIAPIClient(modelName, apiURL, agentRole, defaultPrompt);
5348
5400
  };
5349
5401
 
5350
5402
 
5351
5403
 
5352
5404
 
5353
5405
 
5354
- // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
5355
-
5356
- AOTRAUTILS_LIB_IS_LOADED=true;
5357
-
5358
-
5359
-
5360
-
5361
-
5362
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (25/06/2024-03:01:31)»*/
5406
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (02/09/2024-03:11:36)»*/
5363
5407
  /*-----------------------------------------------------------------------------*/
5364
5408
 
5365
5409
 
@@ -7083,8 +7127,8 @@ getListManager=function(config){
7083
7127
  };
7084
7128
 
7085
7129
 
7086
-
7087
- // NO : IN A NODE CONTEXT WITH requre("") WILL RESULT IN AN UNDEFINED FUNCTION ERROR !!!
7130
+ // CAUTION ! TODO : FIXME : We replace in response all single quotes with "`" (egrave) in order to avoid errors !
7131
+ // NO : IN A NODE CONTEXT WITH require("...") WILL RESULT IN AN UNDEFINED FUNCTION ERROR !!!
7088
7132
  // function performHTTPRequest(...){...
7089
7133
  // USE THIS INSTEAD :
7090
7134
  performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyOrNamedArgs=null,isNodeContext=false,addCORSHeader=ADD_CORS_HEADER){
@@ -7186,7 +7230,15 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
7186
7230
  response.on("end", () => {
7187
7231
 
7188
7232
  try{
7189
- const responseData=parseJSON(responseDataStr);
7233
+ let responseData;
7234
+ try{
7235
+ responseData=parseJSON(responseDataStr);
7236
+ }catch(error){
7237
+ // CAUTION ! TODO : FIXME : We replace in response all single quotes with "`" (egrave) in order to avoid errors !
7238
+ // DEBUG
7239
+ responseDataStr=responseDataStr.replace(/'/gim,"`");
7240
+ responseData=parseJSON(responseDataStr);
7241
+ }
7190
7242
  resolve( {responseData:responseData, response:response, responseDataStr:responseDataStr} );
7191
7243
  }catch(error){
7192
7244
  // DBG
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.1028",
3
+ "version": "0.0.1030",
4
4
  "main": "aotrautils-srv.build.js",
5
5
  "description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",