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
50.3k stars 7.21k forks source link

DIY API interface call, unable to parse context #10037

Closed guxiyang closed 2 days ago

guxiyang commented 2 days ago

Self Checks

Dify version

0.10.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Hello, I called through the dify console and dify API interface with the same parameters. Through log queries, I found that the dify API interface call did not return any results from the node below, including session history, For example: Request parameters:

"{\n" +
"    \"inputs\": {},\n" +
\ "query \": \ "Hello \", \ n+
"    \"response_mode\": \"streaming\",\n" +
"    \"conversation_id\": \"\",\n" +
"    \"user\": \"cdb55965276fe547c21a1cebacceb6ae\",\n" +
"    \"parent_message_id\": \"\"\n" +
"}";
The dify console returns the following result:
{
"model_mode": "chat",
"prompts": [
{
"role": "user",
Text ":" Analyze my uploaded image report ",
"files": [
{
"type": "image",
"data": " https://pr... [TRUNCATED]... 64bc8b.jpg",
"detail": "high"
}
]
},
{
"role": "assistant",
Text ":" This image displays a project detail, with the following specific content: \ n \ n-Project Name: * Creatinine \ n - Result/Unit: 2769.7umol/L \ n - Reference Value: L \ n \ nCreatinine is a metabolic product mainly produced by muscle tissue and excreted through the kidneys. The level of creatinine can reflect the functional status of the kidneys. Under normal circumstances, the reference value range for creatinine varies by gender and age, but is usually between 44-133umol/L. \ n \ nThe creatinine value you provided is 2769.7umol/L, which is much higher than the normal reference value, indicating severe impairment of renal function. It is recommended that you consult a doctor as soon as possible for further examination and treatment. The,
"files": []
},
{
"role": "user",
Text: "Am I sick,
"files": []
},
{
"role": "assistant",
Text: Creatinine is a metabolic product mainly produced by muscle tissue and excreted through the kidneys. The level of creatinine can reflect the functional status of the kidneys. Under normal circumstances, the reference range for creatinine varies by gender and age, but is usually between 44-133umol/L. The creatinine value you provided is 2769.7umol/L, far higher than the normal reference value, which may indicate severe damage to kidney function. It is recommended that you consult a doctor as soon as possible for further examination and treatment,
"files": []
},
{
"role": "user",
Text: "Am I sick,
"files": []
}
],
"model_provider": "tongyi",
"model_name": "qwen-vl-max-0809"
}
The API of dify returns the following result:
{
"event":"node_finished",
"conversation_id":"c39f8541-4bde-4141-a988-5806d447f252",
"message_id":"79b7041c-a250-437d-bf07-a10ce7bea8f1",
"created_at":1730200024,
"task_id":"57e3982d-534c-4e52-938d-667ab4e6977a",
"workflow_run_id":"f3a4da97-ca5a-4c06-8c11-5a4534883ec7",
"data":{
"id":"8a18c9f3-7966-4fc0-b5f3-4a8ecadcb019",
"node_id":"1728528157692",
"node_type":"llm",
Title: "Photo Analysis",
"index":4,
"predecessor_node_id":"1728528440631",
"inputs":{
# context # ":" Am I sick? \ n
},
"process_data":{
"model_mode":"chat",
"prompts":[
{
"role":"system",
"Text": "Role Setting \ n \ nYou are the" Xiaokang Health Expert ", an exclusive health consultant launched by the Kang Boss platform, focusing on interpreting physical examination reports and test results to help users understand their health indicators. Xiaokang has a strong medical knowledge reserve and is committed to providing personalized and thoughtful report analysis and advice to users. \ n \ n1. Core Competencies Interpretation of test report: Help users interpret physical examination reports and test indicators. Being able to translate complex medical terms into easy to understand explanations, helping users understand the impact of test results on their health. \N2. Health advice: Based on the user's test results and health status, provide corresponding health advice and remind the user whether further medical treatment or lifestyle adjustments are needed. \N3. Personalized recommendation: Based on the user's health condition, timely recommend suitable health experts, products, or health content. \N \ n Tone and Style \ n \ n • Professionalism: When answering, try to use medical terminology and provide a simplified explanation of professional terms. \N • Affinity: Maintain a warm and caring tone, making users feel cared for and accompanying them like friends. \N • Concise and clear: Avoid overly complex explanations so that users can quickly understand their health status. \Interactive Method: Report Interpretation and Storage: After the detection report uploaded by the user is parsed, the parsing result is directly output and stored in the global variable globalid_health_data for subsequent follow-up use. \Multiple rounds of interpretation and questioning support: When users ask questions, relevant data will be automatically extracted from {{# globalid_health_data #}} for answering, without the need for users to repeatedly upload or explain. \N • Personalization and care: Maintain interaction in interpretation and suggestions, and provide warm and thoughtful advice based on the user's health background information. \N \ n Skill \ n \ n Skill 1: Interpretation of Test Report \ n \ n Steps: \ n \ n1 After the user uploads the detection report, analysis begins immediately to confirm the detection indicators and data. \N2. Use concise professional terminology to interpret the results, and supplement explanations in plain language to help users understand the health impact of the test results. \If the image content provided by the user contains duplicate indicators, analyze them one by one to ensure that each indicator is fully explained. \Response example: \ n \ n • Indicator analysis: Your blood sugar level is high, which may be due to high blood sugar risk caused by diet or lifestyle. \N • Xiaokang suggestion: It is recommended that you reduce sugar intake, eat more fiber rich foods, and increase physical activity. If blood sugar continues to be high, please seek medical attention promptly. \Skill 2: Health Advice and Inference \ n \ nSteps: \ n \ n1 Provide personalized health recommendations based on user reports and relevant symptoms. \N2. Provide detailed health recommendations and professional inferences about current indicators to help users better understand health risks. \Reply Example: \ n \ n • 📖  Health advice: To control your cholesterol levels, it is recommended to reduce the intake of high-fat foods and increase fish and vegetables. Cardiovascular health can be maintained through aerobic exercise. \Skill 3: Data Storage and Reference \ n \ nSteps: \ n \ n1 Store the analyzed health indicators and interpretation results as structured data in the variable globalid_health_data, ensuring that all health indicators are recorded in this variable for future reference when questioned. \N2. When users ask questions, extract relevant information from the globalid_health_data to ensure that the questions are based on previous interpretations and provide more coherent answers. \N \ n \ n Interaction Process \ n \ n1 Report interpretation and storage: After the user uploads the report, the system automatically parses and outputs the interpretation result, and stores the parsing result in the globalid_health_data for subsequent nodes to use. \N2. Follow up support: When users ask questions, automatically reference the data in globalid_health_data to ensure that the answer content refers to the previous interpretation and provides continuity support. \Example dialogue: After the user uploads the report, please help me interpret it. \AI response: Your report has been analyzed and your blood sugar level is high. It is recommended to reduce sugar intake, eat more fiber rich foods, and increase physical activity. Blood pressure and heart rate are within normal range, continue to maintain good lifestyle habits. \When asked by the user, how can I improve my high blood sugar? \AI response: According to previous test results, your blood sugar is indeed high. It is recommended to control sugar intake and eat more fiber rich foods, such as whole grains and vegetables. Engage in at least 150 minutes of moderate intensity aerobic exercise per week, such as walking or cycling. In addition, regular monitoring of blood sugar changes can help better control health status. \N \ n Precautions \ n \ n • Hidden Storage Information: The content in globalid_health_data is only for internal system reference and is not displayed to users. \Data consistency: Ensure the consistency and accuracy of data when asked by users, avoiding repeated uploads or explanations. \Warm care: After each interpretation and questioning, maintain a warm and caring tone to provide continuous care for users. ",
"files":[ ]
},
{
"role":"user",
Text: "Am I sick?",
"files":[ ]
}
],
"model_provider":"tongyi",
"model_name":"qwen-vl-max-0809"
},
"outputs":{
To accurately answer your question, I need to know your recent medical examination report or any changes in your health condition that you have noticed. Please provide your medical examination report or describe any symptoms you have encountered so that I can provide you with more specific health advice,
"usage":{
"prompt_tokens":946,
"prompt_unit_price":"0.02",
"prompt_price_unit":"0.001",
"prompt_price":"0.0189200",
"completion_tokens":46,
"completion_unit_price":"0.02",
"completion_price_unit":"0.001",
"completion_price":"0.0009200",
"total_tokens":992,
"total_price":"0.0198400",
"currency":"RMB",
"latency":3.0229253279976547
},
"finish_reason":"stop"
},
"status":"succeeded",
"error":null,
"elapsed_time":3.094172,
"execution_metadata":{
"total_tokens":992,
"total_price":"0.0198400",
"currency":"RMB"
},
"created_at":1730200023,
"finished_at":1730200026,
"files":[ ],
"parallel_id":null,
"parallel_start_node_id":null,
"parent_parallel_id":null,
"parent_parallel_start_node_id":null,
"iteration_id":null
}
}

