Remove OpenAI SDK dependency and extend it from Drupal AI core module

Created on 26 June 2025, 3 months ago

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.

Feature request
Status

Active

Version

1.1

Component

Code

Created by

🇪🇸Spain gxleano Cáceres

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

Merge Requests

Comments & Activities

  • Issue created by @gxleano
  • 🇪🇸Spain gxleano Cáceres
  • Pipeline finished with Failed
    3 months ago
    Total: 150s
    #533194
  • Pipeline finished with Failed
    about 2 months ago
    Total: 137s
    #554082
  • Pipeline finished with Failed
    about 2 months ago
    Total: 146s
    #554130
  • Pipeline finished with Success
    about 2 months ago
    #554187
  • Assigned to dan2k3k4
  • Status changed to Needs review 26 days ago
  • 🇨🇭Switzerland dan2k3k4 Zurich

    Will take a look into this

  • 🇨🇭Switzerland dan2k3k4 Zurich

    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.

  • 🇨🇭Switzerland dan2k3k4 Zurich

    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

  • 🇨🇭Switzerland dan2k3k4 Zurich

    Will re-test against recent changes

Production build 0.71.5 2024