aotrautils 0.0.1037 → 0.0.1039

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-02:58:56)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (02/09/2024-03:00:28)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5251,106 +5251,6 @@ window.stringifyObject=function(objectToStringify){
5251
5251
 
5252
5252
 
5253
5253
 
5254
- // AI management :
5255
-
5256
-
5257
-
5258
- class OpenAIAPIClient{
5259
-
5260
- constructor(modelName, apiURL, agentRole, prompt){
5261
-
5262
- //DBG
5263
- lognow(">>>>>>>>>>>>>>>>!!!!!!apiURL:",apiURL);
5264
-
5265
- // this.apiKey=apiKey;
5266
- this.modelName=modelName;
5267
- this.apiURL=apiURL;
5268
- this.agentRole=agentRole;
5269
- this.prompt=prompt;
5270
- }
5271
-
5272
- async getAnswer(AIAPIKey, additionalPrompt){
5273
-
5274
- const self=this;
5275
- const messages = [
5276
- { role: "system", content: this.agentRole },
5277
- { role: "user", content: (this.prompt + additionalPrompt) },
5278
- ];
5279
-
5280
- //DBG
5281
- lognow("------------self.apiURL:",self.apiURL);
5282
-
5283
- const result=await this.launchRequest(AIAPIKey, messages);
5284
-
5285
- // DBG
5286
- console.log("! RESULT text :",result);
5287
-
5288
- return result;
5289
- }
5290
-
5291
-
5292
- /*private*/launchRequest(AIAPIKey, messages){
5293
-
5294
- // DBG
5295
- lognow("! launchRequest messages :",messages);
5296
-
5297
-
5298
- const headers={
5299
- "Authorization": "Bearer "+AIAPIKey,
5300
- "Content-Type": "application/json",
5301
- };
5302
- const parameters={
5303
- model:this.modelName,
5304
- messages:messages,
5305
- };
5306
-
5307
- return new Promise((resolve,reject)=>{
5308
- performHTTPRequest(this.apiURL,"POST",headers,parameters,true).then((responseObj)=>{
5309
- const responseData=responseObj.responseData;
5310
- const data=responseData;
5311
-
5312
- // DBG
5313
- console.log("~~~~~~~~~~~data :",data);
5314
-
5315
- if(data.error){
5316
- const error=data.error;
5317
- // TRACE
5318
- console.error("Error:", error);
5319
- reject(new Error(`${error}`));
5320
- }
5321
-
5322
- const assistantReply = data.choices[0].message.content;
5323
- // DBG
5324
- console.log("~~~~~~~~~~~assistantReply :",assistantReply);
5325
-
5326
- resolve(assistantReply);
5327
- }).catch(error => {
5328
- // TRACE
5329
- console.error("Error:", error);
5330
- reject(error);
5331
- });
5332
- });
5333
-
5334
-
5335
-
5336
-
5337
- }
5338
-
5339
-
5340
-
5341
-
5342
- }
5343
-
5344
-
5345
- // Nodejs compatibility :
5346
- getOpenAIAPIClient=(modelName, apiURL, agentRole, prompt)=>{
5347
- return new OpenAIAPIClient(modelName, apiURL, agentRole, prompt);
5348
- };
5349
-
5350
-
5351
-
5352
-
5353
-
5354
5254
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
5355
5255
 
5356
5256
  AOTRAUTILS_LIB_IS_LOADED=true;
@@ -5359,7 +5259,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5359
5259
 
5360
5260
 
5361
5261
 
5362
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (25/06/2024-02:58:56)»*/
5262
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (02/09/2024-03:00:28)»*/
5363
5263
  /*-----------------------------------------------------------------------------*/
5364
5264
  /* ## Utility global methods in a browser (htmljs) client environment.
5365
5265
  *
@@ -13574,7 +13474,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
13574
13474
 
13575
13475
 
13576
13476
 
13577
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (25/06/2024-02:58:56)»*/
13477
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (02/09/2024-03:00:28)»*/
13578
13478
  /*-----------------------------------------------------------------------------*/
13579
13479
 
13580
13480
 
@@ -14813,7 +14713,151 @@ function rayVsUnitSphereClosestPoint(p, r) {
14813
14713
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14814
14714
 
14815
14715
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14816
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (25/06/2024-02:58:56)»*/
14716
+ /*utils AI library associated with aotra version : «1_29072022-2359 (02/09/2024-03:00:28)»*/
14717
+ /*-----------------------------------------------------------------------------*/
14718
+
14719
+
14720
+ /* ## Utility AI methods in a javascript, console (nodejs) server, or vanilla javascript with no browser environment.
14721
+ *
14722
+ * This set of methods gathers utility generic-purpose methods usable in any JS project.
14723
+ * Several authors of snippets published freely on the Internet contributed to this library.
14724
+ * Feel free to use/modify-enhance/publish them under the terms of its license.
14725
+ *
14726
+ * # Library name : «aotrautils»
14727
+ * # Library license : HGPL(Help Burma) (see aotra README information for details : https://alqemia.com/aotra.js )
14728
+ * # Author name : Jérémie Ratomposon (massively helped by his native country free education system)
14729
+ * # Author email : info@alqemia.com
14730
+ * # Organization name : Alqemia
14731
+ * # Organization email : admin@alqemia.com
14732
+ * # Organization website : https://alqemia.com
14733
+ *
14734
+ *
14735
+ */
14736
+
14737
+
14738
+
14739
+ // COMPATIBILITY browser javascript / nodejs environment :
14740
+ if(typeof(window)==="undefined") window=global;
14741
+
14742
+
14743
+
14744
+ //=========================================================================
14745
+ // GLOBAL CONSTANTS :
14746
+
14747
+ //=========================================================================
14748
+
14749
+
14750
+
14751
+
14752
+ // AI management :
14753
+
14754
+
14755
+
14756
+ class OpenAIAPIClient{
14757
+
14758
+ constructor(modelName, apiURL, agentRole, defaultPrompt){
14759
+
14760
+ //DBG
14761
+ lognow(">>>>>>>>>>>>>>>>!!!!!!apiURL:",apiURL);
14762
+
14763
+ // this.apiKey=apiKey;
14764
+ this.modelName=modelName;
14765
+ this.apiURL=apiURL;
14766
+ this.agentRole=agentRole;
14767
+ this.defaultPrompt=defaultPrompt;
14768
+ }
14769
+
14770
+ async getAnswer(AIAPIKey, additionalPrompt, defaultPromptParameters={}){
14771
+
14772
+ const PARAMETERS_DELIMITERS=["<",">"];
14773
+
14774
+ let newDefaultPrompt=this.defaultPrompt;
14775
+ foreach(defaultPromptParameters, (value,key)=>{
14776
+ const regexp=new RegExp(PARAMETERS_DELIMITERS[0]+key+newDefaultPrompt[1] ,"gim");
14777
+ newDefaultPrompt=newDefaultPrompt.replace(regexp,value);
14778
+ });
14779
+
14780
+ const self=this;
14781
+ const messages = [
14782
+ { role: "system", content: this.agentRole },
14783
+ { role: "user", content: (newDefaultPrompt+ "\n" + additionalPrompt) },
14784
+ ];
14785
+
14786
+ //DBG
14787
+ lognow("------------self.apiURL:",self.apiURL);
14788
+
14789
+ const result=await this.launchRequest(AIAPIKey, messages);
14790
+
14791
+ // DBG
14792
+ console.log("! RESULT text :",result);
14793
+
14794
+ return result;
14795
+ }
14796
+
14797
+
14798
+ /*private*/launchRequest(AIAPIKey, messages){
14799
+
14800
+ // DBG
14801
+ lognow("! launchRequest messages :",messages);
14802
+
14803
+
14804
+ const headers={
14805
+ "Authorization": "Bearer "+AIAPIKey,
14806
+ "Content-Type": "application/json",
14807
+ };
14808
+ const parameters={
14809
+ model:this.modelName,
14810
+ messages:messages,
14811
+ };
14812
+
14813
+ return new Promise((resolve,reject)=>{
14814
+ performHTTPRequest(this.apiURL,"POST",headers,parameters,true).then((responseObj)=>{
14815
+ const responseData=responseObj.responseData;
14816
+ const data=responseData;
14817
+
14818
+ // DBG
14819
+ console.log("~~~~~~~~~~~data :",data);
14820
+
14821
+ if(data.error){
14822
+ const error=data.error;
14823
+ // TRACE
14824
+ console.error("Error:", error);
14825
+ reject(new Error(`${error}`));
14826
+ }
14827
+
14828
+ const assistantReply = data.choices[0].message.content;
14829
+ // DBG
14830
+ console.log("~~~~~~~~~~~assistantReply :",assistantReply);
14831
+
14832
+ resolve(assistantReply);
14833
+ }).catch(error => {
14834
+ // TRACE
14835
+ console.error("Error:", error);
14836
+ reject(error);
14837
+ });
14838
+ });
14839
+
14840
+
14841
+
14842
+
14843
+ }
14844
+
14845
+
14846
+
14847
+
14848
+ }
14849
+
14850
+
14851
+ // Nodejs compatibility :
14852
+ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
14853
+ return new OpenAIAPIClient(modelName, apiURL, agentRole, defaultPrompt);
14854
+ };
14855
+
14856
+
14857
+
14858
+
14859
+
14860
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (02/09/2024-03:00:28)»*/
14817
14861
  /*-----------------------------------------------------------------------------*/
14818
14862
 
14819
14863
 
@@ -16640,6 +16684,10 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
16640
16684
  response.on("end", () => {
16641
16685
 
16642
16686
  try{
16687
+
16688
+ // DEBUG
16689
+ responseDataStr=responseDataStr.replace(/'/gim,"`");
16690
+
16643
16691
  const responseData=parseJSON(responseDataStr);
16644
16692
  resolve( {responseData:responseData, response:response, responseDataStr:responseDataStr} );
16645
16693
  }catch(error){
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1037",
3
+ "version": "0.0.1039",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",