Giter Site home page Giter Site logo

dify-java-client's Introduction

Dify Java SDK

This is the Java SDK for the Dify API, which allows you to seamlessly integrate Dify into your Java applications.

Installation

Please ensure that you have included the necessary dependencies in your project, such as fastjson2, okhttp3, etc. You can use Maven, Gradle, or any other dependency management tool of your choice. The SDK itself can be included once it is published to a package repository.

For the sake of this README, let's assume the SDK is available on Maven Central:

<dependency>
    <groupId>ai.dify</groupId>
    <artifactId>java-client</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Once the SDK is installed, you can use it in your project as follows:

import ai.dify.javaclient.DifyClient;
import ai.dify.javaclient.ChatClient;
import ai.dify.javaclient.CompletionClient;
import okhttp3.Response;

public class DifyApp {

    private static final String API_KEY = "your-api-key-here";

    public static void main(String[] args) {
        try {
            String user = "random-user-id";
            String inputs = "{\"name\":\"test name a\"}";
            String query = "Please tell me a short story in 10 words or less.";
            boolean responseMode = true;

            // Create a completion client
            CompletionClient completionClient = new CompletionClient(API_KEY);
            Response completionResponse = completionClient.createCompletionMessage(inputs, query, user, responseMode);
            System.out.println(completionResponse.body().string());

            // Create a chat client
            ChatClient chatClient = new ChatClient(API_KEY);
            // Create a chat message
            Response chatResponse = chatClient.createChatMessage(inputs, query, user, true, null);
            System.out.println(chatResponse.body().string());

            // Fetch conversations
            chatClient.getConversations(user);
            // Rename conversation
            String conversationId = "example-conversation-id";
            String name = "new-name";
            chatClient.renameConversation(conversationId, name, user);

            // And so on for other methods...

            DifyClient client = new DifyClient(API_KEY);
            // Fetch application parameters
            client.getApplicationParameters(user);

            // Provide feedback for a message
            String messageId = "your-message-id";
            String rating = "5";
            client.messageFeedback(messageId, rating, user);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Replace 'your-api-key-here' with your actual Dify API key.

License

This SDK is released under the MIT License.

dify-java-client's People

Contributors

katytao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.