- Issue created by @marcus_johansson
- 🇧🇪Belgium wouters_f Leuven
An example that I have tested (and works):
<?php namespace Drupal\ai_prompt_mgmt\EventSubscriber; use Drupal\ai\Event\PreGenerateResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Check for IP. */ class GlobalTokenPromptSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} * * @return array * The pre generate response event. */ public static function getSubscribedEvents(): array { return [ PreGenerateResponseEvent::EVENT_NAME => 'checkBeforeRequest', ]; } /** * Change IP before sending. * * @param \Drupal\ai\Event\PreGenerateResponseEvent $event * The event to check. */ public function checkBeforeRequest(PreGenerateResponseEvent $event) { if (in_array('ai_prompt_mgmt_replace_tokens', $event->getTags())) { foreach ($event->getInput()->getMessages() as $key => &$message) { $message->setText(str_replace(['[my_token]'], [$my_replacement], $message->getText())); } } } }
- 🇩🇪Germany marcus_johansson
Adding this to the documentation, sorry for the low-effort issue @mrdalesmith - the issue with the documentation example was discussed on Slack by me and Frederik. Thanks Frederik!
-
marcus_johansson →
committed 4369a963 on 1.0.x
Resolve #3497662 "Errors in documentation"
-
marcus_johansson →
committed 4369a963 on 1.0.x