dify-oapi2 0.5.0__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dify_oapi/api/chat/v1/model/chat_response.py +1 -0
- dify_oapi/api/chat/v1/model/configure_annotation_reply_request.py +1 -0
- dify_oapi/api/chat/v1/model/create_annotation_request.py +1 -0
- dify_oapi/api/chat/v1/model/get_conversations_request.py +49 -0
- dify_oapi/api/chat/v1/model/update_annotation_request.py +1 -0
- dify_oapi/api/chat/v1/resource/__init__.py +1 -8
- dify_oapi/api/chat/v1/resource/annotation.py +37 -27
- dify_oapi/api/chat/v1/resource/chat.py +37 -29
- dify_oapi/api/chat/v1/resource/conversation.py +25 -59
- dify_oapi/api/chat/v1/resource/message.py +13 -15
- dify_oapi/api/chat/v1/version.py +18 -11
- dify_oapi/api/chatflow/service.py +1 -18
- dify_oapi/api/chatflow/v1/resource/annotation.py +14 -49
- dify_oapi/api/chatflow/v1/resource/chatflow.py +6 -19
- dify_oapi/api/chatflow/v1/resource/conversation.py +12 -41
- dify_oapi/api/chatflow/v1/version.py +11 -18
- dify_oapi/api/completion/v1/resource/__init__.py +0 -6
- dify_oapi/api/completion/v1/version.py +8 -6
- dify_oapi/api/dify/v1/model/get_feedbacks_response.py +26 -0
- dify_oapi/api/{completion/v1/model/info → dify/v1/model}/get_parameters_request.py +4 -0
- dify_oapi/api/dify/v1/model/{get_parameter_response.py → get_parameters_response.py} +6 -2
- dify_oapi/api/dify/v1/model/get_site_response.py +17 -0
- dify_oapi/api/{chat → dify}/v1/model/submit_feedback_request_body.py +3 -1
- dify_oapi/api/{chat → dify}/v1/model/submit_feedback_response.py +3 -1
- dify_oapi/api/dify/v1/resource/__init__.py +0 -6
- dify_oapi/api/dify/v1/resource/audio.py +12 -0
- dify_oapi/api/{chat → dify}/v1/resource/feedback.py +6 -6
- dify_oapi/api/dify/v1/resource/info.py +34 -2
- dify_oapi/api/dify/v1/version.py +5 -4
- dify_oapi/api/knowledge/service.py +3 -3
- dify_oapi/api/knowledge/v1/model/create_document_by_file_request.py +1 -3
- dify_oapi/api/knowledge/v1/model/create_document_by_file_request_body.py +4 -46
- dify_oapi/api/knowledge/v1/model/create_document_by_file_request_body_data.py +73 -0
- dify_oapi/api/knowledge/v1/model/process_rule.py +0 -6
- dify_oapi/api/knowledge/v1/model/update_document_by_file_request.py +1 -3
- dify_oapi/api/knowledge/v1/model/update_document_by_file_request_body.py +4 -41
- dify_oapi/api/knowledge/v1/model/update_document_by_file_request_body_data.py +68 -0
- dify_oapi/api/knowledge/v1/resource/__init__.py +0 -8
- dify_oapi/api/workflow/v1/resource/workflow.py +0 -34
- dify_oapi/api/workflow/v1/version.py +9 -0
- dify_oapi/client.py +4 -4
- dify_oapi2-1.0.0.dist-info/METADATA +365 -0
- {dify_oapi2-0.5.0.dist-info → dify_oapi2-1.0.0.dist-info}/RECORD +51 -130
- dify_oapi/api/chat/v1/model/get_app_info_request.py +0 -24
- dify_oapi/api/chat/v1/model/get_app_info_response.py +0 -9
- dify_oapi/api/chat/v1/model/get_app_meta_request.py +0 -24
- dify_oapi/api/chat/v1/model/get_app_meta_response.py +0 -9
- dify_oapi/api/chat/v1/model/get_app_parameters_request.py +0 -28
- dify_oapi/api/chat/v1/model/get_app_parameters_response.py +0 -9
- dify_oapi/api/chat/v1/model/get_feedbacks_response.py +0 -7
- dify_oapi/api/chat/v1/model/get_site_settings_request.py +0 -24
- dify_oapi/api/chat/v1/model/get_site_settings_response.py +0 -9
- dify_oapi/api/chat/v1/model/text_to_audio_request.py +0 -32
- dify_oapi/api/chat/v1/model/text_to_audio_request_body.py +0 -33
- dify_oapi/api/chat/v1/model/upload_file_request.py +0 -54
- dify_oapi/api/chat/v1/model/upload_file_response.py +0 -10
- dify_oapi/api/chat/v1/resource/app.py +0 -47
- dify_oapi/api/chat/v1/resource/audio.py +0 -30
- dify_oapi/api/chat/v1/resource/file.py +0 -25
- dify_oapi/api/chatflow/v1/model/audio_to_text_request.py +0 -37
- dify_oapi/api/chatflow/v1/model/audio_to_text_response.py +0 -21
- dify_oapi/api/chatflow/v1/model/get_app_feedbacks_request.py +0 -30
- dify_oapi/api/chatflow/v1/model/get_app_feedbacks_response.py +0 -23
- dify_oapi/api/chatflow/v1/model/get_info_request.py +0 -22
- dify_oapi/api/chatflow/v1/model/get_info_response.py +0 -7
- dify_oapi/api/chatflow/v1/model/get_meta_request.py +0 -22
- dify_oapi/api/chatflow/v1/model/get_meta_response.py +0 -7
- dify_oapi/api/chatflow/v1/model/get_parameters_request.py +0 -22
- dify_oapi/api/chatflow/v1/model/get_parameters_response.py +0 -7
- dify_oapi/api/chatflow/v1/model/get_site_request.py +0 -22
- dify_oapi/api/chatflow/v1/model/get_site_response.py +0 -7
- dify_oapi/api/chatflow/v1/model/message_feedback_request.py +0 -36
- dify_oapi/api/chatflow/v1/model/message_feedback_request_body.py +0 -33
- dify_oapi/api/chatflow/v1/model/message_feedback_response.py +0 -21
- dify_oapi/api/chatflow/v1/model/text_to_audio_request.py +0 -30
- dify_oapi/api/chatflow/v1/model/text_to_audio_request_body.py +0 -36
- dify_oapi/api/chatflow/v1/model/text_to_audio_response.py +0 -19
- dify_oapi/api/chatflow/v1/model/upload_file_request.py +0 -41
- dify_oapi/api/chatflow/v1/model/upload_file_response.py +0 -11
- dify_oapi/api/chatflow/v1/resource/application.py +0 -76
- dify_oapi/api/chatflow/v1/resource/feedback.py +0 -69
- dify_oapi/api/chatflow/v1/resource/file.py +0 -39
- dify_oapi/api/chatflow/v1/resource/tts.py +0 -29
- dify_oapi/api/completion/v1/model/audio/audio_info.py +0 -28
- dify_oapi/api/completion/v1/model/audio/text_to_audio_request.py +0 -32
- dify_oapi/api/completion/v1/model/audio/text_to_audio_request_body.py +0 -33
- dify_oapi/api/completion/v1/model/audio/text_to_audio_response.py +0 -9
- dify_oapi/api/completion/v1/model/feedback/feedback_info.py +0 -53
- dify_oapi/api/completion/v1/model/feedback/get_feedbacks_request.py +0 -32
- dify_oapi/api/completion/v1/model/feedback/get_feedbacks_response.py +0 -9
- dify_oapi/api/completion/v1/model/feedback/message_feedback_request.py +0 -38
- dify_oapi/api/completion/v1/model/feedback/message_feedback_request_body.py +0 -35
- dify_oapi/api/completion/v1/model/feedback/message_feedback_response.py +0 -7
- dify_oapi/api/completion/v1/model/file/file_info.py +0 -53
- dify_oapi/api/completion/v1/model/file/upload_file_request.py +0 -42
- dify_oapi/api/completion/v1/model/file/upload_file_request_body.py +0 -23
- dify_oapi/api/completion/v1/model/file/upload_file_response.py +0 -9
- dify_oapi/api/completion/v1/model/info/app_info.py +0 -43
- dify_oapi/api/completion/v1/model/info/feature_config.py +0 -91
- dify_oapi/api/completion/v1/model/info/file_upload_config.py +0 -23
- dify_oapi/api/completion/v1/model/info/get_info_request.py +0 -24
- dify_oapi/api/completion/v1/model/info/get_info_response.py +0 -9
- dify_oapi/api/completion/v1/model/info/get_parameters_response.py +0 -9
- dify_oapi/api/completion/v1/model/info/get_site_response.py +0 -9
- dify_oapi/api/completion/v1/model/info/parameters_info.py +0 -75
- dify_oapi/api/completion/v1/model/info/site_info.py +0 -90
- dify_oapi/api/completion/v1/model/info/system_parameters.py +0 -38
- dify_oapi/api/completion/v1/model/info/user_input_form.py +0 -158
- dify_oapi/api/completion/v1/resource/audio.py +0 -19
- dify_oapi/api/completion/v1/resource/feedback.py +0 -33
- dify_oapi/api/completion/v1/resource/file.py +0 -19
- dify_oapi/api/completion/v1/resource/info.py +0 -39
- dify_oapi/api/dify/v1/model/get_parameter_request.py +0 -30
- dify_oapi/api/dify/v1/model/message_feedback_request.py +0 -38
- dify_oapi/api/dify/v1/model/message_feedback_request_body.py +0 -30
- dify_oapi/api/dify/v1/model/message_feedback_response.py +0 -5
- dify_oapi/api/dify/v1/resource/message.py +0 -21
- dify_oapi/api/dify/v1/resource/meta.py +0 -17
- dify_oapi/api/dify/v1/resource/parameter.py +0 -19
- dify_oapi/api/workflow/v1/model/get_info_request.py +0 -24
- dify_oapi/api/workflow/v1/model/get_info_response.py +0 -9
- dify_oapi/api/workflow/v1/model/get_parameters_request.py +0 -24
- dify_oapi/api/workflow/v1/model/get_parameters_response.py +0 -9
- dify_oapi/api/workflow/v1/model/get_site_request.py +0 -24
- dify_oapi/api/workflow/v1/model/get_site_response.py +0 -9
- dify_oapi/api/workflow/v1/model/upload_file_request.py +0 -42
- dify_oapi/api/workflow/v1/model/upload_file_response.py +0 -9
- dify_oapi2-0.5.0.dist-info/METADATA +0 -335
- /dify_oapi/api/{chat → dify}/v1/model/audio_to_text_request.py +0 -0
- /dify_oapi/api/{chat → dify}/v1/model/audio_to_text_request_body.py +0 -0
- /dify_oapi/api/{chat → dify}/v1/model/audio_to_text_response.py +0 -0
- /dify_oapi/api/{chat → dify}/v1/model/get_feedbacks_request.py +0 -0
- /dify_oapi/api/{completion/v1/model/info → dify/v1/model}/get_site_request.py +0 -0
- /dify_oapi/api/{chat → dify}/v1/model/submit_feedback_request.py +0 -0
- {dify_oapi2-0.5.0.dist-info → dify_oapi2-1.0.0.dist-info}/LICENSE +0 -0
- {dify_oapi2-0.5.0.dist-info → dify_oapi2-1.0.0.dist-info}/WHEEL +0 -0
@@ -6,7 +6,6 @@ from pydantic import BaseModel
|
|
6
6
|
|
7
7
|
from .knowledge_types import ProcessingMode
|
8
8
|
from .process_rules import ProcessRules
|
9
|
-
from .segmentation_rule import SegmentationRule
|
10
9
|
|
11
10
|
|
12
11
|
class ProcessRule(BaseModel):
|
@@ -14,7 +13,6 @@ class ProcessRule(BaseModel):
|
|
14
13
|
|
15
14
|
mode: Optional[ProcessingMode] = None
|
16
15
|
rules: Optional[ProcessRules] = None
|
17
|
-
segmentation: Optional[SegmentationRule] = None
|
18
16
|
|
19
17
|
@staticmethod
|
20
18
|
def builder() -> "ProcessRuleBuilder":
|
@@ -37,7 +35,3 @@ class ProcessRuleBuilder:
|
|
37
35
|
def rules(self, rules: ProcessRules) -> "ProcessRuleBuilder":
|
38
36
|
self._process_rule.rules = rules
|
39
37
|
return self
|
40
|
-
|
41
|
-
def segmentation(self, segmentation: SegmentationRule) -> "ProcessRuleBuilder":
|
42
|
-
self._process_rule.segmentation = segmentation
|
43
|
-
return self
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
-
import json
|
6
5
|
from io import BytesIO
|
7
6
|
|
8
7
|
from dify_oapi.core.enum import HttpMethod
|
@@ -50,8 +49,7 @@ class UpdateDocumentByFileRequestBuilder:
|
|
50
49
|
|
51
50
|
def request_body(self, request_body: UpdateDocumentByFileRequestBody) -> UpdateDocumentByFileRequestBuilder:
|
52
51
|
self._update_document_by_file_request.request_body = request_body
|
53
|
-
|
54
|
-
self._update_document_by_file_request.body = {"data": json.dumps(data_dict)}
|
52
|
+
self._update_document_by_file_request.body = request_body.model_dump(exclude_none=True, mode="json")
|
55
53
|
return self
|
56
54
|
|
57
55
|
def file(self, file: BytesIO, file_name: str | None = None) -> UpdateDocumentByFileRequestBuilder:
|
@@ -4,22 +4,13 @@ from __future__ import annotations
|
|
4
4
|
|
5
5
|
from pydantic import BaseModel
|
6
6
|
|
7
|
-
from .
|
8
|
-
from .process_rule import ProcessRule
|
9
|
-
from .retrieval_model import RetrievalModel
|
7
|
+
from .update_document_by_file_request_body_data import UpdateDocumentByFileRequestBodyData
|
10
8
|
|
11
9
|
|
12
10
|
class UpdateDocumentByFileRequestBody(BaseModel):
|
13
11
|
"""Request body model for update document by file API."""
|
14
12
|
|
15
|
-
|
16
|
-
indexing_technique: IndexingTechnique | None = None
|
17
|
-
doc_form: str | None = None
|
18
|
-
doc_language: str | None = None
|
19
|
-
process_rule: ProcessRule | None = None
|
20
|
-
retrieval_model: RetrievalModel | None = None
|
21
|
-
embedding_model: str | None = None
|
22
|
-
embedding_model_provider: str | None = None
|
13
|
+
data: str | None = None
|
23
14
|
|
24
15
|
@staticmethod
|
25
16
|
def builder() -> UpdateDocumentByFileRequestBodyBuilder:
|
@@ -35,34 +26,6 @@ class UpdateDocumentByFileRequestBodyBuilder:
|
|
35
26
|
def build(self) -> UpdateDocumentByFileRequestBody:
|
36
27
|
return self._update_document_by_file_request_body
|
37
28
|
|
38
|
-
def
|
39
|
-
self._update_document_by_file_request_body.
|
40
|
-
return self
|
41
|
-
|
42
|
-
def indexing_technique(self, indexing_technique: IndexingTechnique) -> UpdateDocumentByFileRequestBodyBuilder:
|
43
|
-
self._update_document_by_file_request_body.indexing_technique = indexing_technique
|
44
|
-
return self
|
45
|
-
|
46
|
-
def process_rule(self, process_rule: ProcessRule) -> UpdateDocumentByFileRequestBodyBuilder:
|
47
|
-
self._update_document_by_file_request_body.process_rule = process_rule
|
48
|
-
return self
|
49
|
-
|
50
|
-
def doc_form(self, doc_form: str) -> UpdateDocumentByFileRequestBodyBuilder:
|
51
|
-
self._update_document_by_file_request_body.doc_form = doc_form
|
52
|
-
return self
|
53
|
-
|
54
|
-
def doc_language(self, doc_language: str) -> UpdateDocumentByFileRequestBodyBuilder:
|
55
|
-
self._update_document_by_file_request_body.doc_language = doc_language
|
56
|
-
return self
|
57
|
-
|
58
|
-
def retrieval_model(self, retrieval_model: RetrievalModel) -> UpdateDocumentByFileRequestBodyBuilder:
|
59
|
-
self._update_document_by_file_request_body.retrieval_model = retrieval_model
|
60
|
-
return self
|
61
|
-
|
62
|
-
def embedding_model(self, embedding_model: str) -> UpdateDocumentByFileRequestBodyBuilder:
|
63
|
-
self._update_document_by_file_request_body.embedding_model = embedding_model
|
64
|
-
return self
|
65
|
-
|
66
|
-
def embedding_model_provider(self, embedding_model_provider: str) -> UpdateDocumentByFileRequestBodyBuilder:
|
67
|
-
self._update_document_by_file_request_body.embedding_model_provider = embedding_model_provider
|
29
|
+
def data(self, data: UpdateDocumentByFileRequestBodyData) -> UpdateDocumentByFileRequestBodyBuilder:
|
30
|
+
self._update_document_by_file_request_body.data = data.model_dump_json(exclude_none=True)
|
68
31
|
return self
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"""Update document by file request body model."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from pydantic import BaseModel
|
6
|
+
|
7
|
+
from .knowledge_types import IndexingTechnique
|
8
|
+
from .process_rule import ProcessRule
|
9
|
+
from .retrieval_model import RetrievalModel
|
10
|
+
|
11
|
+
|
12
|
+
class UpdateDocumentByFileRequestBodyData(BaseModel):
|
13
|
+
"""Request body model for update document by file API."""
|
14
|
+
|
15
|
+
name: str | None = None
|
16
|
+
indexing_technique: IndexingTechnique | None = None
|
17
|
+
doc_form: str | None = None
|
18
|
+
doc_language: str | None = None
|
19
|
+
process_rule: ProcessRule | None = None
|
20
|
+
retrieval_model: RetrievalModel | None = None
|
21
|
+
embedding_model: str | None = None
|
22
|
+
embedding_model_provider: str | None = None
|
23
|
+
|
24
|
+
@staticmethod
|
25
|
+
def builder() -> UpdateDocumentByFileRequestBodyDataBuilder:
|
26
|
+
return UpdateDocumentByFileRequestBodyDataBuilder()
|
27
|
+
|
28
|
+
|
29
|
+
class UpdateDocumentByFileRequestBodyDataBuilder:
|
30
|
+
"""Builder for UpdateDocumentByFileRequestBodyData."""
|
31
|
+
|
32
|
+
def __init__(self) -> None:
|
33
|
+
self._update_document_by_file_request_body = UpdateDocumentByFileRequestBodyData()
|
34
|
+
|
35
|
+
def build(self) -> UpdateDocumentByFileRequestBodyData:
|
36
|
+
return self._update_document_by_file_request_body
|
37
|
+
|
38
|
+
def name(self, name: str) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
39
|
+
self._update_document_by_file_request_body.name = name
|
40
|
+
return self
|
41
|
+
|
42
|
+
def indexing_technique(self, indexing_technique: IndexingTechnique) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
43
|
+
self._update_document_by_file_request_body.indexing_technique = indexing_technique
|
44
|
+
return self
|
45
|
+
|
46
|
+
def process_rule(self, process_rule: ProcessRule) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
47
|
+
self._update_document_by_file_request_body.process_rule = process_rule
|
48
|
+
return self
|
49
|
+
|
50
|
+
def doc_form(self, doc_form: str) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
51
|
+
self._update_document_by_file_request_body.doc_form = doc_form
|
52
|
+
return self
|
53
|
+
|
54
|
+
def doc_language(self, doc_language: str) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
55
|
+
self._update_document_by_file_request_body.doc_language = doc_language
|
56
|
+
return self
|
57
|
+
|
58
|
+
def retrieval_model(self, retrieval_model: RetrievalModel) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
59
|
+
self._update_document_by_file_request_body.retrieval_model = retrieval_model
|
60
|
+
return self
|
61
|
+
|
62
|
+
def embedding_model(self, embedding_model: str) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
63
|
+
self._update_document_by_file_request_body.embedding_model = embedding_model
|
64
|
+
return self
|
65
|
+
|
66
|
+
def embedding_model_provider(self, embedding_model_provider: str) -> UpdateDocumentByFileRequestBodyDataBuilder:
|
67
|
+
self._update_document_by_file_request_body.embedding_model_provider = embedding_model_provider
|
68
|
+
return self
|
@@ -5,12 +5,6 @@ from dify_oapi.core.http.transport import ATransport, Transport
|
|
5
5
|
from dify_oapi.core.model.config import Config
|
6
6
|
from dify_oapi.core.model.request_option import RequestOption
|
7
7
|
|
8
|
-
from ..model.get_info_request import GetInfoRequest
|
9
|
-
from ..model.get_info_response import GetInfoResponse
|
10
|
-
from ..model.get_parameters_request import GetParametersRequest
|
11
|
-
from ..model.get_parameters_response import GetParametersResponse
|
12
|
-
from ..model.get_site_request import GetSiteRequest
|
13
|
-
from ..model.get_site_response import GetSiteResponse
|
14
8
|
from ..model.get_workflow_logs_request import GetWorkflowLogsRequest
|
15
9
|
from ..model.get_workflow_logs_response import GetWorkflowLogsResponse
|
16
10
|
from ..model.get_workflow_run_detail_request import GetWorkflowRunDetailRequest
|
@@ -19,8 +13,6 @@ from ..model.run_workflow_request import RunWorkflowRequest
|
|
19
13
|
from ..model.run_workflow_response import RunWorkflowResponse
|
20
14
|
from ..model.stop_workflow_request import StopWorkflowRequest
|
21
15
|
from ..model.stop_workflow_response import StopWorkflowResponse
|
22
|
-
from ..model.upload_file_request import UploadFileRequest
|
23
|
-
from ..model.upload_file_response import UploadFileResponse
|
24
16
|
|
25
17
|
|
26
18
|
class Workflow:
|
@@ -97,12 +89,6 @@ class Workflow:
|
|
97
89
|
async def astop(self, request: StopWorkflowRequest, request_option: RequestOption) -> StopWorkflowResponse:
|
98
90
|
return await ATransport.aexecute(self.config, request, unmarshal_as=StopWorkflowResponse, option=request_option)
|
99
91
|
|
100
|
-
def upload(self, request: UploadFileRequest, request_option: RequestOption) -> UploadFileResponse:
|
101
|
-
return Transport.execute(self.config, request, unmarshal_as=UploadFileResponse, option=request_option)
|
102
|
-
|
103
|
-
async def aupload(self, request: UploadFileRequest, request_option: RequestOption) -> UploadFileResponse:
|
104
|
-
return await ATransport.aexecute(self.config, request, unmarshal_as=UploadFileResponse, option=request_option)
|
105
|
-
|
106
92
|
def logs(self, request: GetWorkflowLogsRequest, request_option: RequestOption) -> GetWorkflowLogsResponse:
|
107
93
|
return Transport.execute(self.config, request, unmarshal_as=GetWorkflowLogsResponse, option=request_option)
|
108
94
|
|
@@ -110,23 +96,3 @@ class Workflow:
|
|
110
96
|
return await ATransport.aexecute(
|
111
97
|
self.config, request, unmarshal_as=GetWorkflowLogsResponse, option=request_option
|
112
98
|
)
|
113
|
-
|
114
|
-
def info(self, request: GetInfoRequest, request_option: RequestOption) -> GetInfoResponse:
|
115
|
-
return Transport.execute(self.config, request, unmarshal_as=GetInfoResponse, option=request_option)
|
116
|
-
|
117
|
-
async def ainfo(self, request: GetInfoRequest, request_option: RequestOption) -> GetInfoResponse:
|
118
|
-
return await ATransport.aexecute(self.config, request, unmarshal_as=GetInfoResponse, option=request_option)
|
119
|
-
|
120
|
-
def parameters(self, request: GetParametersRequest, request_option: RequestOption) -> GetParametersResponse:
|
121
|
-
return Transport.execute(self.config, request, unmarshal_as=GetParametersResponse, option=request_option)
|
122
|
-
|
123
|
-
async def aparameters(self, request: GetParametersRequest, request_option: RequestOption) -> GetParametersResponse:
|
124
|
-
return await ATransport.aexecute(
|
125
|
-
self.config, request, unmarshal_as=GetParametersResponse, option=request_option
|
126
|
-
)
|
127
|
-
|
128
|
-
def site(self, request: GetSiteRequest, request_option: RequestOption) -> GetSiteResponse:
|
129
|
-
return Transport.execute(self.config, request, unmarshal_as=GetSiteResponse, option=request_option)
|
130
|
-
|
131
|
-
async def asite(self, request: GetSiteRequest, request_option: RequestOption) -> GetSiteResponse:
|
132
|
-
return await ATransport.aexecute(self.config, request, unmarshal_as=GetSiteResponse, option=request_option)
|
@@ -1,3 +1,7 @@
|
|
1
|
+
from dify_oapi.api.dify.v1.resource.audio import Audio
|
2
|
+
from dify_oapi.api.dify.v1.resource.feedback import Feedback
|
3
|
+
from dify_oapi.api.dify.v1.resource.file import File
|
4
|
+
from dify_oapi.api.dify.v1.resource.info import Info
|
1
5
|
from dify_oapi.core.model.config import Config
|
2
6
|
|
3
7
|
from .resource.workflow import Workflow
|
@@ -6,3 +10,8 @@ from .resource.workflow import Workflow
|
|
6
10
|
class V1:
|
7
11
|
def __init__(self, config: Config):
|
8
12
|
self.workflow = Workflow(config)
|
13
|
+
# System APIs - delegate to dify module
|
14
|
+
self.file = File(config)
|
15
|
+
self.audio = Audio(config)
|
16
|
+
self.info = Info(config)
|
17
|
+
self.feedback = Feedback(config)
|
dify_oapi/client.py
CHANGED
@@ -6,7 +6,7 @@ from .api.chat.service import ChatService
|
|
6
6
|
from .api.chatflow.service import ChatflowService
|
7
7
|
from .api.completion.service import CompletionService
|
8
8
|
from .api.dify.service import DifyService
|
9
|
-
from .api.knowledge.service import
|
9
|
+
from .api.knowledge.service import KnowledgeService
|
10
10
|
from .api.workflow.service import WorkflowService
|
11
11
|
from .core.enum import LogLevel
|
12
12
|
from .core.http.transport import Transport
|
@@ -24,7 +24,7 @@ class Client:
|
|
24
24
|
self._completion: CompletionService | None = None
|
25
25
|
self._dify: DifyService | None = None
|
26
26
|
self._workflow: WorkflowService | None = None
|
27
|
-
self._knowledge:
|
27
|
+
self._knowledge: KnowledgeService | None = None
|
28
28
|
|
29
29
|
@property
|
30
30
|
def chat(self) -> ChatService:
|
@@ -57,7 +57,7 @@ class Client:
|
|
57
57
|
return self._workflow
|
58
58
|
|
59
59
|
@property
|
60
|
-
def knowledge(self) ->
|
60
|
+
def knowledge(self) -> KnowledgeService:
|
61
61
|
if self._knowledge is None:
|
62
62
|
raise RuntimeError("Knowledge base service has not been initialized")
|
63
63
|
return self._knowledge
|
@@ -135,7 +135,7 @@ class ClientBuilder:
|
|
135
135
|
client._completion = CompletionService(self._config)
|
136
136
|
client._dify = DifyService(self._config)
|
137
137
|
client._workflow = WorkflowService(self._config)
|
138
|
-
client._knowledge =
|
138
|
+
client._knowledge = KnowledgeService(self._config)
|
139
139
|
return client
|
140
140
|
|
141
141
|
def _init_logger(self):
|
@@ -0,0 +1,365 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: dify-oapi2
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A package for interacting with the Dify Service-API
|
5
|
+
License: MIT
|
6
|
+
Keywords: dify,nlp,ai,language-processing
|
7
|
+
Author: Oscaner Miao
|
8
|
+
Author-email: oscaner1997@gmail.com
|
9
|
+
Requires-Python: >=3.10
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
16
|
+
Requires-Dist: httpx (>=0,<1)
|
17
|
+
Requires-Dist: pydantic (>=2,<3)
|
18
|
+
Project-URL: Homepage, https://github.com/nodite/dify-oapi2
|
19
|
+
Project-URL: Source, https://github.com/nodite/dify-oapi2
|
20
|
+
Description-Content-Type: text/markdown
|
21
|
+
|
22
|
+
# Dify-OAPI
|
23
|
+
|
24
|
+
[](https://badge.fury.io/py/dify-oapi2)
|
25
|
+
[](https://www.python.org/downloads/)
|
26
|
+
[](https://opensource.org/licenses/MIT)
|
27
|
+
|
28
|
+
A modern Python SDK for interacting with the Dify Service-API. This library provides a fluent, type-safe interface for building AI-powered applications using Dify's comprehensive API services including chat, completion, knowledge base, workflow, and chatflow features.
|
29
|
+
|
30
|
+
> This project is based on https://github.com/QiMington/dify-oapi, completely refactored with modern Python practices and full support for the latest Dify API.
|
31
|
+
|
32
|
+
## ✨ Features
|
33
|
+
|
34
|
+
- **Complete API Coverage**: Chat (18 APIs), Chatflow (15 APIs), Completion (10 APIs), Knowledge Base (33 APIs), Workflow (4 APIs), and Core Dify (9 APIs)
|
35
|
+
- **Builder Pattern**: Fluent, chainable interface for constructing requests
|
36
|
+
- **Sync & Async Support**: Both synchronous and asynchronous operations
|
37
|
+
- **Streaming Responses**: Real-time streaming for chat and completion
|
38
|
+
- **Type Safety**: Comprehensive type hints with Pydantic 2.x validation
|
39
|
+
- **File Upload**: Support for images and documents
|
40
|
+
- **Modern HTTP Client**: Built on httpx for reliable API communication
|
41
|
+
- **Connection Pool Optimization**: Efficient TCP connection reuse to reduce resource overhead
|
42
|
+
|
43
|
+
## 📦 Installation
|
44
|
+
|
45
|
+
```bash
|
46
|
+
pip install dify-oapi2
|
47
|
+
```
|
48
|
+
|
49
|
+
**Requirements**: Python 3.10+
|
50
|
+
|
51
|
+
**Core Dependencies**:
|
52
|
+
- `pydantic` (^2) - Data validation and settings management with type safety
|
53
|
+
- `httpx` (^0) - Modern async HTTP client
|
54
|
+
|
55
|
+
**Development Dependencies**:
|
56
|
+
- `ruff` (^0) - Fast Python linter and formatter
|
57
|
+
- `mypy` (^1) - Static type checking
|
58
|
+
- `pytest` (^8) - Testing framework
|
59
|
+
- `pre-commit` (^4) - Git hooks for code quality
|
60
|
+
- `commitizen` (^4) - Semantic versioning and changelog generation
|
61
|
+
- `poetry` - Dependency management and packaging
|
62
|
+
|
63
|
+
## 🛠️ Technology Stack
|
64
|
+
|
65
|
+
- **Language**: Python 3.10+
|
66
|
+
- **HTTP Client**: httpx with connection pooling optimization
|
67
|
+
- **Type System**: Pydantic 2.x with comprehensive type validation
|
68
|
+
- **Architecture**: Builder pattern with fluent API design + Service layer pattern
|
69
|
+
- **Async Support**: Full async/await support with AsyncGenerator streaming
|
70
|
+
- **Code Quality**: Ruff (linting + formatting) + MyPy (type checking)
|
71
|
+
- **Testing**: pytest with async support and comprehensive coverage
|
72
|
+
- **Packaging**: Poetry with modern Python packaging standards
|
73
|
+
- **Total Coverage**: 89 API methods across 6 services with complete examples
|
74
|
+
|
75
|
+
## 🚀 Quick Start
|
76
|
+
|
77
|
+
### Basic Usage
|
78
|
+
|
79
|
+
```python
|
80
|
+
from dify_oapi.client import Client
|
81
|
+
from dify_oapi.core.model.request_option import RequestOption
|
82
|
+
from dify_oapi.api.chat.v1.model.chat_request import ChatRequest
|
83
|
+
|
84
|
+
# Initialize client with builder pattern
|
85
|
+
client = (
|
86
|
+
Client.builder()
|
87
|
+
.domain("https://api.dify.ai")
|
88
|
+
.max_connections(100)
|
89
|
+
.keepalive_expiry(30.0)
|
90
|
+
.build()
|
91
|
+
)
|
92
|
+
|
93
|
+
# Create request options
|
94
|
+
req_option = RequestOption.builder().api_key("your-api-key").build()
|
95
|
+
|
96
|
+
# Use the chat API
|
97
|
+
response = client.chat.chat(
|
98
|
+
request=ChatRequest.builder()
|
99
|
+
.query("Hello, how are you?")
|
100
|
+
.user("user-123")
|
101
|
+
.build(),
|
102
|
+
request_option=req_option
|
103
|
+
)
|
104
|
+
|
105
|
+
print(response.answer)
|
106
|
+
```
|
107
|
+
|
108
|
+
### Comprehensive Examples
|
109
|
+
|
110
|
+
Ready to build AI-powered applications? Check out our comprehensive examples:
|
111
|
+
|
112
|
+
- **[Chat Examples](./examples/chat/)** - Interactive conversations and streaming responses
|
113
|
+
- **[Chatflow Examples](./examples/chatflow/)** - Enhanced chat with workflow events
|
114
|
+
- **[Knowledge Base Examples](./examples/knowledge/)** - Build and query knowledge bases
|
115
|
+
- **[Workflow Examples](./examples/workflow/)** - Automate complex AI workflows
|
116
|
+
- **[Complete Examples Collection](./examples/)** - All API services with detailed usage patterns
|
117
|
+
|
118
|
+
Each example includes complete, runnable code with detailed explanations.
|
119
|
+
|
120
|
+
## 🔧 API Services
|
121
|
+
|
122
|
+
### Chat API (18 APIs)
|
123
|
+
**Resources**: annotation (6), chat (3), conversation (6), message (3)
|
124
|
+
- **Interactive Chat**: Send messages with blocking/streaming responses
|
125
|
+
- **Conversation Management**: Complete conversation lifecycle operations
|
126
|
+
- **Annotation System**: Create, update, delete annotations with reply settings
|
127
|
+
- **Message Operations**: Basic message handling and history retrieval
|
128
|
+
- **Streaming Support**: Real-time streaming for chat responses
|
129
|
+
- **Type Safety**: Comprehensive type hints with strict Literal types
|
130
|
+
|
131
|
+
### Chatflow API (15 APIs)
|
132
|
+
**Resources**: annotation (6), chatflow (3), conversation (6)
|
133
|
+
- **Enhanced Chat**: Advanced chat functionality with workflow events
|
134
|
+
- **Conversation Management**: Complete conversation operations with variables
|
135
|
+
- **Annotation System**: Full annotation management and reply configuration
|
136
|
+
- **Workflow Integration**: Seamless integration with workflow events
|
137
|
+
- **Event Streaming**: Real-time streaming with comprehensive event handling
|
138
|
+
- **Type Safety**: Strict Literal types for all predefined values
|
139
|
+
|
140
|
+
### Completion API (10 APIs)
|
141
|
+
**Resources**: annotation (6), completion (4)
|
142
|
+
- **Text Generation**: Advanced text completion and generation
|
143
|
+
- **Message Processing**: Send messages and control text generation
|
144
|
+
- **Annotation Management**: Create, update, and manage annotations
|
145
|
+
- **Generation Control**: Stop ongoing text generation processes
|
146
|
+
- **Streaming Support**: Real-time text generation with streaming responses
|
147
|
+
- **Type Safety**: Full type validation with Pydantic models
|
148
|
+
|
149
|
+
### Knowledge Base API (33 APIs)
|
150
|
+
**Resources**: chunk (4), dataset (6), document (10), model (1), segment (5), tag (7)
|
151
|
+
- **Dataset Management**: Complete dataset CRUD operations and content retrieval
|
152
|
+
- **Document Processing**: File upload, text processing, and batch management
|
153
|
+
- **Content Organization**: Fine-grained segmentation and chunk management
|
154
|
+
- **Tag System**: Flexible tagging and categorization system
|
155
|
+
- **Model Integration**: Embedding model information and configuration
|
156
|
+
- **Search & Retrieval**: Advanced search with multiple retrieval strategies
|
157
|
+
|
158
|
+
### Workflow API (4 APIs)
|
159
|
+
**Resources**: workflow (4)
|
160
|
+
- **Workflow Execution**: Run workflows with blocking or streaming responses
|
161
|
+
- **Execution Control**: Stop running workflows and monitor progress
|
162
|
+
- **Log Management**: Retrieve detailed execution logs and run details
|
163
|
+
- **Parameter Support**: Flexible workflow parameter configuration
|
164
|
+
|
165
|
+
### Dify Core API (9 APIs)
|
166
|
+
**Resources**: audio (2), feedback (2), file (1), info (4)
|
167
|
+
- **Audio Processing**: Speech-to-text and text-to-speech conversion
|
168
|
+
- **Feedback System**: Submit and retrieve user feedback
|
169
|
+
- **File Management**: Unified file upload and processing
|
170
|
+
- **Application Info**: App configuration, parameters, and metadata access
|
171
|
+
|
172
|
+
## 💡 Examples
|
173
|
+
|
174
|
+
Explore comprehensive examples in the [examples directory](./examples):
|
175
|
+
|
176
|
+
### Chat Examples
|
177
|
+
- [**Chat Messages**](./examples/chat/chat/) - Send messages, stop generation, get suggestions
|
178
|
+
- [**Conversation Management**](./examples/chat/conversation/) - Complete conversation operations
|
179
|
+
- [**Message Operations**](./examples/chat/message/) - Basic message operations
|
180
|
+
- [**Annotation Management**](./examples/chat/annotation/) - Annotation CRUD and reply settings
|
181
|
+
|
182
|
+
*Note: File upload and feedback examples are available in [Dify Core API](./examples/dify/) as shared services.*
|
183
|
+
|
184
|
+
### Completion Examples
|
185
|
+
- [**Completion Operations**](./examples/completion/completion/) - Text generation and completion
|
186
|
+
- [**Annotation Management**](./examples/completion/annotation/) - Annotation operations
|
187
|
+
|
188
|
+
### Knowledge Base Examples
|
189
|
+
- [**Dataset Management**](./examples/knowledge/dataset/) - Complete dataset operations
|
190
|
+
- [**Document Processing**](./examples/knowledge/document/) - File upload and text processing
|
191
|
+
- [**Content Organization**](./examples/knowledge/segment/) - Segment and chunk management
|
192
|
+
- [**Tag Management**](./examples/knowledge/tag/) - Metadata and tagging system
|
193
|
+
|
194
|
+
### Chatflow Examples
|
195
|
+
- [**Advanced Chat**](./examples/chatflow/chatflow/) - Enhanced chat with streaming and workflow events
|
196
|
+
- [**Conversation Management**](./examples/chatflow/conversation/) - Complete conversation operations
|
197
|
+
- [**Annotation Management**](./examples/chatflow/annotation/) - Annotation CRUD and reply settings
|
198
|
+
|
199
|
+
### Dify Core Examples
|
200
|
+
- [**Audio Processing**](./examples/dify/audio/) - Speech-to-text and text-to-speech
|
201
|
+
- [**Feedback Management**](./examples/dify/feedback/) - User feedback collection
|
202
|
+
- [**File Management**](./examples/dify/file/) - File upload and processing
|
203
|
+
- [**Application Info**](./examples/dify/info/) - App configuration and metadata
|
204
|
+
|
205
|
+
### Workflow Examples
|
206
|
+
- [**Workflow Operations**](./examples/workflow/workflow/) - Workflow execution and management
|
207
|
+
- [**File Upload**](./examples/workflow/file/) - File upload for workflows
|
208
|
+
|
209
|
+
For detailed examples and usage patterns, see the [examples README](./examples/README.md).
|
210
|
+
|
211
|
+
## 🛠️ Development
|
212
|
+
|
213
|
+
### Prerequisites
|
214
|
+
- Python 3.10+
|
215
|
+
- Poetry (for dependency management)
|
216
|
+
- Git (for version control)
|
217
|
+
|
218
|
+
### Setup
|
219
|
+
|
220
|
+
```bash
|
221
|
+
# Clone repository
|
222
|
+
git clone https://github.com/nodite/dify-oapi2.git
|
223
|
+
cd dify-oapi2
|
224
|
+
|
225
|
+
# Setup development environment (installs dependencies and pre-commit hooks)
|
226
|
+
make dev-setup
|
227
|
+
```
|
228
|
+
|
229
|
+
### Code Quality Tools
|
230
|
+
|
231
|
+
This project uses modern Python tooling for code quality:
|
232
|
+
|
233
|
+
- **Ruff**: Fast Python linter and formatter (replaces Black + isort + flake8)
|
234
|
+
- **MyPy**: Static type checking for type safety
|
235
|
+
- **Pre-commit**: Git hooks for automated code quality checks
|
236
|
+
- **Poetry**: Modern dependency management and packaging
|
237
|
+
|
238
|
+
```bash
|
239
|
+
# Format code
|
240
|
+
make format
|
241
|
+
|
242
|
+
# Lint code
|
243
|
+
make lint
|
244
|
+
|
245
|
+
# Fix linting issues
|
246
|
+
make fix
|
247
|
+
|
248
|
+
# Run all checks (lint + type check)
|
249
|
+
make check
|
250
|
+
|
251
|
+
# Install pre-commit hooks
|
252
|
+
make install-hooks
|
253
|
+
|
254
|
+
# Run pre-commit hooks manually
|
255
|
+
make pre-commit
|
256
|
+
```
|
257
|
+
|
258
|
+
### Testing
|
259
|
+
|
260
|
+
```bash
|
261
|
+
# Set environment variables for integration tests
|
262
|
+
export DOMAIN="https://api.dify.ai"
|
263
|
+
export CHAT_KEY="your-chat-api-key"
|
264
|
+
export CHATFLOW_KEY="your-chatflow-api-key"
|
265
|
+
export COMPLETION_KEY="your-completion-api-key"
|
266
|
+
export DIFY_KEY="your-dify-api-key"
|
267
|
+
export WORKFLOW_KEY="your-workflow-api-key"
|
268
|
+
export KNOWLEDGE_KEY="your-knowledge-api-key"
|
269
|
+
|
270
|
+
# Run tests
|
271
|
+
make test
|
272
|
+
|
273
|
+
# Run tests with coverage
|
274
|
+
make test-cov
|
275
|
+
|
276
|
+
# Run specific test module
|
277
|
+
poetry run pytest tests/knowledge/ -v
|
278
|
+
```
|
279
|
+
|
280
|
+
### Build & Publish
|
281
|
+
|
282
|
+
```bash
|
283
|
+
# Configure PyPI tokens (one-time setup)
|
284
|
+
poetry config http-basic.testpypi __token__ <your-testpypi-token>
|
285
|
+
poetry config http-basic.pypi __token__ <your-pypi-token>
|
286
|
+
|
287
|
+
# Build package
|
288
|
+
make build
|
289
|
+
|
290
|
+
# Publish to TestPyPI (for testing)
|
291
|
+
make publish-test
|
292
|
+
|
293
|
+
# Publish to PyPI (maintainers only)
|
294
|
+
make publish
|
295
|
+
```
|
296
|
+
|
297
|
+
### Project Structure
|
298
|
+
|
299
|
+
```
|
300
|
+
dify-oapi2/
|
301
|
+
├── dify_oapi/ # Main SDK package
|
302
|
+
│ ├── api/ # API service modules
|
303
|
+
│ │ ├── chat/ # Chat API (18 APIs)
|
304
|
+
│ │ │ └── v1/ # Version 1 implementation
|
305
|
+
│ │ ├── chatflow/ # Chatflow API (15 APIs)
|
306
|
+
│ │ │ └── v1/ # Version 1 implementation
|
307
|
+
│ │ ├── completion/ # Completion API (10 APIs)
|
308
|
+
│ │ │ └── v1/ # Version 1 implementation
|
309
|
+
│ │ ├── dify/ # Core Dify API (9 APIs)
|
310
|
+
│ │ │ └── v1/ # Version 1 implementation
|
311
|
+
│ │ ├── knowledge/ # Knowledge Base API (33 APIs)
|
312
|
+
│ │ │ └── v1/ # Version 1 implementation
|
313
|
+
│ │ └── workflow/ # Workflow API (6 APIs)
|
314
|
+
│ │ └── v1/ # Version 1 implementation
|
315
|
+
│ ├── core/ # Core functionality
|
316
|
+
│ │ ├── http/ # HTTP transport layer with connection pooling
|
317
|
+
│ │ ├── model/ # Base models and configurations
|
318
|
+
│ │ └── utils/ # Utility functions
|
319
|
+
│ └── client.py # Main client interface with builder pattern
|
320
|
+
├── docs/ # Comprehensive documentation
|
321
|
+
├── examples/ # Complete usage examples for all APIs
|
322
|
+
├── tests/ # Comprehensive test suite
|
323
|
+
├── pyproject.toml # Project configuration (Poetry + tools)
|
324
|
+
├── Makefile # Development automation
|
325
|
+
└── DEVELOPMENT.md # Development guide
|
326
|
+
```
|
327
|
+
|
328
|
+
## 📖 Documentation
|
329
|
+
|
330
|
+
- [**Development Guide**](./DEVELOPMENT.md) - Setup, workflow, and contribution guidelines
|
331
|
+
- [**Project Overview**](./docs/overview.md) - Architecture and technical details
|
332
|
+
- [**API Documentation**](./docs/) - Complete API documentation by service
|
333
|
+
- [**Examples**](./examples/README.md) - Comprehensive usage examples and patterns
|
334
|
+
|
335
|
+
|
336
|
+
## 🤝 Contributing
|
337
|
+
|
338
|
+
Contributions are welcome! Please follow our development workflow:
|
339
|
+
|
340
|
+
1. Fork the repository
|
341
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
342
|
+
3. Make your changes with comprehensive tests
|
343
|
+
4. Ensure code quality passes (`make check`)
|
344
|
+
5. Run the full test suite (`make test`)
|
345
|
+
6. Commit your changes (`git commit -m 'Add amazing feature'`)
|
346
|
+
7. Push to the branch (`git push origin feature/amazing-feature`)
|
347
|
+
8. Submit a pull request
|
348
|
+
|
349
|
+
See [DEVELOPMENT.md](./DEVELOPMENT.md) for detailed development guidelines.
|
350
|
+
|
351
|
+
## 📄 License
|
352
|
+
|
353
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
354
|
+
|
355
|
+
## 🔗 Links
|
356
|
+
|
357
|
+
- **PyPI Package**: https://pypi.org/project/dify-oapi2/
|
358
|
+
- **Source Code**: https://github.com/nodite/dify-oapi2
|
359
|
+
- **Dify Platform**: https://dify.ai/
|
360
|
+
- **Dify API Docs**: https://docs.dify.ai/
|
361
|
+
|
362
|
+
---
|
363
|
+
|
364
|
+
**Keywords**: dify, ai, nlp, language-processing, python-sdk, async, type-safe, api-client
|
365
|
+
|