Fresh install lists AI provider as (not available) when no model is configured
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3529800. --> Reported by: [das-peter](https://www.drupal.org/user/762870) Related to !11 !12 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>When installing fresh and configuring settings with "Use the configuration from the "AI Translate" module (recommended)" and creating a Translation Job the AI provider is marked as "(not available)".</p> <p>Scope might be extended. After patching and attempting to execute a Translation Job via "Submit to Provider" I now get a new error:</p> <p>I might miss something but to me it does not looks like the <code>ai_translate</code> job does much.<br> In doRequest theres just this code:</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br>&nbsp;&nbsp;&nbsp; $chunk </span><span style="color: #007700">= </span><span style="color: #0000BB">$request_query</span><span style="color: #007700">[</span><span style="color: #DD0000">'text'</span><span style="color: #007700">];<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$settings </span><span style="color: #007700">= </span><span style="color: #0000BB">$translator</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSettings</span><span style="color: #007700">();<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$site_languages </span><span style="color: #007700">= \</span><span style="color: #0000BB">Drupal</span><span style="color: #007700">::</span><span style="color: #0000BB">languageManager</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getLanguages</span><span style="color: #007700">();<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$prompt </span><span style="color: #007700">= </span><span style="color: #0000BB">$settings</span><span style="color: #007700">[</span><span style="color: #DD0000">'advanced'</span><span style="color: #007700">][</span><span style="color: #DD0000">'prompt'</span><span style="color: #007700">] ?? </span><span style="color: #DD0000">'Translate from %source% into %target% language'</span><span style="color: #007700">;<br><br>&nbsp;&nbsp;&nbsp; </span><span style="color: #FF8000">// Replace the source and target language in the prompt.<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$system_prompt </span><span style="color: #007700">= </span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [</span><span style="color: #DD0000">'%source%'</span><span style="color: #007700">, </span><span style="color: #DD0000">'%target%'</span><span style="color: #007700">],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$site_languages</span><span style="color: #007700">[</span><span style="color: #0000BB">$request_query</span><span style="color: #007700">[</span><span style="color: #DD0000">'source'</span><span style="color: #007700">]]-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$site_languages</span><span style="color: #007700">[</span><span style="color: #0000BB">$request_query</span><span style="color: #007700">[</span><span style="color: #DD0000">'target'</span><span style="color: #007700">]]-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$prompt</span><span style="color: #007700">,<br>&nbsp;&nbsp;&nbsp; );<br><br>&nbsp;&nbsp;&nbsp; </span><span style="color: #FF8000">/** @var \Drupal\ai\AiProviderPluginManager $provider_manager */<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$provider_manager </span><span style="color: #007700">= \</span><span style="color: #0000BB">Drupal</span><span style="color: #007700">::</span><span style="color: #0000BB">service</span><span style="color: #007700">(</span><span style="color: #DD0000">'ai.provider'</span><span style="color: #007700">);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #FF8000">/** @var \Drupal\ai\OperationType\Chat\ChatInterface $provider */<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$provider </span><span style="color: #007700">= </span><span style="color: #0000BB">$provider_manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadProviderFromSimpleOption</span><span style="color: #007700">(</span><span style="color: #0000BB">$settings</span><span style="color: #007700">[</span><span style="color: #DD0000">'chat_model'</span><span style="color: #007700">]);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$model_id </span><span style="color: #007700">= </span><span style="color: #0000BB">$provider_manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getModelNameFromSimpleOption</span><span style="color: #007700">(</span><span style="color: #0000BB">$settings</span><span style="color: #007700">[</span><span style="color: #DD0000">'chat_model'</span><span style="color: #007700">]);<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$messages </span><span style="color: #007700">= new </span><span style="color: #0000BB">ChatInput</span><span style="color: #007700">([<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new </span><span style="color: #0000BB">chatMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'system'</span><span style="color: #007700">, </span><span style="color: #0000BB">$system_prompt</span><span style="color: #007700">),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new </span><span style="color: #0000BB">chatMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'user'</span><span style="color: #007700">, </span><span style="color: #0000BB">$chunk</span><span style="color: #007700">),<br>&nbsp;&nbsp;&nbsp; ]);<br>&nbsp;&nbsp;&nbsp; return </span><span style="color: #0000BB">$provider</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">chat</span><span style="color: #007700">(</span><span style="color: #0000BB">$messages</span><span style="color: #007700">, </span><span style="color: #0000BB">$model_id</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">getNormalized</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getText</span><span style="color: #007700">();<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>This seems not to do anything with ai_translate at all.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p><code>\Drupal\ai_tmgmt\Plugin\tmgmt\Translator\AiTranslator::checkAvailable()</code> should check for <code>model_selection_type</code> or <code>chat_model</code>.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ol> <li>&#10003; Write code </li><li>Tests?</li> <li>Reviews</li> <li>Merge</li> </ol> <h3 id="summary-ui-changes">User interface changes</h3> <p>None</p> <h3 id="summary-api-changes">API changes</h3> <p>None</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>None</p>
issue