'TychatLogic/saveChatHistory', 'items'=>[ 'content'=>'聊天内容', 'username'=>'用户名',//医生说话就传医生的username,病人说话就传病人的username ] ]; */ function saveChatHistory($chat_content){ $data = [ 'chat_msg'=>$chat_content, ]; Db::table('fa_tt_chathistory')->insert($data); return Tools::set_ok(); } /** * desc:健康洞察 * * api/HealthInsights/getHealthInsight * * author:wh */ function getHealthInsight(){ $config = config('ai_health_insight_config'); $question = '';//input('question',''); $chatobj = new ChatGPT(); $chatobj->url = $config['base_url']; $chatobj->model = ''; $chatobj->apiKey = $config['APIKey']; $answer_json_arr = []; $ticket = input('ticket'); if(empty($ticket)){ return json(Tools::set_fail('ticket必须')); } $user = Db::table('fa_hdrdoctorusers')->where('ticket',$ticket)->find(); if(empty($user)){ return json(Tools::set_fail('用户不存在')); } $day3 = date('Y-m-d 00:00:00',strtotime('-3 day')); $his_record = Db::table('fa_ty_chathistory') //->where('username',$user['username']) ->order('id asc') ->where('createtime','>',$day3)//3天之内 ->select(); $config = [ 'stream'=>false, ]; $content = [ //["role" => "user", "content" => ''] ]; foreach ($his_record as $item){ $content[] = ["role" => "user", "content" => $item['chat_msg']]; } $chatobj->setBefore($content); $chatobj->chat($question,$config,$answer_json_arr); } }