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.05k stars 7.15k forks source link

When calling the API to update segments, the answer field cannot be updated correctly. #6563

Closed dc-vin closed 2 months ago

dc-vin commented 3 months ago

Self Checks

Dify version

0.6.9

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When calling the API to update segments, the answer field cannot be updated correctly.

QQ_1721717982523

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

dosubot[bot] commented 3 months ago

To resolve the issue where the "answer" field cannot be updated correctly when calling the API to update segments in Dify version 0.6.9 (self-hosted using Docker), ensure that the API call for updating segments is correctly formatted and that the necessary fields are included in the request. Here is an example of how to update a segment:

curl --location --request PATCH 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/segments/{segment_id}' \
  --header 'Authorization: Bearer {api_key}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "content": "Updated content",
    "answer": "Updated answer",
    "keywords": ["Updated", "Keywords"]
  }'

Replace {dataset_id}, {document_id}, and {segment_id} with the actual IDs of your dataset, document, and segment, and {api_key} with your actual API key. This should correctly update the segment, including the "answer" field.

Additionally, ensure that the user making the request has the necessary permissions (admin, owner, or editor) and that the dataset and document exist. The backend code validates these conditions and updates the segment accordingly.

If the issue persists, it might be related to the validation logic in the backend. According to the SegmentService class in api/services/dataset_service.py, the segment_create_args_validate method checks if the "answer" field is present and not empty when the document's doc_form is 'qa_model'. Ensure that the "answer" field is correctly populated and not empty in your request payload [1][2][3].

To continue talking to Dosu, mention @dosu.

crazywoola commented 3 months ago

What is your knowledge base mode? QA or Normal?

dc-vin commented 3 months ago

What is your knowledge base mode? QA or Normal?

QA model

crazywoola commented 2 months ago

It should be resolved in v0.7.1