Form the data structure for AI events with main and optional fields
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3537552. --> Reported by: [murz](https://www.drupal.org/user/157092) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>We have many different AI providers and vector database types with different interfaces. But to implement the observability and usage reporting, we should form a general data structure of the requests and responses, and rely on it while making an aggregation of the usage logs and building reports.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>We should decide what data is crucial to pass to the events, store in logs and traces, and represent in reports, what is required, optional, or nice to have. </p> <p>And form a strict data structure, which will be represented in AI events, then stored in the logs, traces, and metrics, and will be visualized in the AI usage reporting pages for the end users.</p> <p>And provide mappings of the input and output data formats from common AI providers to our data structure.</p> <p>So, we should form a structured list of required and optional fields that should be present in AI events.</p> <p>Proposed structure (keep it updated):</p> <ul> <li><strong>providerId</strong> - string, required: the ID of the AI provider.</li> <li><strong>operationType</strong> - string, required: the name of the operation. <em>Probably we should manage a vocabulary?</em></li> <li><strong>modelId</strong> - string, required: the name of the model.</li> <li><strong>tokensInput</strong> - integer, optional: number of tokens in the input data.</li> <li><strong>tokensOutput</strong> - integer, optional: number of tokens in the output data.</li> <li><strong>tokensTotal</strong> - integer, optional: number of total tokens used for the operation.</li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ul> <li>Form the final version of the structure.</li> <li>Represent this structure in all AI events, maybe introduce an interface and a base class.</li> <li>Create converters from the most popular AI providers' requests and responses&nbsp;to this data format.</li> <li>Document that each provider should provide a converter to form the structured data from their events.</li> </ul> > Related issue: [Issue #3533109](https://www.drupal.org/node/3533109)
issue