Class: Dify::ChatClient

Inherits:
Client
  • Object
show all
Defined in:
lib/dify/chat_client.rb

Instance Method Summary collapse

Methods inherited from Client

#_send_request, #get_application_parameters, #initialize, #message_feedback

Constructor Details

This class inherits a constructor from Dify::Client

Instance Method Details

#create_chat_message(parameters = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/dify/chat_client.rb', line 5

def create_chat_message(parameters = {}, &block)
  raise ArgumentError, "Invalid parameters" unless parameters.is_a?(Hash)
  raise ArgumentError, "Invalid user" unless parameters[:user]
  raise ArgumentError, "Invalid query" unless parameters[:query]

  parameters[:inputs] ||= {}
  parameters[:response_mode] ||= "streaming"
  stream = parameters[:response_mode] == "streaming"

  _send_request("POST", "/chat-messages", parameters, nil, stream, &block)
end

#get_conversation_messages(parameters = {}) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/dify/chat_client.rb', line 17

def get_conversation_messages(parameters = {})
  raise ArgumentError, "Invalid parameters" unless parameters.is_a?(Hash)
  raise ArgumentError, "Invalid user" unless parameters[:user]
  raise ArgumentError, "Invalid conversation_id" unless parameters[:conversation_id]

  _send_request("GET", "/messages", nil, parameters)
end

#get_conversations(parameters = {}) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/dify/chat_client.rb', line 25

def get_conversations(parameters = {})
  raise ArgumentError, "Invalid parameters" unless parameters.is_a?(Hash)
  raise ArgumentError, "Invalid user" unless parameters[:user]

  _send_request("GET", "/conversations", nil, parameters)
end

#rename_conversation(parameters = {}) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
# File 'lib/dify/chat_client.rb', line 32

def rename_conversation(parameters = {})
  raise ArgumentError, "Invalid parameters" unless parameters.is_a?(Hash)
  raise ArgumentError, "Invalid user" unless parameters[:user]
  raise ArgumentError, "Invalid conversation_id" unless parameters[:conversation_id]
  raise ArgumentError, "Invalid name" unless parameters[:name]

  _send_request("POST", "/conversations/#{parameters[:conversation_id]}/name", parameters)
end