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
02548d9d
authored
2023-02-03 18:54:01 +0800
by
RSA
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
WIP
1 parent
7ac4ddf0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
client/src/App.js
index.js
client/src/App.js
View file @
02548d9
...
...
@@ -29,7 +29,7 @@ function App() {
fetch
(
process
.
env
.
REACT_APP_SERVER_URL
+
"/models"
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
console
.
log
(
data
.
models
.
data
)
//
console.log(data.models.data)
// set models in order alpahbetically
data
.
models
.
data
.
sort
((
a
,
b
)
=>
{
if
(
a
.
id
<
b
.
id
)
{
return
-
1
;
}
...
...
@@ -47,6 +47,8 @@ function App() {
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"
)
console
.
log
(
chatLogNew
[
0
])
const
messageDiv
=
document
.
getElementsByClassName
(
"message"
);
const
response
=
await
fetch
(
process
.
env
.
REACT_APP_SERVER_URL
+
"/api"
,
{
method
:
"POST"
,
...
...
@@ -59,11 +61,39 @@ function App() {
})
});
const
data
=
await
response
.
json
();
const
parsedData
=
data
.
message
.
trim
();
console
.
log
(
"-----------"
)
console
.
log
(
data
)
console
.
log
(
"==========="
)
console
.
log
(
parsedData
)
typeText
(
messageDiv
,
parsedData
);
i
=
0
;
setChatLog
([...
chatLogNew
,
{
user
:
"gpt"
,
message
:
`
${
data
.
message
}
`
}
])
var
scrollToTheBottomChatLog
=
document
.
getElementsByClassName
(
"chat-log"
)[
0
];
scrollToTheBottomChatLog
.
scrollTop
=
scrollToTheBottomChatLog
.
scrollHeight
;
}
let
i
=
0
;
const
delay
=
100
;
const
chat_container
=
document
.
getElementsByClassName
(
"chat-log"
);
const
typeText
=
(
element
,
text
)
=>
{
let
index
=
0
let
interval
=
setTimeout
(()
=>
{
if
(
i
<=
text
.
length
){
element
.
innerHTML
=
text
.
substring
(
0
,
i
);
setTimeout
(
typeText
(
element
,
text
),
delay
);
i
++
}
},
30
)
chat_container
.
scrollTop
=
chat_container
.
clientHeight
*
100
;
}
function
handleTemp
(
temp
)
{
if
(
temp
>
1
){
setTemperature
(
1
)
...
...
index.js
View file @
02548d9
...
...
@@ -5,7 +5,7 @@ const cors = require('cors')
require
(
'dotenv'
).
config
()
// Open AI Configuration
console
.
log
(
process
.
env
.
OPENAI_API_ORG
)
//
console.log(process.env.OPENAI_API_ORG)
const
configuration
=
new
Configuration
({
organization
:
process
.
env
.
OPENAI_API_ORG
,
apiKey
:
process
.
env
.
OPENAI_API_KEY
,
...
...
@@ -32,6 +32,20 @@ app.post('/api', async (req, res) => {
max_tokens
:
2500
,
temperature
,
});
// let messagess = response.data.choices[0].text
// let arr_msg1 = messagess.split('<code>')
// for (let i = 0; i < arr_msg1.length; i++) {
// messagess = messagess.replace('<code>','<pre class="cdeblk"><code>').replace(': ```',': <pre class="cdeblk"><code>').replace('```','</code></pre>')
// }
// let arr_msg2 = messagess.split('</code>')
// for (let i = 0; i < arr_msg2.length; i++) {
// messagess = messagess.replace('</code>','</code></pre>')
// }
res
.
json
({
message
:
response
.
data
.
choices
[
0
].
text
,
})
...
...
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