From 36080fe352266daf3d529f353e6940a68f68c07f Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:36:39 +0800 Subject: [PATCH] fix: add missing code (#788) --- sdks/ruby-client/dify_client.gemspec | 2 +- sdks/ruby-client/dify_client/client.rb | 91 -------------------------- 2 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 sdks/ruby-client/dify_client/client.rb diff --git a/sdks/ruby-client/dify_client.gemspec b/sdks/ruby-client/dify_client.gemspec index 11ee07d9f0..3aa3196392 100644 --- a/sdks/ruby-client/dify_client.gemspec +++ b/sdks/ruby-client/dify_client.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "lib/dify_client/version" +require_relative "lib/version" Gem::Specification.new do |spec| spec.name = "dify_client" diff --git a/sdks/ruby-client/dify_client/client.rb b/sdks/ruby-client/dify_client/client.rb deleted file mode 100644 index aacee6cc31..0000000000 --- a/sdks/ruby-client/dify_client/client.rb +++ /dev/null @@ -1,91 +0,0 @@ -require 'net/http' -require 'json' -require 'uri' - -class DifyClient - def initialize(api_key) - @api_key = api_key - @base_url = "https://api.dify.ai/v1" - end - - def _send_request(method, endpoint, data = nil, params = nil, stream = false) - uri = URI.parse("#{@base_url}#{endpoint}") - - http = Net::HTTP.new(uri.host, uri.port) - http.use_ssl = true - - headers = { - "Authorization" => "Bearer #{@api_key}", - "Content-Type" => "application/json" - } - - if method == "GET" - uri.query = URI.encode_www_form(params) if params - request = Net::HTTP::Get.new(uri.request_uri, headers) - elsif method == "POST" - request = Net::HTTP::Post.new(uri.request_uri, headers) - request.body = data.to_json - end - - response = http.request(request) - return response - end - - def message_feedback(message_id, rating, user) - data = { - rating: rating, - user: user - } - return _send_request("POST", "/messages/#{message_id}/feedbacks", data) - end - - def get_application_parameters(user) - params = {user: user} - return _send_request("GET", "/parameters", nil, params) - end -end - -class CompletionClient < DifyClient - def create_completion_message(inputs, query, response_mode, user) - data = { - inputs: inputs, - query: query, - response_mode: response_mode, - user: user - } - return _send_request("POST", "/completion-messages", data, nil, response_mode == "streaming") - end -end - -class ChatClient < DifyClient - def create_chat_message(inputs, query, user, response_mode = "blocking", conversation_id = nil) - data = { - inputs: inputs, - query: query, - user: user, - response_mode: response_mode - } - data[:conversation_id] = conversation_id if conversation_id - - return _send_request("POST", "/chat-messages", data, nil, response_mode == "streaming") - end - - def get_conversation_messages(user, conversation_id = nil, first_id = nil, limit = nil) - params = {user: user} - params[:conversation_id] = conversation_id if conversation_id - params[:first_id] = first_id if first_id - params[:limit] = limit if limit - - return _send_request("GET", "/messages", nil, params) - end - - def get_conversations(user, last_id = nil, limit = nil, pinned = nil) - params = {user: user, last_id: last_id, limit: limit, pinned: pinned} - return _send_request("GET", "/conversations", nil, params) - end - - def rename_conversation(conversation_id, name, user) - data = {name: name, user: user} - return _send_request("POST", "/conversations/#{conversation_id}/name", data) - end -end