02548d9d by RSA

WIP

1 parent 7ac4ddf0
...@@ -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,6 +47,8 @@ function App() { ...@@ -47,6 +47,8 @@ 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");
50 52
51 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", { 53 const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
52 method: "POST", 54 method: "POST",
...@@ -59,11 +61,39 @@ function App() { ...@@ -59,11 +61,39 @@ function App() {
59 }) 61 })
60 }); 62 });
61 const data = await response.json(); 63 const data = await response.json();
64
65 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
62 setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ]) 74 setChatLog([...chatLogNew, { user: "gpt", message: `${data.message}`} ])
63 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0]; 75 var scrollToTheBottomChatLog = document.getElementsByClassName("chat-log")[0];
64 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight; 76 scrollToTheBottomChatLog.scrollTop = scrollToTheBottomChatLog.scrollHeight;
65 } 77 }
66 78
79
80 let i = 0;
81 const delay = 100;
82 const chat_container = document.getElementsByClassName("chat-log");
83 const typeText = (element, text)=>{
84 let index = 0
85 let interval = setTimeout(()=>{
86 if (i <= text.length){
87 element.innerHTML = text.substring(0, i);
88
89 setTimeout(typeText(element, text), delay);
90 i++
91 }
92 },30)
93 chat_container.scrollTop = chat_container.clientHeight * 100;
94 }
95
96
67 function handleTemp(temp) { 97 function handleTemp(temp) {
68 if(temp > 1){ 98 if(temp > 1){
69 setTemperature(1) 99 setTemperature(1)
......
...@@ -5,7 +5,7 @@ const cors = require('cors') ...@@ -5,7 +5,7 @@ const cors = require('cors')
5 require('dotenv').config() 5 require('dotenv').config()
6 6
7 // Open AI Configuration 7 // Open AI Configuration
8 console.log(process.env.OPENAI_API_ORG) 8 // console.log(process.env.OPENAI_API_ORG)
9 const configuration = new Configuration({ 9 const configuration = new Configuration({
10 organization: process.env.OPENAI_API_ORG, 10 organization: process.env.OPENAI_API_ORG,
11 apiKey: process.env.OPENAI_API_KEY, 11 apiKey: process.env.OPENAI_API_KEY,
...@@ -32,6 +32,20 @@ app.post('/api', async (req, res) => { ...@@ -32,6 +32,20 @@ app.post('/api', async (req, res) => {
32 max_tokens: 2500, 32 max_tokens: 2500,
33 temperature, 33 temperature,
34 }); 34 });
35
36 // let messagess = response.data.choices[0].text
37
38 // let arr_msg1 = messagess.split('<code>')
39 // for (let i = 0; i < arr_msg1.length; i++) {
40 // messagess = messagess.replace('<code>','<pre class="cdeblk"><code>').replace(': ```',': <pre class="cdeblk"><code>').replace('```','</code></pre>')
41 // }
42
43 // let arr_msg2 = messagess.split('</code>')
44 // for (let i = 0; i < arr_msg2.length; i++) {
45 // messagess = messagess.replace('</code>','</code></pre>')
46 // }
47
48
35 res.json({ 49 res.json({
36 message: response.data.choices[0].text, 50 message: response.data.choices[0].text,
37 }) 51 })
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!