dify icon indicating copy to clipboard operation
dify copied to clipboard

fix: max_tokens set to 1000 for "auto_generate_name"

Open yzztin opened this issue 10 months ago • 7 comments

Summary

Close https://github.com/langgenius/dify/issues/14246

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

[!Tip] Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

Screenshots

Before After
... ...

Checklist

[!IMPORTANT]
Please review the checklist below before submitting your pull request.

  • [ ] This change requires a documentation update, included: Dify Document
  • [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.
  • [x] I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

yzztin avatar Feb 24 '25 07:02 yzztin

I actually don't konw is it reasonable to set max_tokens be 1000, just in my case, it worked.

yzztin avatar Feb 24 '25 08:02 yzztin

I actually don't konw is it reasonable to set max_tokens be 1000, just in my case, it worked.

I don't think this is a good idea, because you have more token consumption later.

crazywoola avatar Feb 25 '25 09:02 crazywoola

我实际上不知道这样设置是否合理max_tokens1000但就我的情况而言,它有效。

May I ask how the code modification will take effect? I will use it in sequence: docker compose down docker compose pull docker compose up -d The result still doesn't work

I actually don't konw is it reasonable to set max_tokens be 1000, just in my case, it worked.

@yzztin May I ask how the code modification will take effect? I will use it in sequence: docker compose down docker compose pull docker compose up -d The result still doesn't work

MrWangChong avatar Feb 26 '25 03:02 MrWangChong

@MrWangChong @littlebox692 If you want to resolve the problem not gracefully, you can change the max_token like me. Steps for changing code in container:

  1. use GUI tools go into the dify api container like vscode docker plugin
  2. find the code in app/api/core/llm_generator/llm_generator.py, the functions is generate_conversation_name()
  3. change the code nearly line 51: (just make the max_tokens bigger, a num which is enough for you)
original code: prompt_messages=prompts, model_parameters={"max_tokens": 100, "temperature": 1}, stream=False
changed code: prompt_messages=prompts, model_parameters={"max_tokens": 1000, "temperature": 1}, stream=False
  1. restart the container, but not down, also you can docker commit it.

But, attention, it's not a good idea like @crazywoola said. What I recommend is waiting the official solution.

yzztin avatar Feb 26 '25 06:02 yzztin

@MrWangChong @littlebox692 If you want to resolve the problem not gracefully, you can change the max_token like me. Steps for changing code in container:

  1. use GUI tools go into the dify api container like vscode docker plugin
  2. find the code in app/api/core/llm_generator/llm_generator.py, the functions is generate_conversation_name()
  3. change the code nearly line 51: (just make the max_tokens bigger, a num which is enough for you)
original code: prompt_messages=prompts, model_parameters={"max_tokens": 100, "temperature": 1}, stream=False
changed code: prompt_messages=prompts, model_parameters={"max_tokens": 1000, "temperature": 1}, stream=False
  1. restart the container, but not down, also you can docker commit it.

But, attention, it's not a good idea like @crazywoola said. What I recommend is waiting the official solution.

@yzztin Thank you for your response I am certain that I have modified the max_token and restarted Docker. But it still hasn't taken effect. This problem should only occur with deepseek-r1. I have tried switching to qwen2.5 and deepseek-v2, but still have this issue.

MrWangChong avatar Feb 26 '25 09:02 MrWangChong

How about truncating the promptMessage text (e.g., [:100]) or making the max token limit configurable by users—or both?

fdb02983rhy avatar Mar 23 '25 15:03 fdb02983rhy

Will this issue be further optimized or fixed?

hiwuye avatar Mar 25 '25 00:03 hiwuye