Service to interact with Dify API
api_key: str
route: str
Initialize self. See help(type(self)) for accurate signature.
str
str
Create metadata for a specific document in a dataset. Parameters
dataset_id : str Knowledge Base ID body : DifyCreateMetadataRequest Metadata to create Raises
requests.exceptions.HTTPError If the API request fails
str
DifyCreateDatasetMetadataRequest
DifyCreateDatasetMetadataResponse
Delete a document from a dataset.
Parameters
dataset_id : str Knowledge Base ID document_id : str Document ID to delete
Raises
requests.exceptions.HTTPError If the API request fails
str
str
Get all documents in a dataset.
Parameters
dataset_id : str Knowledge Base ID
Returns
List[DifyDatasetDocument] List of documents in the dataset
Raises
requests.exceptions.HTTPError If the API request fails
str
List
Get the base URL of the Dify API before the first '/'. Returns: str: Base URL of the Dify API
str
Get metadata for a specific dataset. Parameters
dataset_id : str Knowledge Base ID Raises
requests.exceptions.HTTPError If the API request fails
str
DifyGetDatasetMetadataResponse
Get metadata for a specific dataset. Parameters
dataset_id : str Knowledge Base ID metadata_name : str Metadata name to get Raises
requests.exceptions.HTTPError If the API request fails
str
str
gws_core.impl.dify.dify_class.DifyGetDatasetMetadataResponseMetadata | None
Get chunks from a specific document in a knowledge base.
This method retrieves chunks from a specific document within a dataset.
Parameters
dataset_id : str Knowledge Base ID document_id : str Document ID to get chunks from keyword : Optional[str], optional Search keyword to filter chunks, by default None status : str, optional Search status filter, by default "completed" page : int, optional Page number for pagination, by default 1 limit : int, optional Number of items to return per page (1-100), by default 20
Returns
DifyDocumentChunksResponse Response containing the document chunks and pagination info
Raises
requests.exceptions.HTTPError If the API request fails
str
str
Optional
str
- completed
int
- 1
int
- 20
DifyDocumentChunksResponse
Get information about a document's uploaded file and optionally download it.
This method retrieves information about the uploaded file associated with a document and can optionally download the file to a temporary directory.
Parameters
dataset_id : str Knowledge Base ID document_id : str Document ID to get the file information for download_to_temp : bool, optional Whether to download the file to a temporary directory, by default True
Returns
Download url
Raises
requests.exceptions.HTTPError If the API request fails RuntimeError If file download fails
str
str
DifyUploadFileResponse
Get a list of documents in a dataset.
Parameters
dataset_id : str Knowledge Base ID page : int Page number for pagination limit : int Number of items to return per page (1-100)
Returns
DifyGetDocumentsResponse Response containing the list of documents and pagination info
Raises
requests.exceptions.HTTPError If the API request fails
str
int
int
DifyGetDocumentsResponse
Get or create the access right metadata in Dify.
str
DifyCreateDatasetMetadataRequest
DifyGetDatasetMetadataResponseMetadata
Retrieve chunks from a Knowledge Base (dataset).
This method retrieves relevant chunks from the specified dataset based on the query and search parameters.
Parameters
dataset_id : str Knowledge Base ID query : str Query keyword to search for search_method : Literal['keyword_search', 'semantic_search', 'full_text_search', 'hybrid_search'], optional Search method to use, by default 'semantic_search' reranking_enable : bool, optional Whether to enable reranking, by default False reranking_provider_name : Optional[str], optional Rerank model provider, required if reranking is enabled reranking_model_name : Optional[str], optional Rerank model name, required if reranking is enabled weights : Optional[float], optional Semantic search weight setting in hybrid search mode top_k : Optional[int], optional Number of results to return score_threshold_enabled : bool, optional Whether to enable score threshold, by default False score_threshold : Optional[float], optional Score threshold value, used if score_threshold_enabled is True
Returns
DifyChunksResponse Response containing query info and retrieved chunks
Raises
requests.exceptions.HTTPError If the API request fails
str
str
Literal
- semantic_search
bool
- False
Optional
Optional
Optional
Optional
- 5
bool
- False
Optional
- 0
DifyChunksResponse
str
str
DifySendDocumentOptions
str
DifySendDocumentResponse
Call the Dify API chat endpoint with streaming response.
Args: query: The user's message conversation_id: Optional ID for continuing a conversation user: Optional user identifier inputs: Optional dictionary of input variables files: Optional list of files to include
Returns: Generator that yields response chunks (string or objects)
str
str
Optional
Optional
Optional
Generator
Update a document in a dataset. Parameters
doc_path : str Path to the document file dataset_id : str Knowledge Base ID document_id : str Document ID to update options : DifyUpdateDocumentOptions Options for updating the document Returns
DifySendDocumentResponse Response containing the updated document information Raises
requests.exceptions.HTTPError If the API request fails
str
str
str
DifySendDocumentOptions
str
DifySendDocumentResponse
Update metadata for a specific document in a dataset.
Parameters
dataset_id : str Knowledge Base ID document_id : str Document ID to update metadata for metadata : Dict[str, Any] Metadata to update
Raises
requests.exceptions.HTTPError If the API request fails
str
List
CredentialsDataOther