--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"response_mode": "streaming",
"user": "abc-123"
}'

對話型應用接口調用示例

curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"query": "Hello, how are you?",
"response_mode": "streaming",
"conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
"user": "abc-123"
}'

通過API維護知識庫的示例代碼

通過文本創建文檔

curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-text' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "example.txt","text": "This is an example text.","indexing_technique": "high_quality","process_rule": {"mode": "automatic"}}'

通過文件創建文檔

curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/document/create-by-file' \
--header 'Authorization: Bearer {api_key}' \
--form 'data="{"indexing_technique":"high_quality","process_rule":{"rules":{"pre_processing_rules":[{"id":"remove_extra_spaces","enabled":true},{"id":"remove_urls_emails","enabled":true}],"segmentation":{"separator":"###","max_tokens":500}},"mode":"custom"}}";type=text/plain' \
--form 'file=@"/path/to/file"'

更新文檔內容

curl --location --request POST 'https://api.dify.ai/v1/datasets/{dataset_id}/documents/{document_id}/update-by-text' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "updated_example.txt","text": "This is an updated example text."}'

查詢知識庫列表

curl --location --request GET 'https://api.dify.ai/v1/datasets?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}'

外部知識庫API調用示例

curl --location --request POST '<your-endpoint>/retrieval' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer your-api-key' \
--data-raw '{
"knowledge_id": "your-knowledge-id",
"query": "你的問題",
"retrieval_setting": {
"top_k": 2,
"score_threshold": 0.5
}
}'

結語

Dify的API文檔為開發者提供了強大的工具,用于構建和管理知識庫。通過基于APIs開發和通過API維護知識庫,開發者可以更加高效地開發應用,并靈活地管理知識庫。Dify的API文檔不僅具有豐富的功能,還提供了詳細的操作指南和示例代碼,使得開發者可以快速上手并應用到實際項目中。無論是開發前端應用還是管理知識庫,Dify的API文檔都是開發者不可或缺的工具。

上一篇:

復雜推理:大語言模型的北極星能力

下一篇:

API接口通俗理解:從概念到應用
#你可能也喜歡這些API文章!

我們有何不同?

API服務商零注冊

多API并行試用

數據驅動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內容創意新穎性、情感共鳴力、商業轉化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費