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.
Issue fork ai_provider_openai-3531260
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
Comment #3
gxleano commentedComment #4
gxleano commentedComment #5
marcus_johansson commentedComment #6
marcus_johansson commentedTargeting the newly added 1.2.x branch.
Comment #7
gxleano commentedThanks 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?
Comment #8
gxleano commentedComment #10
dan2k3k4 commentedTesting locally
Comment #11
dan2k3k4 commentedWorks locally for me.
The chat() method that @admitriiev mentioned, can be reworked at a later stage if needed.
Comment #12
gxleano commentedIt looks good to me Marcus!
Thanks!
Comment #13
marcus_johansson commentedThank you all, getting merged!