Problem/Motivation

When using the Mistral provider with AI Logging enabled, non-streamed chat responses are logged as {} (empty JSON object) instead of the actual response data.
the ai_provider_mistral module passes a Partitech\PhpMistral\Clients\Response object directly to ChatOutput,
but this object has private properties and doesn't implement JsonSerializable, so json_encode() returned {}

Steps to reproduce

1. Install ai_provider_mistral 1.1.0-beta1 and ai_logging
2. Configure Mistral as the default chat provider
3. Enable "Log AI responses" in AI Logging settings
4. Use any AI Suggestion feature without streaming
5. Check AI Logs at /admin/reports/ai-logging

Proposed resolution

Convert the response to an array and then use it when returning ChatOutput

Remaining tasks

User interface changes

API changes

Data model changes

Command icon 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

petar_basic created an issue. See original summary.

petar_basic’s picture

Assigned: petar_basic » Unassigned
Status: Active » Needs review
StatusFileSize
new2.45 KB

The Partitech\PhpMistral\Clients\Response object passed to ChatOutput as rawOutput has private properties and doesn't implement JsonSerializable, causing json_encode() to return {} in AI logs. Fixed by adding a responseToArray() helper that extracts the response data (id, model, usage, choices) into a serializable array.

fago’s picture

Status: Needs review » Needs work
Issue tags: +needs tags

thx, looks good, but it shows our test-coverage is lacking there also -> exactly this missing piece we should make sure we have test-coverage for. Let's add this with the fix!

fago’s picture

Issue tags: -needs tags +Needs tests
petar_basic’s picture

Status: Needs work » Needs review

Added tests, please check

  • fago committed 29f167d2 on 1.1.x authored by petar_basic
    fix: #3568834 Fix responses being logged empty in the AI log
    
    By:...
fago’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

thx, the tests smell like AI, but good enough. Merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.