Problem/Motivation

Currently, OpenAI provider is implemented using the OpenAI SDK directly, with only minor variations.

This approach has led to significant code duplication (reused by other providers), especially evident when implementing new features like function calling. In such cases, nearly identical logic had to be added in multiple places, making the codebase harder to maintain, test, and evolve.

To address this, we already have an AiProviderClientBase class as a common foundation. The proposed direction is to introduce an OpenAiBasedProviderClientBase as an intermediate abstract layer that encapsulates shared OpenAI-specific logic (e.g., request formatting, operation types, basic behavior), reducing duplication and simplifying future enhancements.

Refactoring existing OpenAI-based clients to extend from this new base class will eliminate redundant code, improve maintainability, and align these implementations with the Drupal AI core module's architecture—paving the way for better standardisation and extensibility across AI providers.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gxleano created an issue. See original summary.

gxleano’s picture

Assigned: gxleano » Unassigned
gxleano’s picture

Status: Active » Needs review
marcus_johansson’s picture

Version: 1.1.x-dev » 1.2.x-dev
marcus_johansson’s picture

Targeting the newly added 1.2.x branch.

gxleano’s picture

Thanks for review Artem!

As far as I was able to see, the chat() method in this case could just be taken from base class, I do not see any specific logic in the OpenAI provider.

What do you think Marcus?

gxleano’s picture

anjaliprasannan made their first commit to this issue’s fork.

dan2k3k4’s picture

Assigned: Unassigned » dan2k3k4

Testing locally

dan2k3k4’s picture

Assigned: dan2k3k4 » Unassigned
Status: Needs review » Reviewed & tested by the community

Works locally for me.

The chat() method that @admitriiev mentioned, can be reworked at a later stage if needed.

gxleano’s picture

It looks good to me Marcus!

Thanks!

marcus_johansson’s picture

Status: Reviewed & tested by the community » Fixed

Thank you all, getting merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.