Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/ai/dify/javaclient/ChatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ private String generateQueryParams(Map<String, String> params) {
*/
public Response createChatMessage(String inputs, String query, String user, boolean stream, String conversation_id) throws DifyClientException {
JSONObject json = new JSONObject();
json.put("inputs", inputs);
json.put("query", query);
JSONObject inputsJson = new JSONObject();
inputsJson.put("query", query);
json.put("inputs", inputsJson);
json.put("user", user);
json.put("response_mode", stream ? "streaming" : "blocking");
if (conversation_id != null && !conversation_id.isEmpty()) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ai/dify/javaclient/CompletionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public CompletionClient(String apiKey, String baseUrl) {
*/
public Response createCompletionMessage(String inputs, String query, String user, boolean stream) throws DifyClientException {
JSONObject json = new JSONObject();
json.put("inputs", inputs);
json.put("query", query);
JSONObject inputsJson = new JSONObject();
inputsJson.put("query", query);
json.put("inputs", inputsJson);
json.put("user", user);
json.put("response_mode", stream ? "streaming" : "blocking");

Expand Down
24 changes: 21 additions & 3 deletions src/main/java/ai/dify/javaclient/DifyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import okhttp3.*;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
* This class serves as a client for interacting with the Dify API.
* It provides methods for sending various types of requests to the API.
Expand Down Expand Up @@ -38,13 +40,29 @@ public DifyClient(String apiKey) {
/**
* Constructs a new DifyClient with the provided API key and base URL.
*
* @param apiKey The API key to use for authentication.
* @param baseUrl The base URL of the Dify API.
* @param apiKey The API key to use for authentication.
* @param baseUrl The base URL of the Dify API.
*/
public DifyClient(String apiKey, String baseUrl) {
this(apiKey, baseUrl, 1L, TimeUnit.HOURS);
}

/**
* Constructs a new DifyClient with the provided API key and base URL.
*
* @param apiKey The API key to use for authentication.
* @param baseUrl The base URL of the Dify API.
* @param timeout The timeout number
* @param timeOutUnit The timeout unit
*/
public DifyClient(String apiKey, String baseUrl, Long timeout, TimeUnit timeOutUnit) {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
this.client = new OkHttpClient();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
this.client = builder.connectTimeout(timeout, timeOutUnit)
.readTimeout(timeout, timeOutUnit)
.writeTimeout(timeout, timeOutUnit)
.build();
}

/**
Expand Down