I don't know why these two returned differently. Is it a bug? I hope it can be resolved, According to our understanding, the DIY console can parse the user's context, but the DIY API interface cannot parse the context. Could you please help us take a look.

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

dosubot[bot] commented 2 days ago

@guxiyang Hello there! I'm here to assist you with any bugs, questions, or contributions you might have. Let me know how I can help you today!

The issue you're experiencing with the Dify API not parsing context as expected, while the Dify console does, could be related to differences in how session history and context management are handled between the two interfaces. The Dify API uses a conversation_id to manage session history and context. When starting a new conversation, the conversation_id should be left empty, and the system will generate a new one. This ID must be included in subsequent API calls to maintain the conversation flow [1].

If the API is not returning the expected context, ensure that the conversation_id is being used correctly in your API calls. Additionally, check if there are any configuration settings or parameters affecting context parsing, such as retrieval settings, weighted scores, or score thresholds, which might be influencing the API's behavior [2].

If these aspects are correctly configured and the issue persists, it might be worth investigating further into the specific implementation details or any potential discrepancies between the console and API logic.

To continue talking to Dosu, mention @dosu.

guxiyang commented 2 days ago

@dosu.Hello, I'm not sure if it's a problem with the dify version. I used version 0.10.1 before and I want to upgrade to version 0.10.2 to see if it works. In version 0.10.1, my chatflow workflow is set up very simply without any settings. But when calling the DIY API interface, it still says that it cannot return the history record in the prompts node. Could you please provide more detailed information "prompts":[ { "role":"system", Text ":" Character setting \ n \ nYou are ssss ", "files":[ ] }, { "role":"user", Text: "Am I sick, "files":[ ] } ],

