Add files via upload

pull/6/head
dirk1983 4 years ago committed by GitHub
parent 780d5ae093
commit a073141ebb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,4 @@
127.0.0.1 | 2023-02-16 10:03:27
Q:test
A:服务器返回错误信息:Incorrect API key provided: sk-PXQ0A***************************************wkqd. You can find your API key at https://platform.openai.com/account/api-keys.
----------------

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

@ -0,0 +1,198 @@
.logo-title {
line-height:50px;
color:#fff;
text-decoration:none
}
.layout-header .logo .links {
text-decoration:none;
}
.layout-header {
background:#202123;
}
.layout-header .nav .list .links {
color:#fff;
}
.xiezuo-header {
max-height:calc(100vh - 30px);
overflow-y:auto;
min-height:200px;
}
#article-wrapper {
min-height:calc(100vh - 320px);
border:1px solid;
border-radius:var(--zhuluan-primary-border-radius);
}
.article-box {
min-height:calc(100vh - 50px) !important;
position:relative;
display:flex;
flex-direction:column;
justify-content:space-around;
}
#fixed-block {
background-color:#40414F;
bottom:20px;
}
#kw-target-box {
border-radius:var(--zhuluan-primary-border-radius);
-webkit-border-radius:var(--zhuluan-primary-border-radius);
-moz-border-radius:var(--zhuluan-primary-border-radius);
-ms-border-radius:var(--zhuluan-primary-border-radius);
-o-border-radius:var(--zhuluan-primary-border-radius);
}
#popup {
display:none;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
-webkit-transform:translate(-50%, -50%);
-moz-transform:translate(-50%, -50%);
-ms-transform:translate(-50%, -50%);
-o-transform:translate(-50%, -50%);
background-color:#fff;
padding:20px;
border:1px solid var(--zhuluan-border-color);
width:70%;
border-radius:var(--zhuluan-primary-border-radius);
-webkit-border-radius:var(--zhuluan-primary-border-radius);
-moz-border-radius:var(--zhuluan-primary-border-radius);
-ms-border-radius:var(--zhuluan-primary-border-radius);
-o-border-radius:var(--zhuluan-primary-border-radius);
}
#popup-close {
font-size:24px;
color:#666;
float:right;
cursor:pointer;
}
.popup-header {
height:30px;
}
.pop-title {
font-size:24px;
}
.popup-content {
margin-top:20px;
}
.image-wrapper {
display:flex;
flex-direction:row;
justify-content:space-around;
}
.image-wrapper img {
width:40%;
}
.popup-footer {
margin-top:10px;
text-align:center;
}
#count-down {
font-size:20px;
color:red;
}
#sure-pay {
margin-top:10px;
display:block;
width:120px;
height:40px;
line-height:40px;
border:1px solid var(--zhuluan-border-color);
border-radius:var(--zhuluan-primary-border-radius);
background-color:#0188fb;
color:#fff;
-webkit-border-radius:var(--zhuluan-primary-border-radius);
-moz-border-radius:var(--zhuluan-primary-border-radius);
-ms-border-radius:var(--zhuluan-primary-border-radius);
-o-border-radius:var(--zhuluan-primary-border-radius);
margin-left:50%;
transform:translateX(-50%);
-webkit-transform:translateX(-50%);
-moz-transform:translateX(-50%);
-ms-transform:translateX(-50%);
-o-transform:translateX(-50%);
cursor:pointer;
}
li.article-title {
background:#343541;
padding:14px;
color:#fff;
font-size:15px;
}
li.article-content {
background:#434654;
padding:14px;
color:#fff;
font-size:15px;
}
.article .creating-loading {
display:none;
position:absolute;
z-index:10008;
left:0;
top:0;
right:0;
bottom:0;
background-color:rgba(52, 53, 65, .68);
width:100%;
height:100%;
}
.layout-content {
padding:0 !important;
}
@media screen and (max-width:768px) {
#popup {
height:350px;
}
.image-wrapper img {
width:92px;
height:139px;
}
}
pre {
word-break:break-all;
word-wrap:break-word;
white-space:pre-wrap;
}
input {
display:none;
}
label {
display:block;
width:40px;
height:20px;
border-radius:20px;
background:rgb(164, 165, 179);
border:1px solid #A4A5B3;
cursor:pointer;
position:relative;
overflow:hidden;
}
label::before {
display:block;
content:'';
width:16px;
height:16px;
border-radius:50%;
background:white;
position:absolute;
left:1px;
top:50%;
transform:translateY(-50%);
transition:all .3s;
}
label::after {
display:block;
content:'';
width:0;
height:100%;
background:#202123;
transition:all .3s;
border-radius:10px;
}
input:checked + label::before {
left:20px;
}
input:checked + label::after {
width:100%;
}

