Call to undefined method OpenAiChatMessageIterator::getTools()

Created on 23 April 2025, 1 day ago

Problem/Motivation

When an AI provider doesn't implement the getTools() method, using the chat can result in this error:
https://www.drupal.org/project/ai_provider_openai/issues/3515885 🐛 Streaming chat responses gives Call to undefined method Drupal\ai_provider_openai\OpenAiChatMessageIterator::getTools() Active

The website encountered an unexpected error. Try again later.

Error: Call to undefined method Drupal\ai_provider_openai\OpenAiChatMessageIterator::getTools() in Drupal\ai_api_explorer\Plugin\AiApiExplorer\ChatGenerator->getResponse() (line 306 of modules/contrib/ai/modules/ai_api_explorer/src/Plugin/AiApiExplorer/ChatGenerator.php).
Drupal\ai_api_explorer\Plugin\AiApiExplorer\ChatGenerator->submitForm() (Line: 71)
Drupal\ai_api_explorer\Form\AiApiExplorerForm->submitForm()
call_user_func_array() (Line: 105)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 43)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 589)
Drupal\Core\Form\FormBuilder->processForm() (Line: 144)
Drupal\autosave_form\Form\AutosaveFormBuilder->processForm() (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 97)
Drupal\autosave_form\Form\AutosaveFormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Fresh install of 1.1, set up chat with OpenAI.

Proposed resolution

Have a check to see if getTools() is implemented, prior to calling it.

API changes

Nothing.

🐛 Bug report
Status

Active

Version

1.1

Component

AI Core module

Created by

🇨🇦Canada RobLoach Earth

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024