MCPcopy Create free account
hub / github.com/Rello/analytics / ContextChatManager

Class ContextChatManager

lib/ContextChat/ContextChatManager.php:19–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17use OCA\Analytics\Service\DatasetService;
18
19class ContextChatManager {
20 private $userId;
21 private $logger;
22 private $l10n;
23 private $StorageService;
24 private $DatasetService;
25 private $ContentManager;
26
27 public function __construct(
28 $userId,
29 IL10N $l10n,
30 LoggerInterface $logger,
31 StorageService $StorageService,
32 DatasetService $DatasetService,
33 ContentManager $ContentManager
34 ) {
35 $this->userId = $userId;
36 $this->l10n = $l10n;
37 $this->logger = $logger;
38 $this->StorageService = $StorageService;
39 $this->DatasetService = $DatasetService;
40 $this->ContentManager = $ContentManager;
41 }
42
43 /**
44 * Providers can use this to submit content for indexing in context chat
45 *
46 * @param int $datasetId
47 * @return bool
48 * @throws Exception
49 */
50 public function submitContent(int $datasetId): bool {
51 $datasetMetadata = $this->DatasetService->read($datasetId);
52 if ($datasetMetadata['ai_index'] !== 1) return false;
53
54 if (($datasetMetadata['storageMode'] ?? 'legacy') === 'flexible_shared') {
55 $columnNames = array_column($datasetMetadata['columns'] ?? [], 'name');
56 } else {
57 $columnNames = [$datasetMetadata['dimension1'], $datasetMetadata['dimension2'], $datasetMetadata['value']];
58 }
59 $columns = implode(', ', $columnNames);
60
61 $storageData = $this->StorageService->read($datasetId, null);
62 $data = array_map(function ($subArray) {
63 return implode(",", $subArray);
64 }, $storageData['data']);
65 $dataString = implode("\n", $data);
66
67 $content = 'This is a set of statistical data. The name of the report is: ' . $datasetMetadata['name'] . '. ';
68 $content .= 'The description of the data is: ' . $datasetMetadata['subheader'] . '. ';
69 $content .= 'The data comes in multiple rows with ' . count($columnNames) . ' columns separated by a comma. ';
70 $content .= 'The columns are ' . $columns . '. ';
71 $content .= 'The data is: ' . $dataString;
72
73 $contentItem = new ContentItem(
74 $datasetId,
75 'report',
76 $datasetMetadata['name'],

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected