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.
Issue fork ai_provider_lmstudio-3532629
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
ivnishI 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->clientis 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
Comment #7
marcus_johansson commentedThank you, this is getting merged and a 1.1.0-beta1 will be released. Tested on chat method.