From 4b604bd79af51cc3ca51bc02e8be5bee9b2ddf40 Mon Sep 17 00:00:00 2001 From: Om Kashyap Avashia <147749578+omavashia2005@users.noreply.github.com> Date: Thu, 17 Jul 2025 12:39:14 +0530 Subject: [PATCH] fix: Python SDK WorkflowClient and KnowledgeBase client imports fixed. Added documentation for WorkflowClient. (#22476) Co-authored-by: crazywoola <427733928@qq.com> --- sdks/python-client/README.md | 39 ++++++++++++++++++++++ sdks/python-client/dify_client/__init__.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/sdks/python-client/README.md b/sdks/python-client/README.md index 8949ef08f..7401fd2fd 100644 --- a/sdks/python-client/README.md +++ b/sdks/python-client/README.md @@ -183,3 +183,42 @@ rename_conversation_response.raise_for_status() print('[rename result]') print(rename_conversation_response.json()) ``` + +* Using the Workflow Client +```python +import json +import requests +from dify_client import WorkflowClient + +api_key = "your_api_key" + +# Initialize Workflow Client +client = WorkflowClient(api_key) + +# Prepare parameters for Workflow Client +user_id = "your_user_id" +context = "previous user interaction / metadata" +user_prompt = "What is the capital of France?" + +inputs = { + "context": context, + "user_prompt": user_prompt, + # Add other input fields expected by your workflow (e.g., additional context, task parameters) + +} + +# Set response mode (default: streaming) +response_mode = "blocking" + +# Run the workflow +response = client.run(inputs=inputs, response_mode=response_mode, user=user_id) +response.raise_for_status() + +# Parse result +result = json.loads(response.text) + +answer = result.get("data").get("outputs") + +print(answer["answer"]) + +``` diff --git a/sdks/python-client/dify_client/__init__.py b/sdks/python-client/dify_client/__init__.py index 6fa9d190e..b557a9ce9 100644 --- a/sdks/python-client/dify_client/__init__.py +++ b/sdks/python-client/dify_client/__init__.py @@ -1 +1 @@ -from dify_client.client import ChatClient, CompletionClient, DifyClient +from dify_client.client import ChatClient, CompletionClient, WorkflowClient, KnowledgeBaseClient, DifyClient