@.***

From: dosubot[bot] Date: 2024-10-30 11:38 To: langgenius/dify CC: 顾夕•D; Mention Subject: Re: [langgenius/dify] DIY API interface call, unable to parse context (Issue #10037) @guxiyang Hello there! I'm here to assist you with any bugs, questions, or contributions you might have. Let me know how I can help you today! The issue you're experiencing with the Dify API not parsing context as expected, while the Dify console does, could be related to differences in how session history and context management are handled between the two interfaces. The Dify API uses a conversation_id to manage session history and context. When starting a new conversation, the conversation_id should be left empty, and the system will generate a new one. This ID must be included in subsequent API calls to maintain the conversation flow [1]. If the API is not returning the expected context, ensure that the conversation_id is being used correctly in your API calls. Additionally, check if there are any configuration settings or parameters affecting context parsing, such as retrieval settings, weighted scores, or score thresholds, which might be influencing the API's behavior [2]. If these aspects are correctly configured and the issue persists, it might be worth investigating further into the specific implementation details or any potential discrepancies between the console and API logic. To continue talking to Dosu, mention @dosu. ― Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

dosubot[bot] commented 2 days ago

I couldn't find specific information about changes between Dify versions 0.10.1 and 0.10.2, so it's unclear if upgrading will resolve your issue. However, to address the problem with the Dify API not returning session history, ensure that the conversation_id is correctly managed. When starting a new conversation, leave the conversation_id empty to let the system generate one, and use this ID in subsequent API calls to maintain context [1].

Additionally, check the configuration settings affecting context parsing, such as model parameters and advanced settings like memory and context variables, which can influence how the API processes session history [2]. If these are correctly set and the issue persists, it might be worth exploring any discrepancies between the console and API logic further.

To continue talking to Dosu, mention @dosu.

guxiyang commented 2 days ago

Okay, I'll give it a try later. First, upgrade the version to 0.10.2, and then I'll call it through the API interface. If it doesn't work, I'll need you to check if you have any contact information, such as phone or email, so we can communicate more effectively,

@.***

From: dosubot[bot] Date: 2024-10-30 12:04 To: langgenius/dify CC: 顾夕旸; Mention Subject: Re: [langgenius/dify] DIY API interface call, unable to parse context (Issue #10037) I couldn't find specific information about changes between Dify versions 0.10.1 and 0.10.2, so it's unclear if upgrading will resolve your issue. However, to address the problem with the Dify API not returning session history, ensure that the conversation_id is correctly managed. When starting a new conversation, leave the conversation_id empty to let the system generate one, and use this ID in subsequent API calls to maintain context [1]. Additionally, check the configuration settings affecting context parsing, such as model parameters and advanced settings like memory and context variables, which can influence how the API processes session history [2]. If these are correctly set and the issue persists, it might be worth exploring any discrepancies between the console and API logic further. To continue talking to Dosu, mention @dosu. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

dosubot[bot] commented 2 days ago

This is a tough nut to crack, could really use your help on this, @takatost.

To continue talking to Dosu, mention @dosu.

guxiyang commented 2 days ago

@dosu.Hello, I'm not sure if it's a problem with the dify version. I used version 0.10.1 before and I want to upgrade to version 0.10.2 to see if it works. In version 0.10.1, my chatflow workflow is set up very simply without any settings. But when calling the DIY API interface, it still says that it cannot return the history record in the prompts node. Could you please provide more detailed information @takatost

crazywoola commented 2 days ago

I don't think we have this function yet.