langgenius / dify-docs

The open-source repo for docs.dify.ai
Creative Commons Attribution 4.0 International
197 stars 176 forks source link

Example Response of External Knowledge API #312

Closed zolgear closed 4 weeks ago

zolgear commented 1 month ago

https://docs.dify.ai/guides/knowledge-base/external-knowledge-api-documentation

en\guides\knowledge-base\external-knowledge-api-documentation.md


There is an issue with the JSON response generated by Swagger.

{
  "records": {
    "content": "text",
    "score": 0,
    "title": "text",
    "metadata": "text"
  }
}

The records should be an array, but it is represented with { }. If implemented as is, it will result in a "500 Internal Server Error: 'str' object has no attribute 'get'" during the hit test in /app/api/controllers/console/datasets/external.py.

Fix:

{
  "records": [
    {
      "content": "text",
      "score": 0,
      "title": "text",
      "metadata": "text"
    }
  ]
}

Can you modify en\.gitbook\assets\Dify-test.openapi.json to fix it?

dosubot[bot] commented 1 month ago

To fix the issue with the records field in the Dify-test.openapi.json file, you need to modify the schema to ensure records is an array. Here's how you can update it:

Change the records field definition from an object to an array of objects:

"records": {
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "content": {
        "type": "string",
        "description": "Contains a chunk of text from a data source in the knowledge base."
      },
      "score": {
        "type": "number",
        "format": "float",
        "description": "The score of relevance of the result to the query, scope: 0~1"
      },
      "title": {
        "type": "string",
        "description": "Document title"
      },
      "metadata": {
        "type": "string",
        "description": "Contains metadata attributes and their values for the document in the data source."
      }
    },
    "required": ["content", "score", "title"]
  },
  "title": "A list of records from querying the knowledge base."
}

This change will ensure that the records field is correctly formatted as an array, preventing the "500 Internal Server Error" [1].

To continue talking to Dosu, mention @dosu.

zolgear commented 4 weeks ago

Thank you for making these changes.