Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 72 additions & 72 deletions google-cloud-dialogflow/lib/google/cloud/dialogflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,78 @@ def self.agents_available? version: :v2, transport: :grpc
false
end

##
# Create a new client object for Tools.
#
# By default, this returns an instance of
# [Google::Cloud::Dialogflow::V2::Tools::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-dialogflow-v2/latest/Google-Cloud-Dialogflow-V2-Tools-Client)
# for a gRPC client for version V2 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the Tools service is
# supported by that API version, and the corresponding gem is available, the
# appropriate versioned client will be returned.
# You can also specify a different transport by passing `:rest` or `:grpc` in
# the `transport` parameter.
#
# Raises an exception if the currently installed versioned client gem for the
# given API version does not support the given transport of the Tools service.
# You can determine whether the method will succeed by calling
# {Google::Cloud::Dialogflow.tools_available?}.
#
# ## About Tools
#
# Tool Service for LLM powered Agent Assist. Tools can be used to interact with
# remote APIs (e.g. fetching orders) to retrieve additional information as
# input to LLM.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v2`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [::Object] A client object for the specified version.
#
def self.tools version: :v2, transport: :grpc, &block
require "google/cloud/dialogflow/#{version.to_s.downcase}"

package_name = Google::Cloud::Dialogflow
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
service_module = Google::Cloud::Dialogflow.const_get(package_name).const_get(:Tools)
service_module = service_module.const_get(:Rest) if transport == :rest
service_module.const_get(:Client).new(&block)
end

##
# Determines whether the Tools service is supported by the current client.
# If true, you can retrieve a client object by calling {Google::Cloud::Dialogflow.tools}.
# If false, that method will raise an exception. This could happen if the given
# API version does not exist or does not support the Tools service,
# or if the versioned client gem needs an update to support the Tools service.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v2`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [boolean] Whether the service is available.
#
def self.tools_available? version: :v2, transport: :grpc
require "google/cloud/dialogflow/#{version.to_s.downcase}"
package_name = Google::Cloud::Dialogflow
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
return false unless package_name
service_module = Google::Cloud::Dialogflow.const_get package_name
return false unless service_module.const_defined? :Tools
service_module = service_module.const_get :Tools
if transport == :rest
return false unless service_module.const_defined? :Rest
service_module = service_module.const_get :Rest
end
service_module.const_defined? :Client
rescue ::LoadError
false
end

##
# Create a new client object for Generators.
#
Expand Down Expand Up @@ -1461,78 +1533,6 @@ def self.sip_trunks_available? version: :v2, transport: :grpc
false
end

##
# Create a new client object for Tools.
#
# By default, this returns an instance of
# [Google::Cloud::Dialogflow::V2::Tools::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-dialogflow-v2/latest/Google-Cloud-Dialogflow-V2-Tools-Client)
# for a gRPC client for version V2 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the Tools service is
# supported by that API version, and the corresponding gem is available, the
# appropriate versioned client will be returned.
# You can also specify a different transport by passing `:rest` or `:grpc` in
# the `transport` parameter.
#
# Raises an exception if the currently installed versioned client gem for the
# given API version does not support the given transport of the Tools service.
# You can determine whether the method will succeed by calling
# {Google::Cloud::Dialogflow.tools_available?}.
#
# ## About Tools
#
# Tool Service for LLM powered Agent Assist. Tools can be used to interact with
# remote APIs (e.g. fetching orders) to retrieve additional information as
# input to LLM.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v2`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [::Object] A client object for the specified version.
#
def self.tools version: :v2, transport: :grpc, &block
require "google/cloud/dialogflow/#{version.to_s.downcase}"

package_name = Google::Cloud::Dialogflow
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
service_module = Google::Cloud::Dialogflow.const_get(package_name).const_get(:Tools)
service_module = service_module.const_get(:Rest) if transport == :rest
service_module.const_get(:Client).new(&block)
end

##
# Determines whether the Tools service is supported by the current client.
# If true, you can retrieve a client object by calling {Google::Cloud::Dialogflow.tools}.
# If false, that method will raise an exception. This could happen if the given
# API version does not exist or does not support the Tools service,
# or if the versioned client gem needs an update to support the Tools service.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v2`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [boolean] Whether the service is available.
#
def self.tools_available? version: :v2, transport: :grpc
require "google/cloud/dialogflow/#{version.to_s.downcase}"
package_name = Google::Cloud::Dialogflow
.constants
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
.first
return false unless package_name
service_module = Google::Cloud::Dialogflow.const_get package_name
return false unless service_module.const_defined? :Tools
service_module = service_module.const_get :Tools
if transport == :rest
return false unless service_module.const_defined? :Rest
service_module = service_module.const_get :Rest
end
service_module.const_defined? :Client
rescue ::LoadError
false
end

##
# Create a new client object for Versions.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ def test_agents_rest
end
end

def test_tools_grpc
skip unless Google::Cloud::Dialogflow.tools_available? transport: :grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
client = Google::Cloud::Dialogflow.tools transport: :grpc do |config|
config.credentials = grpc_channel
end
assert_kind_of Google::Cloud::Dialogflow::V2::Tools::Client, client
end
end

def test_tools_rest
skip unless Google::Cloud::Dialogflow.tools_available? transport: :rest
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::Dialogflow.tools transport: :rest do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::Dialogflow::V2::Tools::Rest::Client, client
end
end

def test_generators_grpc
skip unless Google::Cloud::Dialogflow.generators_available? transport: :grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
Expand Down Expand Up @@ -461,27 +482,6 @@ def test_sip_trunks_rest
end
end

def test_tools_grpc
skip unless Google::Cloud::Dialogflow.tools_available? transport: :grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
client = Google::Cloud::Dialogflow.tools transport: :grpc do |config|
config.credentials = grpc_channel
end
assert_kind_of Google::Cloud::Dialogflow::V2::Tools::Client, client
end
end

def test_tools_rest
skip unless Google::Cloud::Dialogflow.tools_available? transport: :rest
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::Dialogflow.tools transport: :rest do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::Dialogflow::V2::Tools::Rest::Client, client
end
end

def test_versions_grpc
skip unless Google::Cloud::Dialogflow.versions_available? transport: :grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
Expand Down
Loading