request.php 902 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup AIProxy AI Proxy
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. $aRequest = array_values(array_filter($GLOBALS['aRequest'] ?? [], static function ($sPart) {
  12. return $sPart !== '';
  13. }));
  14. $bCompletion = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST'
  15. && $aRequest === ['v1', 'chat', 'completions']
  16. && !empty($GLOBALS['aModule']['enabled']);
  17. if (!$bCompletion) {
  18. http_response_code(404);
  19. header('Content-Type: application/json; charset=utf-8');
  20. echo json_encode([
  21. 'error' => [
  22. 'message' => 'Not found',
  23. 'type' => 'not_found',
  24. ],
  25. ]);
  26. return;
  27. }
  28. $oModule = BxDolModule::getInstance($GLOBALS['aModule']['name']);
  29. if (!$oModule)
  30. return;
  31. $oModule->completions();
  32. /** @} */