Skip to content

language_models: Skip empty delta text content in OpenAI and OpenAI compatible provider#37626

Merged
benbrandt merged 1 commit intozed-industries:mainfrom
imumesh18:push-tqymyqxrlsmt
Sep 6, 2025
Merged

language_models: Skip empty delta text content in OpenAI and OpenAI compatible provider#37626
benbrandt merged 1 commit intozed-industries:mainfrom
imumesh18:push-tqymyqxrlsmt

Conversation

@imumesh18
Copy link
Contributor

@imumesh18 imumesh18 commented Sep 5, 2025

Closes #37302

Related: #37614

In case of open_ai_compatible providers like Zhipu AI and z.ai they return empty content along with usage data. below is the example json captured from z.ai. We now ignore empty content returned by providers now to avoid this issue where we would return the same empty content back to provider which would error out.

OpenAI Stream Response JSON:
{
  "id": "2025090518465610d80dc21e66426d",
  "created": 1757069216,
  "model": "glm-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "tool_calls",
      "delta": {
        "role": "assistant",
        "content": ""
      }
    }
  ],
  "usage": {
    "prompt_tokens": 7882,
    "completion_tokens": 150,
    "total_tokens": 8032,
    "prompt_tokens_details": {
      "cached_tokens": 7881
    }
  }
}

Release Notes:

  • Skip empty delta text content in OpenAI and OpenAI compatible provider

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 5, 2025
…ible

provider

Signed-off-by: Umesh Yadav <git@umesh.dev>
@imumesh18
Copy link
Contributor Author

@dhbrojas, I have fixed the issue for z.ai. I have tested it and thanks for the keys. Can you also try this branch and see it has fixed the issue for you as well.

@imumesh18 imumesh18 changed the title language_models: Skip empty delta content in OpenAI and OpenAI compatible provider language_models: Skip empty delta text content in OpenAI and OpenAI compatible provider Sep 5, 2025
@dhbrojas
Copy link

dhbrojas commented Sep 5, 2025

It works perfectly! Thanks a lot @imumesh18 ❤️

Screenshot 2025-09-05 at 13 39 17

@dhbrojas
Copy link

dhbrojas commented Sep 5, 2025

Oh, actually, I'm getting an error in the logs:

2025-09-05T13:42:29+02:00 ERROR [agent::thread] Failed to generate thread summary: API request to https://api.z.ai/api/paas/v4 failed: messages[1].content[0].text:不能为空

It seems the same pattern is used when handling summaries.

@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Sep 5, 2025
@imumesh18
Copy link
Contributor Author

So the normal chat works after this change only the thread errors are getting logged right now disruption in the agent panel? Will check that as well. Might be related to thread summary loop or something all together different.

@dhbrojas
Copy link

dhbrojas commented Sep 5, 2025

So the normal chat works after this change only the thread errors are getting logged right now disruption in the agent panel?

There is no visible disruption in the agent panel. Simply a log line. The normal chat works.

@imumesh18
Copy link
Contributor Author

imumesh18 commented Sep 5, 2025

Okay not been able to trigger that log. Also in your agent panel does the thread has title for the thread you saw the error for? If yes then this might be from some previous thread or different issue 🤔 .
Will try few more times to see if I can generate that error but seems to be not being able to hit that error easily.

Copy link
Member

@benbrandt benbrandt left a comment

Choose a reason for hiding this comment

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

Seems like a valid improvement. thanks!

@benbrandt benbrandt merged commit 8c9442a into zed-industries:main Sep 6, 2025
26 checks passed
@imumesh18 imumesh18 deleted the push-tqymyqxrlsmt branch September 9, 2025 22:59
tidely pushed a commit to tidely/zed that referenced this pull request Sep 10, 2025
…ompatible provider (zed-industries#37626)

Closes zed-industries#37302 

Related: zed-industries#37614 

In case of open_ai_compatible providers like Zhipu AI and z.ai they
return empty content along with usage data. below is the example json
captured from z.ai. We now ignore empty content returned by providers
now to avoid this issue where we would return the same empty content
back to provider which would error out.

```
OpenAI Stream Response JSON:
{
  "id": "2025090518465610d80dc21e66426d",
  "created": 1757069216,
  "model": "glm-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "tool_calls",
      "delta": {
        "role": "assistant",
        "content": ""
      }
    }
  ],
  "usage": {
    "prompt_tokens": 7882,
    "completion_tokens": 150,
    "total_tokens": 8032,
    "prompt_tokens_details": {
      "cached_tokens": 7881
    }
  }
}
```

Release Notes:

- Skip empty delta text content in OpenAI and OpenAI compatible provider

Signed-off-by: Umesh Yadav <git@umesh.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI: Zhipu AI is incompatible with openai_compatible provider

4 participants