Try and get LLMs to return content matching the language of the original content#357
Try and get LLMs to return content matching the language of the original content#357dkotter wants to merge 6 commits intoWordPress:developfrom
Conversation
…n content matching the language given
…ontent matching the language given
…urn content matching the language given
…ons and update those instructions to prompt the LLM to return content matching either the language of the context or the site language
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #357 +/- ##
=============================================
+ Coverage 57.70% 57.76% +0.06%
Complexity 617 617
=============================================
Files 46 46
Lines 3173 3180 +7
=============================================
+ Hits 1831 1837 +6
- Misses 1342 1343 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
While reviewing this PR, I noticed a pre-existing bug in This doesn't block this PR, but it could affect alt text generation if called multiple times in a single request (e.g., batch processing images). Opened #358 with a failing test and one-line fix ( |
There was a problem hiding this comment.
I tested this with a post written in Polish.
English site locale + Polish content:
| Feature | Language | Expected |
|---|---|---|
| Excerpt | Polish ✅ | Polish |
| Summary | English ❌ | Polish |
| Alt text | English ❌ | Polish (from content) or English (from locale) |
Polish site locale + Polish content:
| Feature | Language | Expected |
|---|---|---|
| Excerpt | Polish ✅ | Polish |
| Summary | Polish ✅ | Polish |
| Alt text | English ❌ | Polish |
Excerpt generation consistently respects content language, which is great. Summary only matched Polish when the site locale was also set to Polish — suggesting the LLM may not reliably follow the instruction when the default locale is English. Alt text returned English in all cases, even with Polish locale — the model seems to disregard the locale instruction entirely when working from an image alone.
(Page was refreshed before each action to ensure clean state.)
Aside, it might be not trivial to instruct LLM about the language for the alt image, as it largely depend on the context. In the Media library modal, it should probably will always default to the site's locale. However, in the post, you would need to pass some content so LLM can infer the language from it.
What?
Closes #349, #351
Update some of our system instructions to prompt the LLM to return content in the same language as the original content they were given.
Why?
At the moment, you may get content returned from an LLM that isn't the same as your original content. For example, if you have a post that is written in French and you generate a title, the title may be in English (though in my testing, it always returned in French).
Ideal is to have the LLMs match the language of the content they were given. This supports the widest amount of use cases, like multi-lingual sites.
How?
Updates the system instructions for any Ability that generates user-facing text to tell the LLM to match the language of the content they were given.
For alt text generation, we may not have other content (say when generating alt text straight in the media library) so we pass the site locale to use as our default.
Worth noting it's still up to the LLM to follow these instructions so there's almost certainly edge cases that this won't work for, particularly if using a smaller model.
Use of AI Tools
None
Testing Instructions