@@ -14,14 +14,14 @@ The Simple and Easy-to-Use Dify Java Client, Support the use of [Dify](https://d
1414
1515[ 中文] ( ./README.md ) | English
1616
17- ### Install
18- - env requirements
17+ ### Installation
18+ - Requirements
1919``` code
2020Java : >= 17
2121Dify Version: <= 1.x
2222```
2323
24- - maven
24+ - Maven
2525``` xml
2626<dependency >
2727 <groupId >io.github.yuanbaobaoo</groupId >
@@ -30,43 +30,53 @@ Dify Version: <= 1.x
3030</dependency >
3131```
3232
33- - gradle
33+ - Gradle
3434``` gradle
3535implementation group: 'io.github.yuanbaobaoo', name: 'dify-java-client', version: '1.3.5'
3636```
3737
3838## Quick Start
39- ``` DifyClientBuilder ``` : Used to create various client instances
39+ Create client instances using ``` DifyClientBuilder ```
4040``` java
4141/**
42- * Support base()、 chat()、flow()、completion()、dataset(),which have inconsistent return types
42+ * Create a chat-type client for ChatBot/Agent/ChatFlow/Completion apps
4343 */
44- IDifyBaseClient client = DifyClientBuilder . base(). apiKey(" app-xxxx" ). baseUrl(" http://localhost:4000" ). build();
44+ IAppChatClient appClient = DifyClientBuilder . app(). chat(). apiKey(" app-xxx" ). baseUrl(" https://api.dify.ai/v1" ). build();
45+
46+ /**
47+ * Create a dataset client
48+ */
49+ IDatasetClient datasetClient = DifyClientBuilder . dataset(). apiKey(" app-xxx" ). baseUrl(" https://api.dify.ai/v1" ). build();
50+
51+ /**
52+ * Create a WebConsole client (experimental)
53+ */
54+ IWebConsoleClient webClient = DifyClientBuilder . web(" ${server}" , " ${userName}" , " ${password}" ). connect();
4555```
4656
47- ## Chat Type Client
48- Chat type clients refers to applications applicable to ChatBot, Agent, ChatFlow, and Completion.
57+ ## App Clients
58+ Use ``` DifyClientBuilder.app() ``` to create app-type clients for ChatBot, Agent, ChatFlow, and Completion applications.
4959It provides session related APIs and supports streaming return of sessions. It mainly includes the following:
50- - [ ``` IDifyBaseClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/feature/knowledge-api/ src/main/java/io/github/yuanbaobaoo/dify/app/IDifyBaseClient .java )
51- - [ ``` IDifyChatClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/feature/knowledge-api/ src/main/java/io/github/yuanbaobaoo/dify/app/IDifyChatClient .java )
52- - [ ``` IDifyFlowClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/feature/knowledge-api/ src/main/java/io/github/yuanbaobaoo/dify/app/IDifyFlowClient .java )
53- - [ ``` IDifyCompletion ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/feature/knowledge-api/ src/main/java/io/github/yuanbaobaoo/dify/app/IDifyCompletion .java )
60+ - [ ``` IAppBaseClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/master/ src/main/java/io/github/yuanbaobaoo/dify/app/IAppBaseClient .java )
61+ - [ ``` IAppChatClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/master/ src/main/java/io/github/yuanbaobaoo/dify/app/IAppChatClient .java )
62+ - [ ``` IAppFlowClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/master/ src/main/java/io/github/yuanbaobaoo/dify/app/IAppFlowClient .java )
63+ - [ ``` IAppCompletion ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/master/ src/main/java/io/github/yuanbaobaoo/dify/app/IAppCompletion .java )
5464
55- ### 1、IDifyBaseClient
56- base client, encapsulates some public APIs and authentication logic, and provides simple and easy-to-use calling methods
65+ ### 1、IAppBaseClient
66+ Base client providing common Dify APIs:
5767``` java
58- IDifyBaseClient client = DifyClientBuilder . base(). apiKey(" app-xxxx" ). baseUrl(" http ://localhost:4000 " ). build();
68+ IAppBaseClient client = DifyClientBuilder . app() . base(). apiKey(" app-xxxx" ). baseUrl(" https ://api.dify.ai/v1 " ). build();
5969
6070// Call preset API
6171String metaInfo = client. getAppMetaInfo();
6272// Upload file
6373DifyFileResult result = client. uploadFile(new File (" pom.xml" ), " abc-123" );
6474```
6575
66- ### 2、IDifyChatClient
67- scope = ChatBot、 Agent、 ChatFlow, extends ``` IDifyBaseClient ``` , provides conversation APIs
76+ ### 2、IAppChatClient
77+ For ChatBot/ Agent/ ChatFlow apps ( extends IAppBaseClient):
6878``` java
69- IDifyChatClient chatClient = DifyClientBuilder . chat(). apiKey(" app-xxxx" ). baseUrl(" http ://localhost:4000 /v1" ). build();
79+ IAppChatClient client = DifyClientBuilder . app() . chat(). apiKey(" app-xxxx" ). baseUrl(" https ://api.dify.ai /v1" ). build();
7080
7181// create message
7282ParamMessage m = ParamMessage . builder(). query(" Who are you" ). user(" abc-123" ). inputs(new HashMap<> () {{
@@ -87,10 +97,10 @@ CompletableFuture<Void> future = client.sendMessagesAsync(m, (r) -> {
8797});
8898```
8999
90- ### 3、IDifyFlowClient
91- scope = WorkFlow, extends ``` IDifyBaseClient ``` , provides workflow APIs
100+ ### 3、IAppFlowClient
101+ For WorkFlow apps ( extends IAppBaseClient):
92102``` java
93- IDifyFlowClient flowClient = DifyClientBuilder . flow(). apiKey(" app-xxxx" ). baseUrl(" http ://localhost:4000 /v1" ). build();
103+ IAppFlowClient flowClient = DifyClientBuilder . app() . flow(). apiKey(" app-xxxx" ). baseUrl(" https ://api.dify.ai /v1" ). build();
94104
95105// create message
96106ParamMessage m = ParamMessage . builder(). user(" abc-123" ). inputs(new HashMap<> () {{
@@ -107,10 +117,10 @@ CompletableFuture<Void> future = client.runStreaming(m, (r) -> {
107117});
108118```
109119
110- ### 4、IDifyCompletion
120+ ### 4、IAppCompletion
111121scope = Completion, extends ``` IDifyBaseClient ``` , provides completion APIs
112122``` java
113- IDifyCompletion completion = DifyClientBuilder . completion(). apiKey(" app-xxxx" ). baseUrl(" http ://localhost:4000 /v1" ). build();
123+ IAppCompletion completion = DifyClientBuilder . completion(). flow() . apiKey(" app-xxxx" ). baseUrl(" https ://api.dify.ai /v1" ). build();
114124
115125// create message
116126ParamMessage m = ParamMessage . builder(). query(" Java为什么叫Java" ). user(" abc-123" ). build();
@@ -124,16 +134,16 @@ CompletableFuture<Void> future = completion.sendMessagesAsync(m, (r) -> {
124134});
125135```
126136
127- ## Dataset(Knowledge) Client
137+ ## Dataset Clients
128138The current project provides the definition of internal knowledge base client and external knowledge base related types,
129139of which the external knowledge base has not been specifically implemented.
130140
131141### Dify Dataset: IDifyDatasetClient
132142For specific API definitions, please refer to [ ``` io.github.yuanbaobaoo.dify.client.dataset.IDifyDatasetClient ``` ] ( https://github.com/yuanbaobaoo/dify-java-client/blob/feature/knowledge-api/src/main/java/io/github/yuanbaobaoo/dify/dataset/IDatasetClient.java )
133143
134- #### Reference
144+ #### Examples
135145``` java
136- IDatasetClient client = DifyClientBuilder . dataset(). apiKey(" dataset-xxxx" ). baseUrl(" http ://localhost:4000 " ). build();
146+ IDatasetClient client = DifyClientBuilder . dataset(). apiKey(" dataset-xxxx" ). baseUrl(" https ://api.dify.ai/v1 " ). build();
137147
138148// create params
139149ParamDataset dataset = ParamDataset . builder()
@@ -144,14 +154,14 @@ ParamDataset dataset = ParamDataset.builder()
144154client. create(dataset);
145155```
146156
147- #### Hero Class
157+ #### Hero Classes
148158In the project, for the tool class of the knowledge base, in addition to providing related methods based on ``` IDatasetClient ``` ,
149159it also provides Hero class to support the operation of the knowledge base.Which way to use depends on your needs.
150160
151161- Case 1: add document
152162``` java
153163// dify config
154- DifyConfig config = DifyConfig . builder(). server(" http ://localhost:4000 " ). apiKey(" dataset-xxxx" ). build();
164+ DifyConfig config = DifyConfig . builder(). server(" https ://api.dify.ai/v1 " ). apiKey(" dataset-xxxx" ). build();
155165
156166// create params
157167ParamDocument document = ParamDocument . builder()
@@ -171,7 +181,7 @@ Mode2、use DifyClientBuilder to build the Hero object
171181DatasetHero dataset = DifyClientBuilder . dataset(). config(config). of(" Dataset Id" );
172182dataset. insertTxt(document);
173183```
174- Mod3 、use Hero Class
184+ Mode3 、use Hero Class
175185``` java
176186DatasetHero dataset = DatasetHero . of(" Dataset Id" , config);
177187dataset. insertTxt(document);
@@ -180,7 +190,7 @@ dataset.insertTxt(document);
180190- Case 2: update document
181191``` java
182192// dify config
183- DifyConfig config = DifyConfig . builder(). server(" http ://localhost:4000 " ). apiKey(" dataset-xxxx" ). build();
193+ DifyConfig config = DifyConfig . builder(). server(" https ://api.dify.ai/v1 " ). apiKey(" dataset-xxxx" ). build();
184194
185195// create params
186196ParamDocument document = ParamDocument . builder()
@@ -204,7 +214,7 @@ DocumentHero documentHero = DocumentHero.of("Dataset ID", "Document ID", config)
204214documentHero. updateByText(document);
205215```
206216
207- ### Dify External Dataset: IKnowledgeService
217+ ### External Dataset: IKnowledgeService
208218The current project dose not implement the knowledge API, and only declare parameter objects and interfaces
209219``` java
210220public interface IKnowledgeService {
@@ -238,7 +248,15 @@ class KnowledgeService implements IKnowledgeService {
238248}
239249```
240250
241- ### Exception Type
251+ ## Custom Requests
252+ Any Client object has an httpClient () method,
253+ This method will return a SimpleFHIR object that has been injected with API key and server URL or login token attributes.
254+ You can use this object to make custom interface requests.
255+ ``` java
256+ SimpleHttpClient http = client. httpClient();
257+ ```
258+
259+ ## Exception Type
242260- ** DifyException**
243261> By default, when the normal request returns http status>=400, an exception object ``` DiffyException ``` will be thrown.
244262 This object receives the '``` status ``` , ``` code ``` , ``` message ``` , ``` params ``` .
0 commit comments