Add token usage to streamed chat
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3524435. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !632 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Currently we have the possibility to abstract token usage for anyone using normal static chat, see <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai/issues/3517618" title="Status: Closed (fixed)">#3517618: Abstract token usage</a></span>, however for the streamed chat message this will not happen, since we do not know token usage until the final chunk is strreamed.</p> <p>We need to add this to the PostStreamingResponseEvent as well.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>Add so that you can collect tokens in the StreamedChatMessage, but do not add it to the interface (no breaking changes).</li> <li>Add so we can collect it in the PostStreamingResponseEvent</li> <li>Add so we inject it into the PostStreamingResponseEvent, but not in the constructor (no bkreaing changes)</li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue