Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Administrator
/
chatgpt.ai-pro.org
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
3
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
7fd3de54
authored
2023-03-02 14:14:20 +0800
by
RSA
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
fix conflict
2 parents
3e99a7b9
376c7f7c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
5 deletions
client/src/App.js
client/src/App.js
View file @
7fd3de5
...
...
@@ -20,7 +20,6 @@ function App() {
message
:
"Welcome to AI-PRO... How can I help you?"
}]);
// clear chats
function
clearChat
(){
setChatLog
([]);
setChatInput
(
""
);
...
...
@@ -31,8 +30,6 @@ function App() {
fetch
(
process
.
env
.
REACT_APP_SERVER_URL
+
"/models"
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
// console.log(data.models.data)
// set models in order alpahbetically
data
.
models
.
data
.
sort
((
a
,
b
)
=>
{
if
(
a
.
id
<
b
.
id
)
{
return
-
1
;
}
if
(
a
.
id
>
b
.
id
)
{
return
1
;
}
...
...
@@ -66,8 +63,11 @@ function App() {
setChatInput
(
""
);
setChatLog
(
chatLogNew
)
// fetch response to the api combining the chat log array of messages and seinding it as a message to localhost:3000 as a post
const
userMessage
=
{
user
:
"gpt"
,
message
:
"..."
};
setChatLog
(
prevChatLog
=>
[...
prevChatLog
,
userMessage
]);
const
messages
=
chatLogNew
.
map
((
message
)
=>
message
.
message
).
join
(
"\n"
)
let
intervalId
=
startInterval
();
try
{
const
response
=
await
fetch
(
process
.
env
.
REACT_APP_SERVER_URL
+
"/api"
,
{
...
...
@@ -83,6 +83,7 @@ function App() {
const
data
=
await
response
.
json
();
const
parsedData
=
data
.
message
.
trim
();
clearInterval
(
intervalId
);
const
programmingKeywords
=
[
'code'
,
'application'
,
'controller'
,
'rails'
,
'PHP'
,
'java'
,
'javascript'
,
'script'
,
'console'
,
'python'
,
'programming'
,
'table'
];
const
regex
=
new
RegExp
(
`\\b(
${
programmingKeywords
.
join
(
'|'
)}
)\\b`
,
'gi'
);
...
...
@@ -92,15 +93,47 @@ function App() {
}
else
{
replaceTags
=
(
parsedData
.
replace
(
':'
,
':<code>'
).
replace
(
'<?'
,
'<?'
).
replace
(
'?>'
,
'?>'
).
replace
(
/
\n
/g
,
'<br>'
))
}
setChatLog
([...
chatLogNew
,
{
user
:
"gpt"
,
message
:
`
${
replaceTags
}
`
}
])
for
(
let
i
=
0
;
i
<
replaceTags
.
length
;
i
++
)
{
setTimeout
(()
=>
{
const
parsedMsg
=
replaceTags
.
slice
(
0
,
i
+
1
);
updateLastMessage
(
parsedMsg
);
var
scrollToTheBottomChatLog
=
document
.
getElementsByClassName
(
"chat-log"
)[
0
];
scrollToTheBottomChatLog
.
scrollTop
=
scrollToTheBottomChatLog
.
scrollHeight
;
},
i
*
5
);
}
function
updateLastMessage
(
parsedMsg
)
{
setChatLog
(
prevChatLog
=>
{
const
lastMsg
=
prevChatLog
[
prevChatLog
.
length
-
1
];
if
(
lastMsg
&&
lastMsg
.
user
===
"gpt"
)
{
return
[...
prevChatLog
.
slice
(
0
,
prevChatLog
.
length
-
1
),
{
user
:
lastMsg
.
user
,
message
:
parsedMsg
}];
}
else
{
return
[...
prevChatLog
,
{
user
:
"gpt"
,
message
:
parsedMsg
}];
}
});
}
}
catch
(
error
)
{
const
errorMsg
=
"We apologize for any inconvenience caused due to the delay in the response time. Please try again."
;
setChatLog
([...
chatLogNew
,
{
user
:
"gpt"
,
message
:
`<div class="errormsg"><span>i</span><div class="msg">
${
errorMsg
}
</div></div>`
}
])
}
function
startInterval
()
{
return
setInterval
(
function
()
{
if
(
userMessage
.
message
.
length
===
3
)
{
userMessage
.
message
=
"."
;
}
else
if
(
userMessage
.
message
.
length
===
1
)
{
userMessage
.
message
=
".."
;
}
else
{
userMessage
.
message
=
"..."
;
}
var
thinkingDots
=
document
.
getElementsByClassName
(
"message"
);
var
thinkingDot
=
thinkingDots
[
thinkingDots
.
length
-
1
];
thinkingDot
.
innerHTML
=
userMessage
.
message
;
},
500
);
}
}
function
handleTemp
(
temp
)
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment