Skip to content

Commit 3f04309

Browse files
committed
feat: add missing text generation APIs
- Add stop_completion_message to CompletionClient - Add get_app_feedbacks to DifyClient - Add get_end_user_info to DifyClient - Add corresponding async methods
1 parent a3ce501 commit 3f04309

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

dify_client/async_client.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ async def get_file_preview(self, file_id: str):
178178
"""Get file preview by file ID."""
179179
return await self._send_request("GET", f"/files/{file_id}/preview")
180180

181+
async def get_app_feedbacks(self, page: int = 1, limit: int = 20):
182+
"""Get message feedbacks for the application.
183+
184+
Args:
185+
page: Page number (default: 1)
186+
limit: Number of items per page (default: 20)
187+
188+
Returns:
189+
httpx.Response object
190+
"""
191+
params = {"page": page, "limit": limit}
192+
return await self._send_request("GET", "/app/feedbacks", params=params)
193+
194+
async def get_end_user_info(self, end_user_id: str):
195+
"""Get end user information.
196+
197+
Args:
198+
end_user_id: End user ID
199+
200+
Returns:
201+
httpx.Response object
202+
"""
203+
return await self._send_request("GET", f"/end-users/{end_user_id}")
204+
181205
# App Configuration APIs
182206
async def get_app_site_config(self, app_id: str):
183207
"""Get app site configuration.
@@ -281,6 +305,19 @@ async def create_completion_message(
281305
stream=(response_mode == "streaming"),
282306
)
283307

308+
async def stop_completion_message(self, task_id: str, user: str):
309+
"""Stop a running completion message generation.
310+
311+
Args:
312+
task_id: Task ID from the completion message response
313+
user: User identifier (must match the one used in the original request)
314+
315+
Returns:
316+
httpx.Response object
317+
"""
318+
data = {"user": user}
319+
return await self._send_request("POST", f"/completion-messages/{task_id}/stop", data)
320+
284321

285322
class AsyncChatClient(AsyncDifyClient):
286323
"""Async client for Chat API operations."""

dify_client/client.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,32 @@ def get_file_preview(self, file_id: str):
255255
"""Get file preview by file ID."""
256256
return self._send_request("GET", f"/files/{file_id}/preview")
257257

258+
def get_app_feedbacks(self, page: int = 1, limit: int = 20):
259+
"""Get message feedbacks for the application.
260+
261+
Args:
262+
page: Page number (default: 1)
263+
limit: Number of items per page (default: 20)
264+
265+
Returns:
266+
httpx.Response object
267+
"""
268+
self._validate_params(page=page, limit=limit)
269+
params = {"page": page, "limit": limit}
270+
return self._send_request("GET", "/app/feedbacks", params=params)
271+
272+
def get_end_user_info(self, end_user_id: str):
273+
"""Get end user information.
274+
275+
Args:
276+
end_user_id: End user ID
277+
278+
Returns:
279+
httpx.Response object
280+
"""
281+
self._validate_params(end_user_id=end_user_id)
282+
return self._send_request("GET", f"/end-users/{end_user_id}")
283+
258284
# App Configuration APIs
259285
def get_app_site_config(self, app_id: str):
260286
"""Get app site configuration.
@@ -353,6 +379,20 @@ def create_completion_message(
353379
stream=(response_mode == "streaming"),
354380
)
355381

382+
def stop_completion_message(self, task_id: str, user: str):
383+
"""Stop a running completion message generation.
384+
385+
Args:
386+
task_id: Task ID from the completion message response
387+
user: User identifier (must match the one used in the original request)
388+
389+
Returns:
390+
httpx.Response object
391+
"""
392+
self._validate_params(task_id=task_id, user=user)
393+
data = {"user": user}
394+
return self._send_request("POST", f"/completion-messages/{task_id}/stop", data)
395+
356396

357397
class ChatClient(DifyClient):
358398
def create_chat_message(

0 commit comments

Comments
 (0)