Skip to content

Conversation

dkotter
Copy link
Contributor

@dkotter dkotter commented Sep 11, 2025

As described in #89, if you use a reasoning model, the content returned contains both reasoning_content and content items. The reasoning_content is always first in the array and so when toText is returned, reasoning_content will always be returned instead of content.

This PR adjusts the logic of those methods to only return items that are in the content channel.

May be worth a discussion on if we:

  1. Want methods that allow you to pass in what channel type you want instead of hardcoding that to content. Right now if you want the reasoning_content, you'd have to parse that out yourself from the response instead of using the built-in helper methods
  2. Is there any risk to only returning the content channel? For instance, if an LLM for some reason only returns the reasoning result, this new approach will return nothing (or will throw an exception). I debated modifying these methods to fallback to returning the first result if we don't find any result that matches the content channel but wasn't sure if we actually wanted it to function that way

Copy link

github-actions bot commented Sep 11, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkotter Thank you for fixing this! The PR changes a bit more than fixing the bug, so I think that needs to be simplified.

The other part is that this exact same bug can also occur for all the other to*() methods in GenerativeAiResult, so I think we should fix it there too to only return content bits. Granted, it's likely impossible as of today for any provider to include things like images etc in "thought" or "reasoning", but as per the DTO it's in principle possible. So ideally we adjust all these similar methods to only consider "content" parts.

@felixarntz felixarntz added this to the 0.2.0 milestone Sep 11, 2025
@felixarntz felixarntz added the [Type] Bug An existing feature does not function as intended label Sep 11, 2025
@dkotter
Copy link
Contributor Author

dkotter commented Sep 11, 2025

The other part is that this exact same bug can also occur for all the other to*() methods in GenerativeAiResult, so I think we should fix it there too to only return content bits. Granted, it's likely impossible as of today for any provider to include things like images etc in "thought" or "reasoning", but as per the DTO it's in principle possible. So ideally we adjust all these similar methods to only consider "content" parts

I've updated the toFile and toFiles methods now to have the same check, which the following methods all end up using one of those two:

  • toImageFile
  • toAudioFile
  • toVideoFile
  • toImageFiles
  • toAudioFiles
  • toVideoFiles

There's also toMessage and toMessages but seems like we'd want those to return the entire Message object and not remove extra details (like reasoning_content) but let me know if I should update those as well

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkotter Looks great! Just making some minor doc nit-pick updates.

You're completely right regarding toMessage() and toMessages(), these should maintain the messages as is.

@felixarntz felixarntz merged commit 861ab5f into WordPress:trunk Sep 11, 2025
5 checks passed
@dkotter dkotter deleted the fix/89 branch September 11, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants