Skip to content
Snippets Groups Projects
Commit c5460672 authored by Marcus Johansson's avatar Marcus Johansson
Browse files

Issue #3489690: Add an event that triggers on chat iterator consumption

parent 325baac2
No related branches found
No related tags found
1 merge request!295Resolve #3489690 "Add an event"
......@@ -3,12 +3,15 @@
namespace Drupal\ai\OperationType\Chat;
use Drupal\ai\Event\PostStreamingResponseEvent;
use Drupal\ai\Traits\OperationType\EventDispatcherTrait;
/**
* Streamed chat message iterator interface.
*/
abstract class StreamedChatMessageIterator implements StreamedChatMessageIteratorInterface {
use EventDispatcherTrait;
/**
* The iterator.
*
......@@ -60,7 +63,7 @@ abstract class StreamedChatMessageIterator implements StreamedChatMessageIterato
// Dispatch the event.
$event = new PostStreamingResponseEvent($this->eventId, $message, []);
\Drupal::service('event_dispatcher')->dispatch($event, PostStreamingResponseEvent::EVENT_NAME);
$this->getEventDispatcher()->dispatch($event, PostStreamingResponseEvent::EVENT_NAME);
}
/**
......
<?php
namespace Drupal\ai\Traits\OperationType;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Event dispatcher trait for operation types.
*
* @package Drupal\ai\Traits\OperationType
*/
trait EventDispatcherTrait {
/**
* {@inheritdoc}
*/
public function getEventDispatcher(): EventDispatcherInterface {
return \Drupal::service('event_dispatcher');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment