You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Dify Node.js SDK
  2. This is the Node.js SDK for the Dify API, which allows you to easily integrate Dify into your Node.js applications.
  3. ## Install
  4. ```bash
  5. npm install dify-client
  6. ```
  7. ## Usage
  8. After installing the SDK, you can use it in your project like this:
  9. ```js
  10. import { DifyClient, ChatClient, CompletionClient } from 'dify-client'
  11. const API_KEY = 'your-api-key-here'
  12. const user = `random-user-id`
  13. const inputs = {
  14. name: 'test name a'
  15. }
  16. const query = "Please tell me a short story in 10 words or less."
  17. // Create a completion client
  18. const completionClient = new CompletionClient(API_KEY)
  19. // Create a completion message
  20. completionClient.createCompletionMessage(inputs, query, responseMode, user)
  21. // Create a chat client
  22. const chatClient = new ChatClient(API_KEY)
  23. // Create a chat message in stream mode
  24. const response = await chatClient.createChatMessage(inputs, query, user, true, null)
  25. const stream = response.data;
  26. stream.on('data', data => {
  27. console.log(data);
  28. });
  29. stream.on('end', () => {
  30. console.log("stream done");
  31. });
  32. // Fetch conversations
  33. chatClient.getConversations(user)
  34. // Fetch conversation messages
  35. chatClient.getConversationMessages(conversationId, user)
  36. // Rename conversation
  37. chatClient.renameConversation(conversationId, name, user)
  38. const client = new DifyClient(API_KEY)
  39. // Fetch application parameters
  40. client.getApplicationParameters(user)
  41. // Provide feedback for a message
  42. client.messageFeedback(messageId, rating, user)
  43. ```
  44. Replace 'your-api-key-here' with your actual Dify API key.Replace 'your-app-id-here' with your actual Dify APP ID.
  45. ## License
  46. This SDK is released under the MIT License.