DifyService
Service to interact with Dify API
api_key: strroute: strInitialize self. See help(type(self)) for accurate signature.
strstrCreate 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
strDifyCreateDatasetMetadataRequestDifyCreateDatasetMetadataResponseDelete 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
strstrGet 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
strListGet the base URL of the Dify API before the first '/'. Returns: str: Base URL of the Dify API
strGet metadata for a specific dataset. Parameters
dataset_id : str Knowledge Base ID Raises
requests.exceptions.HTTPError If the API request fails
strDifyGetDatasetMetadataResponseGet 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
strstrgws_core.impl.dify.dify_class.DifyGetDatasetMetadataResponseMetadata | NoneGet 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
strstrOptionalstr - completedint - 1int - 20DifyDocumentChunksResponseGet 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
strstrDifyUploadFileResponseGet 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
strintintDifyGetDocumentsResponseGet or create the access right metadata in Dify.
strDifyCreateDatasetMetadataRequestDifyGetDatasetMetadataResponseMetadataRetrieve 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
strstrLiteral - semantic_searchbool - FalseOptionalOptionalOptionalOptional - 5bool - FalseOptional - 0DifyChunksResponsestrstrDifySendDocumentOptionsstrDifySendDocumentResponseCall 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)
strstrOptionalOptionalOptionalGeneratorUpdate 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
strstrstrDifySendDocumentOptionsstrDifySendDocumentResponseUpdate 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
strListCredentialsDataOther