@ -0,0 +1,89 @@
<?php
$type = "个人";
// if (substr($_SERVER["REMOTE_ADDR"],0,9)!="127.0.0.1"){
// if (strpos($_SERVER["HTTP_USER_AGENT"],"MicroMessenger")){
// echo "<div style='height:100%;width:100%;text-align:center;margin-top:30%;'><h1>请点击右上角,选择”在浏览器打开“</h1></div>";
// exit;
// }
// if (!isset($_SERVER['PHP_AUTH_USER'])) {
// header('WWW-Authenticate: Basic realm="Please input username and password."');
// header('HTTP/1.0 401 Unauthorized');
// echo 'Bye, honey.';
// exit;
// } else {
// if (($_SERVER['PHP_AUTH_USER']=="admin")&&($_SERVER['PHP_AUTH_PW']=="admin")){
// $type = "外网";
// } else {
// echo 'Wrong password, bye...';
// exit;
// }
// }
// } else {
// $type = "内网";
// }
?>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>ChatGPT<?=$type?>专用版</title>
<link rel="stylesheet" href="css/common.css?v1.1">
<link rel="stylesheet" href="css/wenda.css?v1.1">
</head>
<body>
<div class="layout-wrap">
<header class="layout-header">
<div class="container" data-flex="main:justify cross:start">
<div class="header-logo">
<h2 class="logo"><a class="links" id="clean" title="清空对话信息"><span class="logo-title">清空对话信息</span></a></h2>
</div>
<div class="header-logo">
<h2 class="logo"><a class="links" id="showlog" title="查看他人对话"><span class="logo-title">查看他人对话</span></a></h2>
</div>
</div>
</header>
<div class="layout-content">
<div class="container">
<article class="article" id="article">
<div class="article-box">
<div style="text-align: center;color:#9ca2a8">
ChatGPT是一个超强的AI,它会创作、写论文、答辩、编程等。请勿查询违法信息,服务器会保留查询记录。<br/>
账户总查询次数有限,请不要过于浪费查询机会,仅限内部人员测试使用。<br/>
</div>
<div class="precast-block" data-flex="main:left">
<div class="input-group">
<span style="text-align: center;color:#9ca2a8">&nbsp;&nbsp;连续对话:</span>
<input type="checkbox" id="keep" checked style="min-width:220px;">
<label for="keep"></label>
<span style="text-align: center;color:#9ca2a8">&nbsp;&nbsp;&nbsp;&nbsp;默认开启,ChatGPT将以下面的对话信息作为上下文回答您的提问(含上下文问题最多3072个字符,AI回答不超过1024个字符)。</span>
</div>
</div>
<ul id="article-wrapper">
</ul>
<div class="creating-loading" data-flex="main:center dir:top cross:center">
<div class="semi-circle-spin"></div>
</div>
<div id="fixed-block">
<div class="precast-block" id="kw-target-box" data-flex="main:left cross:center">
<div id="target-box" class="box">
<input type="text" name="kw-target" placeholder="请点此提问" id="kw-target" autofocus>
</div>
<div class="right-btn layout-bar">
<p class="btn ai-btn bright-btn" id="ai-btn" data-flex="main:center cross:center"><i class="iconfont icon-wuguan"></i>发送</p>
</div>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.cookie.min.js"></script>
<script src="js/layer.min.js" type="application/javascript"></script>
<script src="js/chat.js?v2.8"></script>
</body>
</html>

