Simplify AI Event classes by using base classes

Created on 11 August 2025, 24 days ago

Problem/Motivation

Now we have four event types:
PostGenerateResponseEvent.php
PostStreamingResponseEvent.php
PreGenerateResponseEvent.php
ProviderDisabledEvent.php

And most of them contain the same properties, getters, and setters, which leads to code duplication.

Proposed resolution

Let's introduce base classes, containing the base properties, that are used in the events, instead of having the same code in each event.

Remaining tasks

✨ Feature request
Status

Active

Version

1.2

Component

AI Core module

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @murz
  • @murz opened merge request.
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    I created two base classes:
    - AiProviderRequestBaseEvent
    - AiProviderResponseBaseEvent
    that stores all the common properties and getters-setters for the child events - this allowed us to make the real event classes compact and almost empty: + 521 βˆ’ 819 lines ;)

    Moving the issue to needs review.

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    a.dmitriiev β†’ made their first commit to this issue’s fork.

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    The idea is good and the implementation looks also fine. I have only one concern, please check the MR comment.

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    So, if the current implementation is okay, let's merge this then? Rebased on the fresh base branch, please make a fresh review.

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    It looks good now, but there is now problem in src/Base/OpenAiBasedProviderClientBase.php line 356, the setChatTokenUsage method expects second parameter to be array, but StreamedResponse object is passed. Maybe Marcus can check this?

    Because of this error there is no way to test the Streamed logging.

  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    Seems the problem was in the wrong order of parameters, I fixed this and reworked the code to use named parameters to minimize such errors in the future, take a look pls.

Production build 0.71.5 2024