Problem/Motivation

Currently, Mistral 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

Status: Active » Needs review
gxleano’s picture

dan2k3k4’s picture

Assigned: Unassigned » dan2k3k4

Will take a look into this

dan2k3k4’s picture

Assigned: dan2k3k4 » Unassigned
Status: Needs review » Needs work

Unsure if this is because I'm testing with latest 1.2.x version of the AI module (SHA: 302ba82a8d89)

On route `/admin/config/ai/ai-external-moderation`

TypeError: set_error_handler(): Argument #1 ($callback) must be a valid callback or null, class Drupal\ai_provider_mistral\Plugin\AiProvider\MistralProvider does not have a method "errorCatcher" in set_error_handler() (line 35 of modules/contrib/ai_provider_mistral/src/Plugin/AiProvider/MistralProvider.php).

Also on the default settings route: `/admin/config/ai/settings` - I have no models listed for Mistral AI.

dan2k3k4’s picture

I believe we need to push a 1.2.x branch and target 1.2.x of the AI module, same as the other provider modules

dan2k3k4’s picture

Assigned: Unassigned » dan2k3k4
Status: Needs work » Needs review

Will re-test against recent changes

fago’s picture

let's pause this until we decided https://www.drupal.org/project/ai_provider_mistral/issues/3495572#commen... - if we switch the client we don't need to do this any more. 1.0.x I'd keep rather stable as is + focus on moving on with 1.1x

marcus_johansson’s picture

Status: Needs review » Closed (won't fix)

Decision was taken on #3532634: Remove OpenAI SDK dependency and extend it from Drupal AI core module, so we will close this. Thank you for the efforts!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

dan2k3k4’s picture

Assigned: dan2k3k4 » Unassigned