Skip to content

Make OpenAIChatGenerator easier to extend #13186

Description

@anakin87

Several integrations inherit from OpenAIChatGenerator.

Currently, the base class calls some functions defined at the module level (e.g. _convert_chat_completion_to_chat_message, _convert_chat_completion_chunk_to_streaming_chunk, ...).

This makes it hard for subclasses to customize specific parts and leads to significant code duplication; in addition, the integration implementing this duplicate logic is also forced to test it, so this also costs unnecessary CI runs.

If they were methods of OpenAIChatGenerator, it would be much easier to override them and avoid duplication.

Some integrations worth investigating: Mistral, OpenRouter, STACKIT.

Since some integrations already import these functions, we cannot easily delete them, so an idea might be just exposing them as (static) methods:

class OpenAIChatGenerator:
    @staticmethod
    def _convert_completion_to_chat_message(completion, choice):
        return _convert_chat_completion_to_chat_message(completion, choice)

The exact design needs investigation, as there could be additional extension points worth introducing.

The goal would be letting integrations customize provider-specific behaviors but reusing more of the parent logic: less duplication and testing of copied code.


👋 Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!

Activity

  1. added theissue type on Oct 8, 2026
  2. changed the title [-]# Make `OpenAIChatGenerator` easier to extend[/-] [+]Make `OpenAIChatGenerator` easier to extend[/+] on Oct 8, 2026
  3. added
    P1High priority, add to the next sprint
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High priority, add to the next sprinthandled internallyHandled by the team, not open for external contributions

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions