langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
46.76k stars 6.61k forks source link

fix:Spark's large language model token calculation error #7911 #8755

Closed cherryhuahua closed 3 days ago

cherryhuahua commented 3 days ago

Checklist:

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

Description

The submitted this bug fixes the https://github.com/langgenius/dify/issues/7911, cause the language model of 1, the Spark at the end of the returned flow without a clear identity, so every time back to have the usage the value, However, the _handle_invoke_result_stream method in base_app_runner.py checks whether usage exists. If it exists, it is no longer assigned. As a result, usage only stores the value of the iterator.

  1. In the llm.py file of Spark's large language model, the _handle_generate_stream_response method completion_tokens calculates the value in each iteration without adding up

Fixes #7911

Type of Change

Testing Instructions

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration