Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in calculating the correct total in the workflow. Remove the number of tokens in the loop #8414

Closed
5 tasks done
minhkhacoder opened this issue Sep 14, 2024 · 2 comments
Labels
🐞 bug Something isn't working

Comments

@minhkhacoder
Copy link

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 search for existing issues, 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

v.0.8.2

Cloud or Self Hosted

Cloud, Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

image
image

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

@minhkhacoder
Copy link
Author

image

@dosubot dosubot bot added the 🐞 bug Something isn't working label Sep 14, 2024
Copy link

dosubot bot commented Sep 14, 2024

Chào @minhkhacoder! Tôi là Dosu, một bot có thể giúp bạn giải quyết lỗi, trả lời câu hỏi và trở thành một người đóng góp. Tôi ở đây để giúp bạn trong khi đợi người duy trì hệ thống. 🤖

To fix the error in calculating the correct total in the workflow by removing the number of tokens in the loop, you need to modify the section where the total tokens are being incremented. Specifically, you should remove or adjust the part where self.graph_runtime_state.total_tokens is being updated within the loop.

Here is the relevant part of the code that needs to be modified:

if run_result.status == WorkflowNodeExecutionStatus.SUCCEEDED:
    if run_result.metadata and run_result.metadata.get(NodeRunMetadataKey.TOTAL_TOKENS):
        # plus state total_tokens
        self.graph_runtime_state.total_tokens += int(
            run_result.metadata.get(NodeRunMetadataKey.TOTAL_TOKENS)  # type: ignore[arg-type]
        )

To remove the number of tokens in the loop, you can simply comment out or delete the lines that update self.graph_runtime_state.total_tokens:

if run_result.status == WorkflowNodeExecutionStatus.SUCCEEDED:
    if run_result.metadata and run_result.metadata.get(NodeRunMetadataKey.TOTAL_TOKENS):
        # Comment out or remove the following lines to stop updating total_tokens
        # self.graph_runtime_state.total_tokens += int(
        #     run_result.metadata.get(NodeRunMetadataKey.TOTAL_TOKENS)  # type: ignore[arg-type]
        # )

By doing this, the total tokens will no longer be incremented within the loop, which should fix the error in calculating the correct total in the workflow [1].

To continue talking to Dosu, mention @dosu.

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 15, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant