OpenAI provider chat method generates response twice
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3480160. --> Reported by: [mrdalesmith](https://www.drupal.org/user/2612656) Related to !175 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>At line 309 in ai/modules/providers/provider_openai/src/Plugin/AiProvider/OpenAiProvider.php, the chat method generates a $response for the provider within a try/catch. Then at line 325, it regenerates a response with the same settings dependent on whether the response should be streamed or not. The first response is never used and seems to be generated in error, meaning the provider will use up any quota twice as quickly.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Refactor the code so the streamed/not streamed check is done inside the try/catch so the correct type of $response is generated, once.</p>
issue