@ -0,0 +1,101 @@
/*
//定时器*/
var contextarray = [];
$(document).ready(function () {
$("#kw-target").on('keydown', function (event) {
if (event.keyCode == 13) {
send_post();
return false;
}
});
$("#ai-btn").click(function () {
send_post();
return false;
});
$("#clean").click(function () {
$("#article-wrapper").html("");
contextarray = [];
layer.msg("清理完毕!");
return false;
});
$("#showlog").click(function () {
let btnArry = ['已阅'];
layer.open({<!-- -->
type: 1
,title: '全部对话日志'
,area: ['80%', '80%']
,shade: 0.5
,scrollbar: true
,offset: [
($(window).height() * 0.1)
,($(window).width() * 0.1)
]
,content: '<iframe src="chat.txt?' + new Date().getTime()+ '" style="width: 100%; height: 100%;"></iframe>'
,btn: btnArry
});
return false;
});
function articlewrapper(answer,str){
$("#article-wrapper").append('<li class="article-content" id="'+answer+'"><pre></pre></li>');
if(str == null || str == ""){
str="服务器响应超时,您可以更换词语再试试或过会儿再试。";
}
let str_ = ''
let i = 0
let timer = setInterval(()=>{
if(str_.length<str.length){
str_ += str[i++]
$("#"+answer).children('pre').text(str_+'_')//打印时加光标
}else{
clearInterval(timer)
$("#"+answer).children('pre').text(str_)//打印时加光标
}
},5)
}
function send_post() {
var prompt = $("#kw-target").val();
if (prompt == "") {
layer.msg("请输入您的问题", { icon: 5 });
return;
}
var loading = layer.msg('正在组织语言,请稍等片刻...', {
icon: 16,
shade: 0.4,
time:false //取消自动关闭
});
$.ajax({
cache: true,
type: "POST",
url: "message.php",
data: {
message: prompt,
context:$("#keep").prop("checked")?JSON.stringify(contextarray):'[]',
},
dataType: "json",
success: function (results) {
layer.close(loading);
$("#kw-target").val("");
layer.msg("处理成功!");
contextarray.push([prompt, results.raw_message]);
$("#article-wrapper").append('<li class="article-title">问:'+prompt+'</li>');
articlewrapper(randomString(16),"答:"+results.raw_message);
}
});
}
function randomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
var maxPos = $chars.length;
var pwd = '';
for (i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
});

@ -0,0 +1,2 @@
/*! jquery.cookie v1.4.1 | MIT */
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?a(require("jquery")):a(jQuery)}(function(a){function b(a){return h.raw?a:encodeURIComponent(a)}function c(a){return h.raw?a:decodeURIComponent(a)}function d(a){return b(h.json?JSON.stringify(a):String(a))}function e(a){0===a.indexOf('"')&&(a=a.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return a=decodeURIComponent(a.replace(g," ")),h.json?JSON.parse(a):a}catch(b){}}function f(b,c){var d=h.raw?b:e(b);return a.isFunction(c)?c(d):d}var g=/\+/g,h=a.cookie=function(e,g,i){if(void 0!==g&&!a.isFunction(g)){if(i=a.extend({},h.defaults,i),"number"==typeof i.expires){var j=i.expires,k=i.expires=new Date;k.setTime(+k+864e5*j)}return document.cookie=[b(e),"=",d(g),i.expires?"; expires="+i.expires.toUTCString():"",i.path?"; path="+i.path:"",i.domain?"; domain="+i.domain:"",i.secure?"; secure":""].join("")}for(var l=e?void 0:{},m=document.cookie?document.cookie.split("; "):[],n=0,o=m.length;o>n;n++){var p=m[n].split("="),q=c(p.shift()),r=p.join("=");if(e&&e===q){l=f(r,g);break}e||void 0===(r=f(r))||(l[q]=r)}return l};h.defaults={},a.removeCookie=function(b,c){return void 0===a.cookie(b)?!1:(a.cookie(b,"",a.extend({},c,{expires:-1})),!a.cookie(b))}});

2
js/jquery.min.js vendored

File diff suppressed because one or more lines are too long

1
js/layer.min.js vendored

File diff suppressed because one or more lines are too long

@ -0,0 +1,75 @@
<?php
header( "Content-Type: application/json" );
$context = json_decode( $_POST['context'] ?: "[]" ) ?: [];
$prompt = "";
if( empty( $context ) ) {
$please_use_above = "";
} else {
$context = array_slice( $context, -5 );
foreach( $context as $message ) {
$prompt .= "问题:\n" . $message[0] . "\n\n答案:\n" . $message[1] . "\n\n";
}
$please_use_above = "。请使用上面的问题和答案作为前后文进行回答。";
}
$prompt .= "问题:\n" . $_POST['message'] . $please_use_above . "\n\n答案:\n\n";
$dTemperature = 0.9;
$iMaxTokens = 1024;
$top_p = 1;
$frequency_penalty = 0.0;
$presence_penalty = 0.0;
$OPENAI_API_KEY = "sk-PXQ0A35RLCQaImgLujPST3blbkFJ2d7Kaa9aJjUqzvYwwkqd";
$sModel = "text-davinci-003";
$ch = curl_init();
$headers = [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY . ''
];
$postData = [
'model' => $sModel,
'prompt' => str_replace('"', '', $prompt),
'temperature' => $dTemperature,
'max_tokens' => $iMaxTokens,
'top_p' => $top_p,
'frequency_penalty' => $frequency_penalty,
'presence_penalty' => $presence_penalty,
'stop' => '[" Human:", " AI:"]',
];
//echo json_encode($postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
$result = curl_exec($ch);
$complete = json_decode($result);
if( isset( $complete->choices[0]->text ) ) {
$text = str_replace( "\\n", "\n", $complete->choices[0]->text );
} elseif( isset( $complete->error->message ) ) {
$text = "服务器返回错误信息:".$complete->error->message;
} else {
$text = "抱歉,我不知道如何回答.";
}
echo json_encode( [
"message" => $text,
"raw_message" => $text,
"status" => "success",
] );
$content2 = $_SERVER["REMOTE_ADDR"]." | ".date("Y-m-d H:i:s")."\n";
$content2 .= "Q:".$_POST['message']."\nA:".$text."\n----------------\n";
$myfile = fopen(__DIR__ . "/chat.txt", "a") or die("Writing file failed.");
fwrite($myfile, $content2);
fclose($myfile);
?>
Loading…
Cancel
Save