cURL Timeout and Deprecated Function Error When Using AI Translate Submodule

Created on 7 October 2024, 4 months ago

Drupal Information

- Drupal Version: 10.3.6
- AI Module Version: 1.0.x-dev (Updated on 6 Oct 2024)
- AI Translate Submodule: Enabled
- PHP Version: 8.3.10
- Server Environment: DDEV, Nginx

Description

When attempting to translate content using the AI Translate submodule, I encounter a 500 Internal Server Error accompanied by a cURL timeout. Additionally, there's a deprecated function warning related to the `explode()` function. These issues occur on the `/en/node/118/translations` page when clicking the "Translate using gpt-4o" link.

Steps to Reproduce

1. Navigate to the translations page of a node, e.g., `/en/node/118/translations`.
2. Click on the Translate using gpt-4o link.
3. Observe the error messages displayed.

Expected Behavior

The content should be successfully sent to the GPT-4 model for translation, and the translated content should appear without errors.

Actual Behavior

- Primary Error:

  Batch has encountered an error
  Continue to the error page

  An AJAX HTTP error occurred.
  HTTP Result Code: 500
  Debugging information follows.
  Path: /en/batch?id=191&op=do_nojs&op=do
  StatusText: error
  ResponseText: The website encountered an unexpected error. Try again later.
  Drupal\ai\Exception\AiRequestErrorException: Error invoking model response: cURL error 28: Operation timed out after 30006 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.openai.com/v1/chat/completions in Drupal\ai\Plugin\ProviderProxy->wrapperCall() (line 190 of modules/contrib/ai/src/Plugin/ProviderProxy.php).

- Deprecated Function Warning:
Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in Drupal\ai_translate\Form\AiTranslateForm->buildForm() (line 112 of modules/contrib/ai/modules/ai_translate/src/Form/AiTranslateForm.php).

I'm using the latest development version of the AI module, and I understand it's still under active development. I hope this information helps in diagnosing and resolving the issues.

Thank you for your dedication and hard work on the Drupal AI project!

🐛 Bug report
Status

Active

Version

1.0

Component

Other Submodules

Created by

🇰🇬Kyrgyzstan dan_metille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dan_metille
  • 🇩🇪Germany marcus_johansson

    Changing the issue to a feature request and adding the possibility to set timeouts based on fine grained level.

    The problem right now is that your guzzle client times out due to global settings, you can fix this similar to how you see here: https://www.jeffgeerling.com/blog/2016/increase-guzzle-http-client-reque.... But this not recommmeded.

  • 🇰🇬Kyrgyzstan dan_metille

    Thanks Marcus. In the meanwhile, I will give a try to that linked solution in my dev environment.

  • Assigned to marcus_johansson
  • 🇸🇰Slovakia poker10

    When chatting with AI assistant in Drupal CMS (AI recipe), I am unable to get any response and still getting

    Error invoking model response: cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.openai.com/v1/chat/completions
    

    This issue seems more serious? The chat only displays Error, please try again. which if effectively draining your tokens again and again, but the error is only in watchdog, which could probably be not obvious for an unexperienced site builder to look at first..

    I disagree this is an error in the guzzle library, because Drupal CMS orchestrate everything and you cannot expect that ambitious site builders will start changing such values.

    I am using OpenAI provider. Example prompt which returns the curl error: List all fields of Basic page content type

  • First commit to issue fork.
  • 🇺🇸United States phenaproxima Massachusetts

    This issue is starting to worry some folks in the Drupal CMS issue queue.

    So as a possible workaround, why not make \Drupal\ai\Base\AiProviderClientBase::create() support a $configuration['timeout'] value that defaults to a generous 60 seconds, and gets passed to the HTTP client factory service to create the HTTP client? There is no need to override anything in settings.php.

    I've submitted an MR with exactly this change, and I'm hoping that it can be merged quickly and put into a new 1.0.1 tag that Drupal CMS could use. That should allay some concerns and solidify the inclusion of the AI module in the 1.0.0 release.

  • Merge request !397Allow providers to override HTTP timeout → (Merged) created by phenaproxima
  • Pipeline finished with Canceled
    11 days ago
    Total: 164s
    #393083
  • Pipeline finished with Success
    11 days ago
    Total: 191s
    #393084
  • Pipeline finished with Canceled
    11 days ago
    Total: 253s
    #393102
  • Pipeline finished with Failed
    11 days ago
    Total: 219s
    #393103
  • Pipeline finished with Success
    11 days ago
    Total: 320s
    #393105
  • 🇩🇪Germany marcus_johansson

    Tested and working against spoof Mockoon API with a timeout of 59 seconds. Will be merged. Thanks @phenaproxima.

  • 🇩🇪Germany marcus_johansson

    @poker10 - just FYI a follow up issues that might make the UX better when this happens: 📌 Better error handling in the Chatbot Active and Add Javascript Orchestration for Chatbot/Assistant Active .

  • 🇮🇳India abhishek@kumar
    • Modify the module's configuration schema in ai_translate.settings.yml:
    timeout: 
      type: integer
      label: 'API Call Timeout'
      default: 30 # Default timeout in seconds
    
    • Update the cURL request logic to use this configurable timeout value:
    $timeout = \Drupal::config('ai_translate.settings')->get('timeout') ?: 30;
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    
    • Review and replace the deprecated usage of explode() where applicable.
    • Example replacement
    // Replace this:
    list($key, $value) = explode(':', $string);
    
    // With this:
    [$key, $value] = explode(':', $string, 2);
    
Production build 0.71.5 2024