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

The API call results for the workflow orchestration dialogue application cannot properly display the consumed token values and prices. #8873

Open cabinai opened 13 hours ago

cabinai commented 13 hours ago

Self Checks

Dify version

0.8.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

The API call results for the workflow orchestration dialogue application cannot properly display the consumed token values and prices.

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

dosubot[bot] commented 13 hours ago

I found some similar issues that might be relevant to your problem:

  1. Upgrade to 0.8.3, metadata still lacks the return of token usage information - This issue was closed by a pull request on September 23, 2024.
  2. Can't get usage info in metadata object - This issue was also closed and was last updated on September 21, 2024.

The problem with displaying consumed token values and prices in Dify version 0.8.3 is due to the execution_metadata object being nested within the data object of the node_finished event. This structure might not be correctly parsed or displayed by the application. Here is the relevant part of the response:

data: {"event": "node_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "execution_metadata": {"total_tokens": 63127864, "total_price": 2.378, "currency": "USD"},  "created_at": 1679586595}}

The execution_metadata object is within the data object, and if the application does not correctly parse this nested structure, it will not display the total_tokens and total_price values properly [1].

To address this issue, you might want to check how the execution_metadata object is parsed and displayed in the UI. The execution_metadata object is parsed and displayed in the UI through the execution_metadata_dict property in the WorkflowRun class. This property parses the execution_metadata JSON string into a dictionary [2].

Additionally, the LangSmithDataTrace class in api/core/ops/langsmith_trace/langsmith_trace.py also parses the execution_metadata object when handling workflow traces [3].

In the UI, the execution_metadata object is also parsed and displayed in the TracingPanel component located in web/app/components/workflow/run/tracing-panel.tsx [4].

You might want to ensure that these components correctly parse and display the execution_metadata object to resolve the issue.

To continue talking to Dosu, mention @dosu.

cabinai commented 13 hours ago

I use the formula blocking