AiChatController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Controllers\Api\V1\Chat;
  3. use App\Facades\AiChatContentFacade;
  4. use App\Http\Controllers\Api\V1\BaseController;
  5. use Illuminate\Http\Request;
  6. /**
  7. * AI聊天
  8. */
  9. class AiChatController extends BaseController
  10. {
  11. /**
  12. * 发送聊天数据
  13. * @param Request $request
  14. * @return array
  15. */
  16. public function sendData(Request $request)
  17. {
  18. return AiChatContentFacade::sendData(
  19. (int)$this->auth(),
  20. strval($request->get("conversation_id","")),
  21. strval($request->get("content",""))
  22. );
  23. }
  24. /**
  25. * 聊天历史,列表分页
  26. * @return array
  27. */
  28. public function index()
  29. {
  30. $conditions = [
  31. 'Robot' => true,
  32. 'user_id' => $this->auth(),
  33. "conversation_id"=>request('conversation_id', null)
  34. ];
  35. $fields = ['*'];
  36. $sort = '`id` asc';
  37. $page = request('page', 1);
  38. $limit = request('limit', 20);
  39. return AiChatContentFacade::getChatContentList($conditions, $fields, $sort, $page, $limit);
  40. }
  41. }