From 80e390b906b848eae41e185c97acb83fd22cc4fa Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 18 Apr 2024 11:23:18 +0800 Subject: [PATCH] feat: add workflow api in Node.js sdk (#3584) --- sdks/nodejs-client/index.js | 21 ++++++++++++++++++++- sdks/nodejs-client/package.json | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sdks/nodejs-client/index.js b/sdks/nodejs-client/index.js index b59d9c42e..127d62cf8 100644 --- a/sdks/nodejs-client/index.js +++ b/sdks/nodejs-client/index.js @@ -37,7 +37,11 @@ export const routes = { fileUpload: { method: "POST", url: () => `/files/upload`, - } + }, + runWorkflow: { + method: "POST", + url: () => `/workflows/run`, + }, }; export class DifyClient { @@ -143,6 +147,21 @@ export class CompletionClient extends DifyClient { stream ); } + + runWorkflow(inputs, user, stream = false, files = null) { + const data = { + inputs, + user, + response_mode: stream ? "streaming" : "blocking", + }; + return this.sendRequest( + routes.runWorkflow.method, + routes.runWorkflow.url(), + data, + null, + stream + ); + } } export class ChatClient extends DifyClient { diff --git a/sdks/nodejs-client/package.json b/sdks/nodejs-client/package.json index a937040a5..83b2f8a4c 100644 --- a/sdks/nodejs-client/package.json +++ b/sdks/nodejs-client/package.json @@ -1,6 +1,6 @@ { "name": "dify-client", - "version": "2.2.1", + "version": "2.3.1", "description": "This is the Node.js SDK for the Dify.AI API, which allows you to easily integrate Dify.AI into your Node.js applications.", "main": "index.js", "type": "module",