
大模型上下文協議與Spring開發集成篇——mcp-spring-webmvc原理
--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"
}'
通過文本創建文檔:
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}'
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文檔都是開發者不可或缺的工具。