调整配置信息

pull/88/head
沈秋实 4 years ago
parent 477b6fd955
commit bbffb5ac7d

4
.gitignore vendored

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

@ -25,6 +25,23 @@ 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"
------
**log调整每日为单独文件**
**注意请赋予站点修改log文件夹内内容权限**
------
**本项目常见问题:**

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

@ -0,0 +1,5 @@
{
"personalKey": false,
"key": "sk-replace_with_your_api_key_dude",
"proxy": ""
}

@ -1,5 +1,9 @@
<?php
$type = "个人";
// 读取JSON文件
$json = file_get_contents('config.json');
// 解码JSON数据
$configs = json_decode($json, true);
// 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>";
@ -35,6 +39,7 @@ $type = "个人";
</head>
<body>
<?= $configs["name"] ?>
<div class="layout-wrap">
<header class="layout-header">
<div class="container" data-flex="main:justify cross:start">
@ -50,13 +55,11 @@ $type = "个人";
<div class="container">
<article class="article" id="article">
<div class="article-box">
<div class="precast-block" data-flex="main:left">
<!--
<div class="input-group">
<div class="precast-block" data-flex="main:left">
<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;">

@ -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);
@ -71,10 +77,17 @@ 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";
// file_put_contents(__DIR__ . "/log/" . date('Y-m-d') . "_chat.txt",$filecontent,FILE_APPEND);
// curl_close($ch);
$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);
curl_close($ch);
Loading…
Cancel
Save