Problem/Motivation

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

ivnish’s picture

I tested this patch and I got

Error: Call to a member function chat() on null in Drupal\ai\Base\OpenAiBasedProviderClientBase->chat() (line 339 of /var/www/web/modules/contrib/ai/src/Base/OpenAiBasedProviderClientBase.php).

after chat request

$this->client is NULL here $response = $this->client->chat()->create($payload)->toArray();

if (!empty($this->getConfig()->get('host')))

Seems should be "host_name" here

Anyway $this->client is NULL

marcus_johansson’s picture

Status: Needs review » Fixed

Thank you, this is getting merged and a 1.1.0-beta1 will be released. Tested on chat method.

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

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

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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