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