8533480c by RSA

WIP

1 parent 02548d9d
...@@ -29,7 +29,7 @@ function App() { ...@@ -29,7 +29,7 @@ function App() {
29 fetch(process.env.REACT_APP_SERVER_URL + "/models") 29 fetch(process.env.REACT_APP_SERVER_URL + "/models")
30 .then(res => res.json()) 30 .then(res => res.json())
31 .then(data => { 31 .then(data => {
32 // console.log(data.models.data) 32 console.log(data.models.data)
33 // set models in order alpahbetically 33 // set models in order alpahbetically
34 data.models.data.sort((a, b) => { 34 data.models.data.sort((a, b) => {
35 if(a.id < b.id) { return -1; } 35 if(a.id < b.id) { return -1; }
...@@ -47,13 +47,12 @@ function App() { ...@@ -47,13 +47,12 @@ function App() {
47 setChatLog(chatLogNew) 47 setChatLog(chatLogNew)
48 // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post 48 // fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post
49 const messages = chatLogNew.map((message) => message.message).join("\n") 49 const messages = chatLogNew.map((message) => message.message).join("\n")
50 console.log(chatLogNew[0])
51 const messageDiv = document.getElementsByClassName("message");
52 50
53 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 51 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
54 method: "POST", 52 method: "POST",
55 headers: { 53 headers: {
56 "Content-Type": "application/json" 54 "Content-Type": "application/json",
55 "Accept":"application/json"
57 }, 56 },
58 body: JSON.stringify({ 57 body: JSON.stringify({
59 message: messages, 58 message: messages,
...@@ -63,36 +62,72 @@ function App() { ...@@ -63,36 +62,72 @@ function App() {
63 const data = await response.json(); 62 const data = await response.json();
64 63
65 const parsedData = data.message.trim(); 64 const parsedData = data.message.trim();
66 console.log("-----------")
67 console.log(data)
68 console.log("===========")
69 console.log(parsedData)
70
71 typeText(messageDiv,parsedData);
72 i = 0;
73 65
74 setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ]) 66 setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ])
75 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; 67 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
76 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; 68 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
77 }
78 69
79 70
80 let i = 0; 71 // var oHttp = new XMLHttpRequest();
81 const delay = 100; 72 // oHttp.open("POST", "https://api.openai.com/v1/completions");
82 const chat_container = document.getElementsByClassName("chat-log"); 73 // oHttp.setRequestHeader("Accept", "application/json");
83 const typeText = (element, text)=>{ 74 // oHttp.setRequestHeader("Content-Type", "application/json");
84 let index = 0 75 // oHttp.setRequestHeader("Authorization", "Bearer " + "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")
85 let interval = setTimeout(()=>{ 76
86 if (i <= text.length){ 77 // oHttp.onreadystatechange = function () {
87 element.innerHTML = text.substring(0, i); 78 // if (oHttp.readyState === 4) {
88 79 // var s = ''
89 setTimeout(typeText(element, text), delay); 80 // var oJson = {}
90 i++ 81 // if (s != "") s += "\n";
91 } 82 // try {
92 },30) 83 // oJson = JSON.parse(oHttp.responseText);
93 chat_container.scrollTop = chat_container.clientHeight * 100; 84 // } catch (ex) {
94 } 85 // s += "Error: " + ex.message
86 // }
87 // if (oJson.error && oJson.error.message) {
88 // s += "Error: " + oJson.error.message;
89 // } else if (oJson.choices && oJson.choices[0].text) {
90 // s = oJson.choices[0].text;
91 // var a = s.split("?\n");
92 // if (a.length == 2) {
93 // s = a[1];
94 // }
95 // // if (selLang.value != "en-US") {
96 // // var a = s.split("?\n");
97 // // if (a.length == 2) {
98 // // s = a[1];
99 // // }
100 // // }
101 // if (s == "") s = "No response";
102 // console.log('ssssssssssssssssssssss',s);
103 // var replaceBR= (s.replace(/(?:\r\n|\r|\n)/g, "<br>")).replace(/\r?\n|\r/, "");
104
105 // setChatLog([...chatLogNew, { user: "gpt", message: `${replaceBR}`} ]);
106 // }
107 // }
108 // };
109
110 // var sModel = currentModel;// "text-davinci-003";
111 // var iMaxTokens = 100;
112 // var sUserId = "1";
113 // var dTemperature =temperature;
114
115 // var data = {
116 // model: sModel,
117 // prompt: messages,
118 // max_tokens: iMaxTokens,
119 // //user: sUserId,
120 // temperature: dTemperature,
121 // // frequency_penalty: 0.0, //Number between -2.0 and 2.0 Positive value decrease the model's likelihood to repeat the same line verbatim.
122 // //presence_penalty: 0.0, //Number between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics.
123 // //stop: ["#", ";"] //Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
124 // }
125 var oHttp = new XMLHttpRequest();
126 oHttp.open("POST", "/your-endpoint", true);
127 oHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
128 oHttp.send(JSON.stringify(data));
95 129
130 }
96 131
97 function handleTemp(temp) { 132 function handleTemp(temp) {
98 if(temp > 1){ 133 if(temp > 1){
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!