aotrautils-srv 0.0.624 → 0.0.625

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 (30/09/2023-18:45:40)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (02/10/2023-19:46:29)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5047,6 +5047,80 @@ window.stringifyObject=function(objectToStringify){
5047
5047
 
5048
5048
 
5049
5049
 
5050
+
5051
+ // AI management :
5052
+
5053
+
5054
+
5055
+ class OpenAPIClient{
5056
+
5057
+ construct(modelName, apiURL, agentRole, prompt){
5058
+
5059
+ this.modelName=modelName;
5060
+ this.apiURL=apiURL;
5061
+ this.agentRole=agentRole;
5062
+ this.prompt=prompt;
5063
+
5064
+ }
5065
+
5066
+ getAnswer(AIAPIKey, additionalPrompt){
5067
+
5068
+ const self=this;
5069
+ const messages = [
5070
+ { role: "system", content: this.agentRole },
5071
+ { role: "user", content: this.prompt+additionalPrompt },
5072
+ ];
5073
+
5074
+ async function getResult(){
5075
+ const p=new Promise((accept,reject)=>{
5076
+
5077
+ fetch(self.apiURL, {
5078
+ method: "POST",
5079
+ headers: {
5080
+ "Authorization": "Bearer "+self.apiKey,
5081
+ "Content-Type": "application/json",
5082
+ },
5083
+ body: JSON.stringify({
5084
+ model:self.modelName,
5085
+ messages,
5086
+ }),
5087
+ })
5088
+ .then(response => response.json())
5089
+ .then(data => {
5090
+ // DBG
5091
+ // console.log("data :",data);
5092
+ const assistantReply = data.choices[0].message.content;
5093
+ accept(assistantReply);
5094
+ })
5095
+ .catch(error => {
5096
+ // TRACE
5097
+ console.error("Error:", error);
5098
+ reject(""+error);
5099
+ });
5100
+
5101
+ });
5102
+
5103
+ const r=await p;
5104
+
5105
+ // DBG
5106
+ // console.log("! RESULT text :",r);
5107
+
5108
+ return r;
5109
+ }
5110
+
5111
+ return getResult();
5112
+ }
5113
+
5114
+
5115
+ }
5116
+
5117
+
5118
+
5119
+
5120
+
5121
+
5122
+
5123
+
5050
5124
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
5051
5125
 
5052
5126
  AOTRAUTILS_LIB_IS_LOADED=true;
@@ -5054,7 +5128,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5054
5128
 
5055
5129
 
5056
5130
 
5057
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (30/09/2023-18:45:40)»*/
5131
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (02/10/2023-19:46:29)»*/
5058
5132
  /*-----------------------------------------------------------------------------*/
5059
5133
 
5060
5134
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.624",
3
+ "version": "0.0.625",
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)",