diff --git a/application/api/controller/Auto.php b/application/api/controller/Auto.php index 100064c..ed04fa8 100644 --- a/application/api/controller/Auto.php +++ b/application/api/controller/Auto.php @@ -269,17 +269,30 @@ class Auto extends Base // OpenAI API key $api_key = Env::get("gpt.api_key"); - $mes['role'] = "user"; - $mes['content'] = "hello"; + $mes1['role'] = "user"; + $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 $data = array( 'model' => 'gpt-3.5-turbo', - 'messages' => [$mes], + 'messages' => $m, 'temperature' => 0.2, 'max_tokens' => 2048, 'n' => 1, 'stop' => '', - 'stream' => true // Use streaming mode + // 'stream' => true ,// Use streaming mode ); // Create request headers @@ -329,15 +342,15 @@ class Auto extends Base public function GptCreateChat(){ $data = $this->request->post(); $rule = new Validate([ - 'message'=>'require' + 'message'=>'require|array' ]); if(!$rule->check($data)){ return jsonError($rule->getError()); } $d['message'] = $data['message']; - $mid = isset($data['mid'])?$data['mid']:""; - $d['mid'] = $mid; - $ckey = md5(rand(1000,9999).time().$data['message']); + // $mid = isset($data['mid'])?$data['mid']:""; + // $d['mid'] = $mid; + $ckey = md5(rand(1000,9999).time().rand(10000,99999)); $d['ckey'] = $ckey; Queue::push('app\api\job\gpt@fire', $d, "gpt"); $re['ckey'] = $ckey; diff --git a/application/api/controller/Production.php b/application/api/controller/Production.php index d789f0e..c535591 100644 --- a/application/api/controller/Production.php +++ b/application/api/controller/Production.php @@ -419,6 +419,14 @@ class Production extends Base } } + /** + * 校对主入口 + */ + public function proto(){ + $data = $this->request->post(); + + } + public function eeeccc() { diff --git a/application/api/job/gpt.php b/application/api/job/gpt.php index 4df67bf..6f871ed 100644 --- a/application/api/job/gpt.php +++ b/application/api/job/gpt.php @@ -19,7 +19,7 @@ class gpt { * @param type $data */ public function push($data){ - GptChar($data['message'],$data['ckey'],$data['mid']); + GptChar($data['message'],$data['ckey']); } } diff --git a/application/common.php b/application/common.php index 3083da7..9f9e837 100644 --- a/application/common.php +++ b/application/common.php @@ -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'; // OpenAI API key $api_key = Env::get("gpt.api_key"); - $mes['role'] = "user"; - $mes['content'] = $message; - if($mid!=""){ - $mes['name'] = $mid; - } // Request data $data = array( 'model' => 'gpt-3.5-turbo', - 'messages' => [$mes], + 'messages' => $message, 'temperature' => 0.2, 'max_tokens' => 2048, 'n' => 1, @@ -323,7 +318,7 @@ function GptChar($message,$ckey,$mid="") if($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); }