Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: promote grounding check APIs to v1 GA #25965

Merged
merged 2 commits into from
May 30, 2024
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
140 changes: 140 additions & 0 deletions google-cloud-discovery_engine/lib/google/cloud/discovery_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,43 @@ def self.completion_service version: :v1, transport: :grpc, &block
service_module.const_get(:Client).new(&block)
end

##
# Create a new client object for ControlService.
#
# By default, this returns an instance of
# [Google::Cloud::DiscoveryEngine::V1::ControlService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/latest/Google-Cloud-DiscoveryEngine-V1-ControlService-Client)
# for a gRPC client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the ControlService 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.
#
# ## About ControlService
#
# Service for performing CRUD operations on Controls.
# Controls allow for custom logic to be implemented in the serving path.
# Controls need to be attached to a Serving Config to be considered during a
# request.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [::Object] A client object for the specified version.
#
def self.control_service version: :v1, transport: :grpc, &block
require "google/cloud/discovery_engine/#{version.to_s.downcase}"

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

##
# Create a new client object for SearchService.
#
Expand Down Expand Up @@ -252,6 +289,109 @@ def self.engine_service version: :v1, transport: :grpc, &block
service_module.const_get(:Client).new(&block)
end

##
# Create a new client object for GroundedGenerationService.
#
# By default, this returns an instance of
# [Google::Cloud::DiscoveryEngine::V1::GroundedGenerationService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/latest/Google-Cloud-DiscoveryEngine-V1-GroundedGenerationService-Client)
# for a gRPC client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the GroundedGenerationService 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.
#
# ## About GroundedGenerationService
#
# Service for grounded generation.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [::Object] A client object for the specified version.
#
def self.grounded_generation_service version: :v1, transport: :grpc, &block
require "google/cloud/discovery_engine/#{version.to_s.downcase}"

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

##
# Create a new client object for ProjectService.
#
# By default, this returns an instance of
# [Google::Cloud::DiscoveryEngine::V1::ProjectService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/latest/Google-Cloud-DiscoveryEngine-V1-ProjectService-Client)
# for a gRPC client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the ProjectService 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.
#
# ## About ProjectService
#
# Service for operations on the
# Project.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [::Object] A client object for the specified version.
#
def self.project_service version: :v1, transport: :grpc, &block
require "google/cloud/discovery_engine/#{version.to_s.downcase}"

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

##
# Create a new client object for RankService.
#
# By default, this returns an instance of
# [Google::Cloud::DiscoveryEngine::V1::RankService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/latest/Google-Cloud-DiscoveryEngine-V1-RankService-Client)
# for a gRPC client for version V1 of the API.
# However, you can specify a different API version by passing it in the
# `version` parameter. If the RankService 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.
#
# ## About RankService
#
# Service for ranking text records.
#
# @param version [::String, ::Symbol] The API version to connect to. Optional.
# Defaults to `:v1`.
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
# @return [::Object] A client object for the specified version.
#
def self.rank_service version: :v1, transport: :grpc, &block
require "google/cloud/discovery_engine/#{version.to_s.downcase}"

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

##
# Create a new client object for RecommendationService.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ def test_completion_service_rest
end
end

def test_control_service_grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
client = Google::Cloud::DiscoveryEngine.control_service transport: :grpc do |config|
config.credentials = grpc_channel
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::ControlService::Client, client
end
end

def test_control_service_rest
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::DiscoveryEngine.control_service transport: :rest do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::ControlService::Rest::Client, client
end
end

def test_search_service_grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
Expand Down Expand Up @@ -147,6 +166,63 @@ def test_engine_service_rest
end
end

def test_grounded_generation_service_grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
client = Google::Cloud::DiscoveryEngine.grounded_generation_service transport: :grpc do |config|
config.credentials = grpc_channel
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::GroundedGenerationService::Client, client
end
end

def test_grounded_generation_service_rest
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::DiscoveryEngine.grounded_generation_service transport: :rest do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::GroundedGenerationService::Rest::Client, client
end
end

def test_project_service_grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
client = Google::Cloud::DiscoveryEngine.project_service transport: :grpc do |config|
config.credentials = grpc_channel
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::ProjectService::Client, client
end
end

def test_project_service_rest
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::DiscoveryEngine.project_service transport: :rest do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::ProjectService::Rest::Client, client
end
end

def test_rank_service_grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
client = Google::Cloud::DiscoveryEngine.rank_service transport: :grpc do |config|
config.credentials = grpc_channel
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::RankService::Client, client
end
end

def test_rank_service_rest
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
client = Google::Cloud::DiscoveryEngine.rank_service transport: :rest do |config|
config.credentials = :dummy_credentials
end
assert_kind_of Google::Cloud::DiscoveryEngine::V1::RankService::Rest::Client, client
end
end

def test_recommendation_service_grpc
Gapic::ServiceStub.stub :new, DummyStub.new do
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
Expand Down