1
This commit is contained in:
@@ -269,17 +269,30 @@ class Auto extends Base
|
|||||||
// OpenAI API key
|
// OpenAI API key
|
||||||
$api_key = Env::get("gpt.api_key");
|
$api_key = Env::get("gpt.api_key");
|
||||||
|
|
||||||
$mes['role'] = "user";
|
$mes1['role'] = "user";
|
||||||
$mes['content'] = "hello";
|
$mes1['content'] = "黄瓜可以沾糖吃吗";
|
||||||
|
$mes2['role'] = "assistant";
|
||||||
|
$mes2['content'] = "黄瓜可以沾糖吃,但是一般情况下人们更倾向于将黄瓜作为蔬菜来食用,而不是作为水果来食用。如果您想要将黄瓜作为水果来食用,可以将其切成小块,然后沾上适量的糖粉,这样可以增加其甜度。但是需要注意的是,过量食用糖会对健康造成不良影响,建议适量食用。";
|
||||||
|
$mes3['role'] = "user";
|
||||||
|
$mes3['content'] = "那可以沾盐吃吗?";
|
||||||
|
$m[] = $mes1;
|
||||||
|
$m[] = $mes2;
|
||||||
|
$m[] = $mes3;
|
||||||
|
|
||||||
|
// dump([$m]);
|
||||||
|
|
||||||
|
// dump([$mes1,$mes2,$mes3]);
|
||||||
|
|
||||||
|
// die;
|
||||||
// Request data
|
// Request data
|
||||||
$data = array(
|
$data = array(
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-3.5-turbo',
|
||||||
'messages' => [$mes],
|
'messages' => $m,
|
||||||
'temperature' => 0.2,
|
'temperature' => 0.2,
|
||||||
'max_tokens' => 2048,
|
'max_tokens' => 2048,
|
||||||
'n' => 1,
|
'n' => 1,
|
||||||
'stop' => '',
|
'stop' => '',
|
||||||
'stream' => true // Use streaming mode
|
// 'stream' => true ,// Use streaming mode
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request headers
|
// Create request headers
|
||||||
@@ -329,15 +342,15 @@ class Auto extends Base
|
|||||||
public function GptCreateChat(){
|
public function GptCreateChat(){
|
||||||
$data = $this->request->post();
|
$data = $this->request->post();
|
||||||
$rule = new Validate([
|
$rule = new Validate([
|
||||||
'message'=>'require'
|
'message'=>'require|array'
|
||||||
]);
|
]);
|
||||||
if(!$rule->check($data)){
|
if(!$rule->check($data)){
|
||||||
return jsonError($rule->getError());
|
return jsonError($rule->getError());
|
||||||
}
|
}
|
||||||
$d['message'] = $data['message'];
|
$d['message'] = $data['message'];
|
||||||
$mid = isset($data['mid'])?$data['mid']:"";
|
// $mid = isset($data['mid'])?$data['mid']:"";
|
||||||
$d['mid'] = $mid;
|
// $d['mid'] = $mid;
|
||||||
$ckey = md5(rand(1000,9999).time().$data['message']);
|
$ckey = md5(rand(1000,9999).time().rand(10000,99999));
|
||||||
$d['ckey'] = $ckey;
|
$d['ckey'] = $ckey;
|
||||||
Queue::push('app\api\job\gpt@fire', $d, "gpt");
|
Queue::push('app\api\job\gpt@fire', $d, "gpt");
|
||||||
$re['ckey'] = $ckey;
|
$re['ckey'] = $ckey;
|
||||||
|
|||||||
@@ -419,6 +419,14 @@ class Production extends Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校对主入口
|
||||||
|
*/
|
||||||
|
public function proto(){
|
||||||
|
$data = $this->request->post();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function eeeccc()
|
public function eeeccc()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class gpt {
|
|||||||
* @param type $data
|
* @param type $data
|
||||||
*/
|
*/
|
||||||
public function push($data){
|
public function push($data){
|
||||||
GptChar($data['message'],$data['ckey'],$data['mid']);
|
GptChar($data['message'],$data['ckey']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,23 +259,18 @@ function search_array_val($arr, $val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function GptChar($message,$ckey,$mid="")
|
function GptChar($message,$ckey)
|
||||||
{
|
{
|
||||||
$url = 'https://api.openai.com/v1/chat/completions';
|
$url = 'https://api.openai.com/v1/chat/completions';
|
||||||
|
|
||||||
// OpenAI API key
|
// OpenAI API key
|
||||||
$api_key = Env::get("gpt.api_key");
|
$api_key = Env::get("gpt.api_key");
|
||||||
|
|
||||||
$mes['role'] = "user";
|
|
||||||
$mes['content'] = $message;
|
|
||||||
if($mid!=""){
|
|
||||||
$mes['name'] = $mid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request data
|
// Request data
|
||||||
$data = array(
|
$data = array(
|
||||||
'model' => 'gpt-3.5-turbo',
|
'model' => 'gpt-3.5-turbo',
|
||||||
'messages' => [$mes],
|
'messages' => $message,
|
||||||
'temperature' => 0.2,
|
'temperature' => 0.2,
|
||||||
'max_tokens' => 2048,
|
'max_tokens' => 2048,
|
||||||
'n' => 1,
|
'n' => 1,
|
||||||
@@ -323,7 +318,7 @@ function GptChar($message,$ckey,$mid="")
|
|||||||
if($cache_id!=''){
|
if($cache_id!=''){
|
||||||
Cache::set($ckey."_id",$cache_id);
|
Cache::set($ckey."_id",$cache_id);
|
||||||
}
|
}
|
||||||
Cache::set($ckey,$cc."[{enddata}]",3600);
|
Cache::set($ckey,(Cache::get($ckey)?Cache::get($ckey):'')."[{enddata}]",3600);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user