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
51.81k stars 7.51k forks source link

API interface to get the next round of problem suggestions, the interface sometimes returns a different structure #8795

Closed 1192603654 closed 1 month ago

1192603654 commented 1 month ago

Self Checks

Dify version

0.8.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

image

The JSON structure may appear when the actual call is made

1727339198788

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

crazywoola commented 1 month ago

It depends on what llm you choose.

dosubot[bot] commented 1 month ago

Hey @1192603654! 👋 I'm here to help you with any bugs, questions, or contributions you have in mind. I'm Dosu, a bot designed to assist you while you wait for a human maintainer.

I found a similar issue that was previously discussed and closed. The issue was about the get_suggested_questions_after_answer function returning a different data structure. The discrepancy was due to the function's design in Dify version 0.6.7, where it returns an array of objects with a "question" key instead of a simple array of strings. This design allows for handling rich metadata associated with each question [1].

Additionally, the API interface for getting the next round of problem suggestions sometimes returns a different JSON structure because the JSON Schema output must be enabled and properly configured in the application settings. If the JSON Schema is not enabled or the schema template is not correctly defined, the output structure may vary. To ensure consistent JSON structure, follow these steps:

  1. Switch the LLM to a model that supports JSON Schema output.
  2. Enable JSON Schema in the settings form.
  3. Input the correct JSON Schema template.
  4. Set the response_format to json_schema.

Here is an example of a JSON Schema template:

{
    "name": "template_schema",
    "description": "JSON Schemaの汎用テンプレート",
    "strict": true,
    "schema": {
        "type": "object",
        "properties": {
            "field1": {
                "type": "string",
                "description": "field1の説明"
            },
            "field2": {
                "type": "number",
                "description": "field2の説明"
            },
            "field3": {
                "type": "array",
                "description": "field3の説明",
                "items": {
                    "type": "string"
                }
            },
            "field4": {
                "type": "object",
                "description": "field4の説明",
                "properties": {
                    "subfield1": {
                        "type": "string",
                        "description": "subfield1の説明"
                    }
                },
                "required": ["subfield1"],
                "additionalProperties": false
            }
        },
        "required": ["field1", "field2", "field3", "field4"],
        "additionalProperties": false
    }
}

Ensure that the JSON Schema is correctly defined and applied to maintain a consistent JSON structure in the API responses [2].

To continue talking to Dosu, mention @dosu.

1192603654 commented 1 month ago

image It uses workflow orchestration, ChatGPT-4O's LLM