pull/88/head
root 4 years ago
parent 477b6fd955
commit e38a31567b

4
.gitignore vendored

@ -0,0 +1,4 @@
/log/*
!/log/此文件夹用于存放日志文件.txt
config.json
favicon.ico

@ -25,6 +25,46 @@ ChatGPT的横空出世真的改变了世界,用过的人都知道ChatGPT完全
![t2](https://user-images.githubusercontent.com/5563148/232330566-c6ea7fb3-474f-45e4-adda-37f3db27b92a.jpg)
------
**调整部分内容为配置文件形式优化拉取代码配置信息冲突**
拉取代码后请复制config.json_example 为 config.json
linux下 进入项目目录执行 cp config.json_example config.json
配置定义如下
// 控制是否显示私人密钥输入框
"personalKey": false,
//设置全局密钥 开启私人密钥输入框后此key将不启用
"key": "sk-replace_with_your_api_key_dude",
//代理服务器未设置则不启用代理示例 http://127.0.0.1
"proxy": "http://127.0.0.1"
//白名单ip数组内的ip加入白名单访问时直接进入内部专用版
"homeAddress": [
"127.0.0.1"
],
//设置可访问用户名和与密码
"userList": {
"admin": "123"
}
------
**log调整每日为单独文件**
**注意请赋予站点修改log文件夹内内容权限**
------
**本项目常见问题:**

@ -1,4 +0,0 @@
127.0.0.1 | 2023-03-08 10:37:47
Q:你好
A:你好!有什么我可以帮助你的吗?
----------------

@ -0,0 +1,6 @@
{
"homeAddress":[]:,
"personalKey": false,
"key": "sk-replace_with_your_api_key_dude",
"proxy": ""
}

@ -1,26 +1,35 @@
<?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 = "内网";
// }
// 读取JSON文件
$json = file_get_contents('config.json');
// 解码JSON数据
$configs = json_decode($json, true);
$isHome = false;
if(in_array($_SERVER["REMOTE_ADDR"],$configs['homeAddress'])){
$isHome = true;
}
if ($isHome) {
$type = "内部";
} else {
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 ($configs["userList"][$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW']) {
$type = "外网";
} else {
echo 'Wrong password, bye...';
exit;
}
}
}
?>
<html lang="zh-CN">
@ -35,6 +44,7 @@ $type = "个人";
</head>
<body>
<?= $isHome ?>
<div class="layout-wrap">
<header class="layout-header">
<div class="container" data-flex="main:justify cross:start">
@ -51,12 +61,10 @@ $type = "个人";
<article class="article" id="article">
<div class="article-box">
<div class="precast-block" data-flex="main:left">
<!--
<div class="input-group">
<div id="keydiv" <?= $configs["personalKey"] ? "style=''" : "style='display:none;'" ?>class="input-group">
<span style="text-align: center;color:#9ca2a8">&nbsp;&nbsp;API-KEY&nbsp;&nbsp;</span>
<input type="password" id="key" style="border:1px solid grey;display:block;max-width:270px;width:calc(100% - 70px);" onload="this.focus();">
</div>
-->
<div class="input-group">
<span style="text-align: center;color:#9ca2a8">&nbsp;&nbsp;连续对话:</span>
<input type="checkbox" id="keep" checked="" style="min-width:220px;">
@ -229,4 +237,4 @@ $type = "个人";
</script>
</body>
</html>
</html>

@ -163,7 +163,7 @@ $(document).ready(function () {
});
function send_post() {
if (($('#key').length) && ($('#key').val().length != 51)) {
if ($("#keydiv").attr("style").indexOf("display:none") < 0 && ($('#key').length) && ($('#key').val().length != 51)) {
layer.msg("请输入正确的API-KEY", { icon: 5 });
return;
}

@ -0,0 +1,2 @@
此文件夹用于存放日志文件.txt
若无法自动生成YYYY-mm-dd_chat.txt的日志文件请给php允许着log文件夹修改权限 或 设置log文件夹为所有用户皆可修改

@ -6,11 +6,15 @@ session_start();
$postData = $_SESSION['data'];
$_SESSION['response'] = "";
$ch = curl_init();
$OPENAI_API_KEY = "sk-replace_with_your_api_key_dude";
// 读取JSON配置文件
$json = file_get_contents('config.json');
// 解码JSON配置文件数据
$configs = json_decode($json, true);
$OPENAI_API_KEY = $configs["key"];
if (isset($_SESSION['key'])) {
$OPENAI_API_KEY = $_SESSION['key'];
}
$headers = [
$headers = [
'Accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer ' . $OPENAI_API_KEY
@ -54,7 +58,9 @@ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
//curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1:1081");
if($configs["proxy"]){
curl_setopt($ch, CURLOPT_PROXY, $configs["proxy"]);
}
curl_exec($ch);
@ -74,7 +80,9 @@ foreach ($responsearr as $msg) {
$questionarr = json_decode($_SESSION['data'], true);
$filecontent = $_SERVER["REMOTE_ADDR"] . " | " . date("Y-m-d H:i:s") . "\n";
$filecontent .= "Q:" . end($questionarr['messages'])['content'] . "\nA:" . trim($answer) . "\n----------------\n";
$myfile = fopen(__DIR__ . "/chat.txt", "a") or die("Writing file failed.");
fwrite($myfile, $filecontent);
fclose($myfile);
curl_close($ch);
file_put_contents(__DIR__ . "/log/" . date('Y-m-d') . "_chat.txt",$filecontent,FILE_APPEND);
// $myfile = fopen(__DIR__ . "/chat.txt", "a") or die("Writing file failed.");
// fwrite($myfile, $filecontent);
// fclose($myfile);
curl_close($ch);
Loading…
Cancel
Save