Problem/Motivation
The chat() method signature accepts array|string|ChatInput, but when a string is passed, line 312 calls $input->isStreamedOutput() on the string, causing a fatal error.
Steps to reproduce
$provider = \Drupal::service("ai.provider")->createInstance("mistral");
$provider->chat("Hello", "mistral-small-latest");
// Error: Call to a member function isStreamedOutput() on string Proposed resolution
Normalize string and array inputs to ChatInput at the start of the chat() method, matching the interface contract. Additionally, guard the isStreamedOutput() call to only apply for ChatInput objects.
- String input: Convert to ChatInput with a single user message
- Array input: Convert to ChatInput by mapping array elements to ChatMessage objects
- Add type check before calling $input->isStreamedOutput()
Remaining tasks
Issue fork ai_provider_mistral-3570605
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
petar_basic commentedAdded support for string and array input types as declared in the ChatInterface.
Also added 2 tests for string & array as parms to the chat.
to test, with a valid API key configured:
There should be no error in any of the runs
Comment #5
fagoMakes sense and works, however since we normalized the input to ChatInput we should simplify the code to not check it afterwards any more. Adding that, otherwise all good
Comment #7
fagochange works + pass tests - merged!