tongyi model get_num_tokens always returns 0 #248

Closed
opened 2026-02-16 10:18:35 -05:00 by yindo · 2 comments
Owner

Originally created by @zhenliuxc on GitHub (Apr 30, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

v1.1.2

Plugin version

tongyi-0.0.16

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I tried to get the token nums for prompt messages from '/dispatch/llm/num_tokens', but it always returns 0 when using the Tongyi model.

✔️ Error log

if self.get_customizable_model_schema(model, credentials) is not None:
return 0

When debugging the problem, I found that because get_customizable_model_schema always returns a non-None value, the function get_num_tokens always returns 0. Why was get_customizable_model_schema added?

Originally created by @zhenliuxc on GitHub (Apr 30, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version v1.1.2 ### Plugin version tongyi-0.0.16 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I tried to get the token nums for prompt messages from '/dispatch/llm/num_tokens', but it always returns 0 when using the Tongyi model. ### ✔️ Error log [ if self.get_customizable_model_schema(model, credentials) is not None: return 0](https://github.com/langgenius/dify-official-plugins/blob/deaa4c9596d128aaefbc48b101bf077a23d0f8b3/models/tongyi/models/llm/llm.py#L117) When debugging the problem, I found that because **get_customizable_model_schema** always returns a non-None value, the function **get_num_tokens** always returns 0. Why was **get_customizable_model_schema** added?
yindo added the bug label 2026-02-16 10:18:35 -05:00
yindo closed this issue 2026-02-16 10:18:35 -05:00
Author
Owner

@zhenliuxc commented on GitHub (Apr 30, 2025):

@Yeuoly

@zhenliuxc commented on GitHub (Apr 30, 2025): @Yeuoly
Author
Owner

@dosubot[bot] commented on GitHub (Aug 17, 2025):

Hi, @zhenliuxc. I'm Dosu (https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that the Tongyi model's get_num_tokens function always returns 0.
  • This happens because get_customizable_model_schema returns a non-None value, causing an early return.
  • You questioned the rationale behind adding get_customizable_model_schema as it disrupts token count retrieval via '/dispatch/llm/num_tokens'.
  • The only comment on the issue is a brief mention of @Yeuoly without further discussion.
  • The issue remains unresolved.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here.
  • If I do not hear back within 5 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 17, 2025): Hi, @zhenliuxc. I'm Dosu (https://dosu.dev), and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale. Issue Summary: - You reported that the Tongyi model's get_num_tokens function always returns 0. - This happens because get_customizable_model_schema returns a non-None value, causing an early return. - You questioned the rationale behind adding get_customizable_model_schema as it disrupts token count retrieval via '/dispatch/llm/num_tokens'. - The only comment on the issue is a brief mention of @Yeuoly without further discussion. - The issue remains unresolved. Next Steps: - Please let me know if this issue is still relevant with the latest version of the dify-official-plugins repository by commenting here. - If I do not hear back within 5 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#248