Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 query = 'Please tell me a short story in 10 words or less.'
  14. const remote_url_files = [{
  15. type: 'image',
  16. transfer_method: 'remote_url',
  17. url: 'your_url_address'
  18. }]
  19. // Create a completion client
  20. const completionClient = new CompletionClient(API_KEY)
  21. // Create a completion message
  22. completionClient.createCompletionMessage({'query': query}, user)
  23. // Create a completion message with vision model
  24. completionClient.createCompletionMessage({'query': 'Describe the picture.'}, user, false, remote_url_files)
  25. // Create a chat client
  26. const chatClient = new ChatClient(API_KEY)
  27. // Create a chat message in stream mode
  28. const response = await chatClient.createChatMessage({}, query, user, true, null)
  29. const stream = response.data;
  30. stream.on('data', data => {
  31. console.log(data);
  32. });
  33. stream.on('end', () => {
  34. console.log('stream done');
  35. });
  36. // Create a chat message with vision model
  37. chatClient.createChatMessage({}, 'Describe the picture.', user, false, null, remote_url_files)
  38. // Fetch conversations
  39. chatClient.getConversations(user)
  40. // Fetch conversation messages
  41. chatClient.getConversationMessages(conversationId, user)
  42. // Rename conversation
  43. chatClient.renameConversation(conversationId, name, user)
  44. const client = new DifyClient(API_KEY)
  45. // Fetch application parameters
  46. client.getApplicationParameters(user)
  47. // Provide feedback for a message
  48. client.messageFeedback(messageId, rating, user)
  49. ```
  50. Replace 'your-api-key-here' with your actual Dify API key.Replace 'your-app-id-here' with your actual Dify APP ID.
  51. ## License
  52. This SDK is released under the MIT License.