Commit 160bf91
language_models: Filter out whitespace-only text content parts for OpenAI and OpenAI compatible providers (#40316)
Closes #40097
When multiple files are added sequentially to the agent panel, the
request JSON incorrectly includes "text" elements containing only
spaces. These empty elements cause the Zhipu AI API to return a "text
cannot be empty" error.
The fix filters out any "text" elements that are empty or contain only
whitespaces.
UI state when the error occurs:
<img width="300" alt="Image"
src="https://github.com/user-attachments/assets/c55e5272-3f03-42c0-b412-fa24be2b0043"
/>
Request JSON (causing the error):
```
{
"model": "glm-4.6",
"messages": [
{
"role": "system",
"content": "<<CUT>>"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "[@1.txt](zed:///agent/file?path=C%3A%5CTemp%5CTest%5C1.txt)"
},
{ "type": "text", "text": " " },
{
"type": "text",
"text": "[@2.txt](zed:///agent/file?path=C%3A%5CTemp%5CTest%5C2.txt)"
},
{ "type": "text", "text": " describe" },
```
Release Notes:
- Fixed an issue when an OpenAI request contained whitespace-only text content
Co-authored-by: Bennet Bo Fenner <[email protected]>1 parent aff4c25 commit 160bf91
1 file changed
+7
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
364 | 366 | | |
365 | 367 | | |
366 | 368 | | |
| |||
0 commit comments