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
3cbc5ff7
authored
2023-02-28 10:28:05 +0800
by
RSA
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
WIP
1 parent
94593dd1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
client/src/App.js
client/src/App.js
View file @
3cbc5ff
...
...
@@ -44,7 +44,6 @@ function App() {
async
function
handleSubmit
(
e
){
e
.
preventDefault
();
// console.log(chatInput)
const
userInput
=
[
'what'
,
'why'
,
'when'
,
'where'
,
'which'
,
'did'
,
'do'
,
'how'
,
'can'
,
'are'
,
'who'
];
const
userInputRegex
=
new
RegExp
(
`\\b(
${
userInput
.
join
(
'|'
)}
)\\b`
,
'gi'
);
const
inputMatches
=
chatInput
.
match
(
userInputRegex
);
...
...
@@ -53,25 +52,43 @@ function App() {
const
userPunctuationRegex
=
new
RegExp
(
`[
${
userPunctuation
.
join
(
''
)}
]$`
);
const
punctuationMatches
=
chatInput
.
match
(
userPunctuationRegex
);
// console.log(punctuationMatches)
var
userModifiedInput
=
chatInput
if
(
!
punctuationMatches
)
{
if
(
!
inputMatches
)
{
userModifiedInput
=
chatInput
+
"."
;
// console.log("not a question!")
}
else
{
userModifiedInput
=
chatInput
+
"?"
;
// console.log("its a question!")
}
}
let
chatLogNew
=
[...
chatLog
,
{
user
:
"me"
,
message
:
`
${
userModifiedInput
}
`
}
]
const
messages
=
chatLogNew
.
map
((
message
)
=>
message
.
message
).
join
(
"\n"
)
// Find the table format and replace it with HTML table tags
const
parsedData
=
chatLogNew
.
map
(
message
=>
{
if
(
message
.
message
.
includes
(
"|"
))
{
console
.
log
(
"Have"
)
const
rows
=
message
.
message
.
split
(
"\n"
);
const
headers
=
rows
[
0
].
split
(
"|"
).
filter
(
h
=>
h
);
const
divider
=
headers
.
map
(
h
=>
"-"
.
repeat
(
h
.
length
));
const
data
=
rows
.
slice
(
2
,
rows
.
length
-
1
).
map
(
row
=>
{
const
values
=
row
.
split
(
"|"
).
filter
(
v
=>
v
);
return
values
.
reduce
((
obj
,
value
,
index
)
=>
{
obj
[
headers
[
index
]]
=
value
.
trim
();
return
obj
;
},
{});
});
const
table
=
`<table><thead><tr>
${
headers
.
map
(
h
=>
`<th>
${
h
.
trim
()}
</th>`
).
join
(
""
)}
</tr></thead><tbody>
${
data
.
map
(
row
=>
`<tr>
${
headers
.
map
(
h
=>
`<td>
${
row
[
h
.
trim
()]}
</td>`
).
join
(
""
)}
</tr>`
).
join
(
""
)}
</tbody></table>`
;
return
table
;
}
else
{
return
message
.
message
;
}
}).
join
(
"\n"
);
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
messages
=
chatLogNew
.
map
((
message
)
=>
message
.
message
).
join
(
"\n"
)
try
{
const
response
=
await
fetch
(
process
.
env
.
REACT_APP_SERVER_URL
+
"/api"
,
{
...
...
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