Create Base Class for OpenAI based clients
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3531134. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
Related to !687
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Currently out of the 15 clients we have, 5 of them are based on pure OpenAI Client with some sprinkles:</p>
<p>* OpenAI<br>
* LiteLLM<br>
* LmStudio<br>
* AmazeeAI</p>
<p>Outside of that we have three providers that are using it but with heavy modifications in:</p>
<p>* Anthropic<br>
* Ollama<br>
* Mistral<br>
* Groq</p>
<p>It should be noted that Mistral will move away, but for the other seven, it was obvious when we added function calling for instance, that we added the same piece of code on 4 places at least. This is just hard to maintain and just creates noise.</p>
<p>We already have a AiProviderClientBase that works as base class for all the clients, we should extend that and create an OpenAiBasedProviderClientBase that sets certain things and sets up the operation type methods in their most vanilla way.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Require openai-php/client in AI Core</p>
<p>Create an OpenAiBasedProviderClientBase that derives from AiProviderClientBase and:</p>
<ul>
<li>Set a variable called endpoint that is empty</li>
<li>Set a default (OpenAI based) way of isUsable function.</li>
<li>Set a default setAuthentication method</li>
<li>Set a default getClient method - do not base it on having moderation.</li>
<li>Set a default loadClient method, if the endpoint is set, configure it (see GroqProvider), otherwise do not set it in the OpenAI factory.</li>
<li>Set a vanilla Chat method (use Groq)</li>
<li>Set a vanilla moderation method (use OpenAI without the default omni-moderation-latest)</li>
<li>Set a vanilla textToImage from OpenAI, minus the specific error exceptions.</li>
<li>Set a vanilla textToSpeech from OpenAI, minus the specific error exceptions.</li>
<li>Set a vanilla speechToTetx from OpenAI, minus the specific error exceptions.</li>
<li>Set a vanilla embeddings from OpenAI, minus the specific error exceptions.</li>
</ul>
<p>In the AiProviderClientBase we can also improve by</p>
<ul>
<li>Set a default getConfig that gets the {modulename}.settings</li>
<li>Same for getApiDefintion</li>
</ul>
<p></p>
<h3 id="summary-follow-up-issues">Follow Up Issues</h3>
<ul>
<li>Opem AI Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_provider_openai/issues/3531260" title="Status: Closed (fixed)">#3531260: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
<li>LiteLLM Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_provider_litellm/issues/3532628" title="Status: Closed (fixed)">#3532628: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
<li>LmStudio Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_provider_lmstudio/issues/3532629" title="Status: Closed (fixed)">#3532629: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
<li>AmazeeAI Provider - <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/ai_provider_amazeeio/-/work_items/3532631" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/ai_provider_amazeeio/-/work_items/3532631</a></span></li>
<li>Anthropic Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_provider_anthropic/issues/3532632" title="Status: Closed (fixed)">#3532632: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
<li>Ollama Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_provider_ollama/issues/3532633" title="Status: Closed (fixed)">#3532633: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
<li>Mistral Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-5"><a href="https://www.drupal.org/project/ai_provider_mistral/issues/3532634" title="Status: Closed (won't fix)">#3532634: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
<li>Groq Provider - <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai_provider_groq/issues/3532635" title="Status: Closed (fixed)">#3532635: Remove OpenAI SDK dependency and extend it from Drupal AI core module</a></span></li>
</ul>
> Related issue: [Issue #3531260](https://www.drupal.org/node/3531260)
> Related issue: [Issue #3532628](https://www.drupal.org/node/3532628)
> Related issue: [Issue #3532629](https://www.drupal.org/node/3532629)
> Related issue: [Issue #3532631](https://www.drupal.org/node/3532631)
> Related issue: [Issue #3532632](https://www.drupal.org/node/3532632)
> Related issue: [Issue #3532633](https://www.drupal.org/node/3532633)
> Related issue: [Issue #3532634](https://www.drupal.org/node/3532634)
> Related issue: [Issue #3532635](https://www.drupal.org/node/3532635)
issue