Sha256: 157c5759935c7d54fcdaf622a5f307acedde1fb2434c34d72dfc61ffecf931b5

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Dify
  class ChatClient < Client
    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

    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

    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dify-0.1.5 lib/dify/chat_client.rb
dify-0.1.2 lib/dify/chat_client.rb