采用Stream流模式,前端采用JS的EventSource。同时将Markdown格式文本进行了排版,对代码进行了着色处理。
parent
6a6c760669
commit
0e018b1ae1
@ -0,0 +1,59 @@
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 3px 5px
|
||||
}
|
||||
|
||||
.hljs {
|
||||
color: #abb2bf;
|
||||
background: #282c34
|
||||
}
|
||||
|
||||
.hljs-comment,.hljs-quote {
|
||||
color: #5c6370;
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
.hljs-doctag,.hljs-formula,.hljs-keyword {
|
||||
color: #c678dd
|
||||
}
|
||||
|
||||
.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst {
|
||||
color: #e06c75
|
||||
}
|
||||
|
||||
.hljs-literal {
|
||||
color: #56b6c2
|
||||
}
|
||||
|
||||
.hljs-addition,.hljs-attribute,.hljs-meta .hljs-string,.hljs-regexp,.hljs-string {
|
||||
color: #98c379
|
||||
}
|
||||
|
||||
.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable {
|
||||
color: #d19a66
|
||||
}
|
||||
|
||||
.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title {
|
||||
color: #61aeee
|
||||
}
|
||||
|
||||
.hljs-built_in,.hljs-class .hljs-title,.hljs-title.class_ {
|
||||
color: #e6c07b
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: 700
|
||||
}
|
||||
|
||||
.hljs-link {
|
||||
text-decoration: underline
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
$context = json_decode($_POST['context'] ?: "[]") ?: [];
|
||||
$postData = [
|
||||
"model" => "gpt-3.5-turbo",
|
||||
"temperature" => 0,
|
||||
"stream" => true,
|
||||
"messages" => [],
|
||||
];
|
||||
if (!empty($context)) {
|
||||
$context = array_slice($context, -5);
|
||||
foreach ($context as $message) {
|
||||
$postData['messages'][] = ['role' => 'user', 'content' => str_replace("\n", "\\n", $message[0])];
|
||||
$postData['messages'][] = ['role' => 'assistant', 'content' => str_replace("\n", "\\n", $message[1])];
|
||||
}
|
||||
}
|
||||
$postData['messages'][] = ['role' => 'user', 'content' => $_POST['message']];
|
||||
$postData = json_encode($postData);
|
||||
session_start();
|
||||
$_SESSION['data'] = $postData;
|
||||
if (isset($POST['key'])) {
|
||||
$_SESSION['key'] = $_POST['key'];
|
||||
}
|
||||
echo '{"success":true}';
|
||||
Loading…
Reference in New Issue