BxDolAIToolContentSearch.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. use NeuronAI\Tools\PropertyType;
  10. use NeuronAI\Tools\ToolProperty;
  11. use NeuronAI\Tools\ArrayProperty;
  12. class BxDolAIToolContentSearch extends BxDolAITool
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct(
  17. 'content_search',
  18. 'Search for content items based on a keyword and optional sections. If needed, prepend base URL to links: ' . BX_DOL_URL_ROOT . '. Available sections: ' . self::getSections() . '.',
  19. );
  20. }
  21. public static function getSections()
  22. {
  23. $aSections = BxDolSearch::getSections();
  24. return implode(',', array_keys($aSections));
  25. }
  26. protected function properties(): array
  27. {
  28. return [
  29. new ToolProperty(
  30. name: 'keyword',
  31. type: PropertyType::STRING,
  32. description: 'The keyword to search for.',
  33. required: true
  34. ),
  35. new ArrayProperty(
  36. name: 'sections',
  37. description: 'List of sections to search in.',
  38. required: false,
  39. items: new ToolProperty(
  40. name: 'section',
  41. type: PropertyType::STRING,
  42. description: 'Section name.',
  43. )
  44. ),
  45. new ToolProperty(
  46. name: 'limit',
  47. type: PropertyType::INTEGER,
  48. description: 'The maximum number of results to return. Default is 5.',
  49. required: false
  50. )
  51. ];
  52. }
  53. public function __invoke(string $keyword, array $sections, ?int $limit = 5): array
  54. {
  55. $a = bx_srv('system', 'search', [$keyword, $sections, $limit], 'TemplServiceContent');
  56. if (!$a)
  57. return ["error" => "No content items found"];
  58. return $a;
  59. }
  60. }