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
b0078561
authored
2023-02-06 21:20:16 +0800
by
RSA
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixes
1 parent
8533480c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
80 deletions
client/src/App.js
client/src/color_theme_1.css
index.js
client/src/App.js
View file @
b007856
...
...
@@ -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
;
}
...
...
@@ -51,8 +51,7 @@ function App() {
const
response
=
await
fetch
(
process
.
env
.
REACT_APP_SERVER_URL
+
"/api"
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
,
"Accept"
:
"application/json"
"Content-Type"
:
"application/json"
},
body
:
JSON
.
stringify
({
message
:
messages
,
...
...
@@ -60,73 +59,29 @@ function App() {
})
});
const
data
=
await
response
.
json
();
const
parsedData
=
data
.
message
.
trim
();
console
.
log
(
parsedData
)
const
programmingKeywords
=
[
'code'
,
'application'
,
'controller'
,
'rails'
,
'PHP'
,
'java'
,
'javascript'
,
'script'
,
'console'
,
'python'
,
'programming'
,
'table'
];
const
regex
=
new
RegExp
(
`\\b(
${
programmingKeywords
.
join
(
'|'
)}
)\\b`
,
'gi'
);
console
.
log
(
regex
)
const
matches
=
parsedData
.
match
(
regex
);
console
.
log
(
matches
);
if
(
!
matches
)
{
var
replaceTags
=
(
parsedData
.
replace
(
/
(?:\r\n
|
\r
|
\n)
/g
,
'<br>'
).
replace
(
/
\.
/g
,
'. '
))
console
.
log
(
"not programming!"
)
// return replaceTags
}
else
{
replaceTags
=
(
parsedData
.
replace
(
':'
,
':<code>'
).
replace
(
'<?'
,
'<?'
).
replace
(
'?>'
,
'?>'
).
replace
(
/
\n
/g
,
'<br>'
))
console
.
log
(
"programming!"
)
// return replaceTags
//.replace('<?','<' + '?').replace('?>','?'+'>')
}
setChatLog
([...
chatLogNew
,
{
user
:
"gpt"
,
message
:
`
${
replaceTags
}
`
}
])
setChatLog
([...
chatLogNew
,
{
user
:
"gpt"
,
message
:
`
${
data
.
message
}
`
}
])
// setChatLog([...chatLogNew, { user: "gpt", message: `<div>${parsedData}</div>
`} ])
var
scrollToTheBottomChatLog
=
document
.
getElementsByClassName
(
"chat-log"
)[
0
];
scrollToTheBottomChatLog
.
scrollTop
=
scrollToTheBottomChatLog
.
scrollHeight
;
// var oHttp = new XMLHttpRequest();
// oHttp.open("POST", "https://api.openai.com/v1/completions");
// oHttp.setRequestHeader("Accept", "application/json");
// oHttp.setRequestHeader("Content-Type", "application/json");
// oHttp.setRequestHeader("Authorization", "Bearer " + "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")
// oHttp.onreadystatechange = function () {
// if (oHttp.readyState === 4) {
// var s = ''
// var oJson = {}
// if (s != "") s += "\n";
// try {
// oJson = JSON.parse(oHttp.responseText);
// } catch (ex) {
// s += "Error: " + ex.message
// }
// if (oJson.error && oJson.error.message) {
// s += "Error: " + oJson.error.message;
// } else if (oJson.choices && oJson.choices[0].text) {
// s = oJson.choices[0].text;
// var a = s.split("?\n");
// if (a.length == 2) {
// s = a[1];
// }
// // if (selLang.value != "en-US") {
// // var a = s.split("?\n");
// // if (a.length == 2) {
// // s = a[1];
// // }
// // }
// if (s == "") s = "No response";
// console.log('ssssssssssssssssssssss',s);
// var replaceBR= (s.replace(/(?:\r\n|\r|\n)/g, "<br>")).replace(/\r?\n|\r/, "");
// setChatLog([...chatLogNew, { user: "gpt", message: `${replaceBR}`} ]);
// }
// }
// };
// var sModel = currentModel;// "text-davinci-003";
// var iMaxTokens = 100;
// var sUserId = "1";
// var dTemperature =temperature;
// var data = {
// model: sModel,
// prompt: messages,
// max_tokens: iMaxTokens,
// //user: sUserId,
// temperature: dTemperature,
// // frequency_penalty: 0.0, //Number between -2.0 and 2.0 Positive value decrease the model's likelihood to repeat the same line verbatim.
// //presence_penalty: 0.0, //Number between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics.
// //stop: ["#", ";"] //Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
// }
var
oHttp
=
new
XMLHttpRequest
();
oHttp
.
open
(
"POST"
,
"/your-endpoint"
,
true
);
oHttp
.
setRequestHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
oHttp
.
send
(
JSON
.
stringify
(
data
));
}
function
handleTemp
(
temp
)
{
...
...
client/src/color_theme_1.css
View file @
b007856
...
...
@@ -45,7 +45,8 @@ span.info {
filter
:
progid
:
DXImageTransform
.
Microsoft
.
gradient
(
startColorstr
=
'#feffff'
,
endColorstr
=
'#eff7f5'
,
GradientType
=
1
);
/* IE6-9 fallback on horizontal gradient */
}
.chat-message-center
{
padding
:
20px
10px
!important
;
padding
:
20px
10vw
!important
;
max-width
:
none
;
}
.avatar
{
...
...
@@ -131,3 +132,49 @@ span.info {
text-align
:
center
;
padding
:
10px
0
;
}
.message
code
{
background
:
#303030
;
width
:
100%
;
color
:
#fff
;
padding
:
15px
20px
;
border-radius
:
10px
;
font-family
:
monospace
,
sans-serif
;
font-size
:
12px
;
display
:
block
;
margin
:
15px
5px
;
}
code
br
:nth-child
(
-n
+
2
)
{
display
:
none
;
}
@media
(
min-width
:
1280px
)
{
.message
{
font-size
:
18px
;
}
}
@media
(
max-width
:
1279px
)
{
.message
{
font-size
:
16px
;
}
}
@media
(
max-width
:
991px
)
{
.message
{
font-size
:
14px
;
}
.chat-message-center
{
padding
:
20px
5vw
!important
;
}
}
@media
(
max-width
:
414px
)
{
.message
{
font-size
:
14px
;
}
.chat-message-center
{
padding
:
20px
5vw
!important
;
}
}
\ No newline at end of file
...
...
index.js
View file @
b007856
...
...
@@ -33,19 +33,6 @@ app.post('/api', async (req, res) => {
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