Skip to content

Commit f61f34a

Browse files
feat: add a QueryData API for NL2SQL conversion (#32258)
feat: A new message `AgentContextReference` is added feat: A new method `QueryData` is added to service `DataChatService` feat: A new message `QueryDataRequest` is added feat: A new message `GenerationOptions` is added feat: A new message `QueryDataContext` is added feat: A new message `QueryDataResponse` is added feat: A new message `ExecutedQueryResult` is added feat: A new field `alloydb` is added to message `.google.cloud.geminidataanalytics.v1beta.DatasourceReferences` feat: A new field `spanner_reference` is added to message `.google.cloud.geminidataanalytics.v1beta.DatasourceReferences` feat: A new field `cloud_sql_reference` is added to message `.google.cloud.geminidataanalytics.v1beta.DatasourceReferences` feat: A new message `AlloyDbReference` is added feat: A new message `AlloyDbDatabaseReference` is added feat: A new message `SpannerReference` is added feat: A new message `SpannerDatabaseReference` is added feat: A new message `CloudSqlReference` is added feat: A new message `CloudSqlDatabaseReference` is added feat: A new field `alloy_db_reference` is added to message `.google.cloud.geminidataanalytics.v1beta.Datasource` feat: A new field `spanner_reference` is added to message `.google.cloud.geminidataanalytics.v1beta.Datasource` feat: A new field `cloud_sql_reference` is added to message `.google.cloud.geminidataanalytics.v1beta.Datasource` PiperOrigin-RevId: 842905100 Source-Link: googleapis/googleapis@b32495a Source-Link: googleapis/googleapis-gen@f67a35a Copy-Tag: eyJwIjoiZ29vZ2xlLWNsb3VkLWdlbWluaV9kYXRhX2FuYWx5dGljcy12MWJldGEvLk93bEJvdC55YW1sIiwiaCI6ImY2N2EzNWE2ZDRkMjk1MjVkNmQ1OTAwMzA3YWE3MTljZjUxMzMyYjMifQ== * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7869da2 commit f61f34a

16 files changed

Lines changed: 888 additions & 9 deletions

File tree

google-cloud-gemini_data_analytics-v1beta/.owlbot-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"lib/google/cloud/gemini_data_analytics/v1beta/data_chat_service/rest/service_stub.rb",
3535
"lib/google/cloud/gemini_data_analytics/v1beta/rest.rb",
3636
"lib/google/cloud/gemini_data_analytics/v1beta/version.rb",
37+
"lib/google/cloud/geminidataanalytics/v1beta/agent_context_pb.rb",
3738
"lib/google/cloud/geminidataanalytics/v1beta/context_pb.rb",
3839
"lib/google/cloud/geminidataanalytics/v1beta/conversation_pb.rb",
3940
"lib/google/cloud/geminidataanalytics/v1beta/credentials_pb.rb",
@@ -50,6 +51,7 @@
5051
"proto_docs/google/api/field_info.rb",
5152
"proto_docs/google/api/launch_stage.rb",
5253
"proto_docs/google/api/resource.rb",
54+
"proto_docs/google/cloud/geminidataanalytics/v1beta/agent_context.rb",
5355
"proto_docs/google/cloud/geminidataanalytics/v1beta/context.rb",
5456
"proto_docs/google/cloud/geminidataanalytics/v1beta/conversation.rb",
5557
"proto_docs/google/cloud/geminidataanalytics/v1beta/credentials.rb",
@@ -86,6 +88,7 @@
8688
"snippets/data_chat_service/get_conversation.rb",
8789
"snippets/data_chat_service/list_conversations.rb",
8890
"snippets/data_chat_service/list_messages.rb",
91+
"snippets/data_chat_service/query_data.rb",
8992
"snippets/snippet_metadata_google.cloud.geminidataanalytics.v1beta.json",
9093
"test/google/cloud/gemini_data_analytics/v1beta/data_agent_service_operations_test.rb",
9194
"test/google/cloud/gemini_data_analytics/v1beta/data_agent_service_paths_test.rb",

google-cloud-gemini_data_analytics-v1beta/gapic_metadata.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
"methods": [
8989
"list_messages"
9090
]
91+
},
92+
"QueryData": {
93+
"methods": [
94+
"query_data"
95+
]
9196
}
9297
}
9398
}

google-cloud-gemini_data_analytics-v1beta/lib/google/cloud/gemini_data_analytics/v1beta/data_chat_service/client.rb

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,100 @@ def list_messages request, options = nil
805805
raise ::Google::Cloud::Error.from_error(e)
806806
end
807807

808+
##
809+
# Queries data from a natural language user query.
810+
#
811+
# @overload query_data(request, options = nil)
812+
# Pass arguments to `query_data` via a request object, either of type
813+
# {::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest} or an equivalent Hash.
814+
#
815+
# @param request [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest, ::Hash]
816+
# A request object representing the call parameters. Required. To specify no
817+
# parameters, or to keep all the default parameter values, pass an empty Hash.
818+
# @param options [::Gapic::CallOptions, ::Hash]
819+
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
820+
#
821+
# @overload query_data(parent: nil, prompt: nil, context: nil, generation_options: nil)
822+
# Pass arguments to `query_data` via keyword arguments. Note that at
823+
# least one keyword argument is required. To specify no parameters, or to keep all
824+
# the default parameter values, pass an empty Hash as a request object (see above).
825+
#
826+
# @param parent [::String]
827+
# Required. The parent resource to generate the query for.
828+
# Format: projects/\\{project}/locations/\\{location}
829+
# @param prompt [::String]
830+
# Required. The natural language query for which to generate query.
831+
# Example: "What are the top 5 best selling products this month?"
832+
# @param context [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataContext, ::Hash]
833+
# Required. The context for the data query, including the data sources to
834+
# use.
835+
# @param generation_options [::Google::Cloud::GeminiDataAnalytics::V1beta::GenerationOptions, ::Hash]
836+
# Optional. Options to control query generation and execution behavior.
837+
#
838+
# @yield [response, operation] Access the result along with the RPC operation
839+
# @yieldparam response [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse]
840+
# @yieldparam operation [::GRPC::ActiveCall::Operation]
841+
#
842+
# @return [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse]
843+
#
844+
# @raise [::Google::Cloud::Error] if the RPC is aborted.
845+
#
846+
# @example Basic example
847+
# require "google/cloud/gemini_data_analytics/v1beta"
848+
#
849+
# # Create a client object. The client can be reused for multiple calls.
850+
# client = Google::Cloud::GeminiDataAnalytics::V1beta::DataChatService::Client.new
851+
#
852+
# # Create a request. To set request fields, pass in keyword arguments.
853+
# request = Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest.new
854+
#
855+
# # Call the query_data method.
856+
# result = client.query_data request
857+
#
858+
# # The returned object is of type Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse.
859+
# p result
860+
#
861+
def query_data request, options = nil
862+
raise ::ArgumentError, "request must be provided" if request.nil?
863+
864+
request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest
865+
866+
# Converts hash and nil to an options object
867+
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
868+
869+
# Customize the options with defaults
870+
metadata = @config.rpcs.query_data.metadata.to_h
871+
872+
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
873+
metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
874+
lib_name: @config.lib_name, lib_version: @config.lib_version,
875+
gapic_version: ::Google::Cloud::GeminiDataAnalytics::V1beta::VERSION
876+
metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
877+
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
878+
879+
header_params = {}
880+
if request.parent
881+
header_params["parent"] = request.parent
882+
end
883+
884+
request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
885+
metadata[:"x-goog-request-params"] ||= request_params_header
886+
887+
options.apply_defaults timeout: @config.rpcs.query_data.timeout,
888+
metadata: metadata,
889+
retry_policy: @config.rpcs.query_data.retry_policy
890+
891+
options.apply_defaults timeout: @config.timeout,
892+
metadata: @config.metadata,
893+
retry_policy: @config.retry_policy
894+
895+
@data_chat_service_stub.call_rpc :query_data, request, options: options do |response, operation|
896+
yield response, operation if block_given?
897+
end
898+
rescue ::GRPC::BadStatus => e
899+
raise ::Google::Cloud::Error.from_error(e)
900+
end
901+
808902
##
809903
# Configuration class for the DataChatService API.
810904
#
@@ -1018,6 +1112,11 @@ class Rpcs
10181112
# @return [::Gapic::Config::Method]
10191113
#
10201114
attr_reader :list_messages
1115+
##
1116+
# RPC-specific configuration for `query_data`
1117+
# @return [::Gapic::Config::Method]
1118+
#
1119+
attr_reader :query_data
10211120

10221121
# @private
10231122
def initialize parent_rpcs = nil
@@ -1033,6 +1132,8 @@ def initialize parent_rpcs = nil
10331132
@list_conversations = ::Gapic::Config::Method.new list_conversations_config
10341133
list_messages_config = parent_rpcs.list_messages if parent_rpcs.respond_to? :list_messages
10351134
@list_messages = ::Gapic::Config::Method.new list_messages_config
1135+
query_data_config = parent_rpcs.query_data if parent_rpcs.respond_to? :query_data
1136+
@query_data = ::Gapic::Config::Method.new query_data_config
10361137

10371138
yield self if block_given?
10381139
end

google-cloud-gemini_data_analytics-v1beta/lib/google/cloud/gemini_data_analytics/v1beta/data_chat_service/rest/client.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,93 @@ def list_messages request, options = nil
759759
raise ::Google::Cloud::Error.from_error(e)
760760
end
761761

762+
##
763+
# Queries data from a natural language user query.
764+
#
765+
# @overload query_data(request, options = nil)
766+
# Pass arguments to `query_data` via a request object, either of type
767+
# {::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest} or an equivalent Hash.
768+
#
769+
# @param request [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest, ::Hash]
770+
# A request object representing the call parameters. Required. To specify no
771+
# parameters, or to keep all the default parameter values, pass an empty Hash.
772+
# @param options [::Gapic::CallOptions, ::Hash]
773+
# Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
774+
#
775+
# @overload query_data(parent: nil, prompt: nil, context: nil, generation_options: nil)
776+
# Pass arguments to `query_data` via keyword arguments. Note that at
777+
# least one keyword argument is required. To specify no parameters, or to keep all
778+
# the default parameter values, pass an empty Hash as a request object (see above).
779+
#
780+
# @param parent [::String]
781+
# Required. The parent resource to generate the query for.
782+
# Format: projects/\\{project}/locations/\\{location}
783+
# @param prompt [::String]
784+
# Required. The natural language query for which to generate query.
785+
# Example: "What are the top 5 best selling products this month?"
786+
# @param context [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataContext, ::Hash]
787+
# Required. The context for the data query, including the data sources to
788+
# use.
789+
# @param generation_options [::Google::Cloud::GeminiDataAnalytics::V1beta::GenerationOptions, ::Hash]
790+
# Optional. Options to control query generation and execution behavior.
791+
# @yield [result, operation] Access the result along with the TransportOperation object
792+
# @yieldparam result [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse]
793+
# @yieldparam operation [::Gapic::Rest::TransportOperation]
794+
#
795+
# @return [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse]
796+
#
797+
# @raise [::Google::Cloud::Error] if the REST call is aborted.
798+
#
799+
# @example Basic example
800+
# require "google/cloud/gemini_data_analytics/v1beta"
801+
#
802+
# # Create a client object. The client can be reused for multiple calls.
803+
# client = Google::Cloud::GeminiDataAnalytics::V1beta::DataChatService::Rest::Client.new
804+
#
805+
# # Create a request. To set request fields, pass in keyword arguments.
806+
# request = Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest.new
807+
#
808+
# # Call the query_data method.
809+
# result = client.query_data request
810+
#
811+
# # The returned object is of type Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse.
812+
# p result
813+
#
814+
def query_data request, options = nil
815+
raise ::ArgumentError, "request must be provided" if request.nil?
816+
817+
request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest
818+
819+
# Converts hash and nil to an options object
820+
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
821+
822+
# Customize the options with defaults
823+
call_metadata = @config.rpcs.query_data.metadata.to_h
824+
825+
# Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
826+
call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
827+
lib_name: @config.lib_name, lib_version: @config.lib_version,
828+
gapic_version: ::Google::Cloud::GeminiDataAnalytics::V1beta::VERSION,
829+
transports_version_send: [:rest]
830+
831+
call_metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
832+
call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
833+
834+
options.apply_defaults timeout: @config.rpcs.query_data.timeout,
835+
metadata: call_metadata,
836+
retry_policy: @config.rpcs.query_data.retry_policy
837+
838+
options.apply_defaults timeout: @config.timeout,
839+
metadata: @config.metadata,
840+
retry_policy: @config.retry_policy
841+
842+
@data_chat_service_stub.query_data request, options do |result, operation|
843+
yield result, operation if block_given?
844+
end
845+
rescue ::Gapic::Rest::Error => e
846+
raise ::Google::Cloud::Error.from_error(e)
847+
end
848+
762849
##
763850
# Configuration class for the DataChatService REST API.
764851
#
@@ -942,6 +1029,11 @@ class Rpcs
9421029
# @return [::Gapic::Config::Method]
9431030
#
9441031
attr_reader :list_messages
1032+
##
1033+
# RPC-specific configuration for `query_data`
1034+
# @return [::Gapic::Config::Method]
1035+
#
1036+
attr_reader :query_data
9451037

9461038
# @private
9471039
def initialize parent_rpcs = nil
@@ -957,6 +1049,8 @@ def initialize parent_rpcs = nil
9571049
@list_conversations = ::Gapic::Config::Method.new list_conversations_config
9581050
list_messages_config = parent_rpcs.list_messages if parent_rpcs.respond_to? :list_messages
9591051
@list_messages = ::Gapic::Config::Method.new list_messages_config
1052+
query_data_config = parent_rpcs.query_data if parent_rpcs.respond_to? :query_data
1053+
@query_data = ::Gapic::Config::Method.new query_data_config
9601054

9611055
yield self if block_given?
9621056
end

google-cloud-gemini_data_analytics-v1beta/lib/google/cloud/gemini_data_analytics/v1beta/data_chat_service/rest/service_stub.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,46 @@ def list_messages request_pb, options = nil
307307
end
308308
end
309309

310+
##
311+
# Baseline implementation for the query_data REST call
312+
#
313+
# @param request_pb [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest]
314+
# A request object representing the call parameters. Required.
315+
# @param options [::Gapic::CallOptions]
316+
# Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
317+
#
318+
# @yield [result, operation] Access the result along with the TransportOperation object
319+
# @yieldparam result [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse]
320+
# @yieldparam operation [::Gapic::Rest::TransportOperation]
321+
#
322+
# @return [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse]
323+
# A result object deserialized from the server's reply
324+
def query_data request_pb, options = nil
325+
raise ::ArgumentError, "request must be provided" if request_pb.nil?
326+
327+
verb, uri, query_string_params, body = ServiceStub.transcode_query_data_request request_pb
328+
query_string_params = if query_string_params.any?
329+
query_string_params.to_h { |p| p.split "=", 2 }
330+
else
331+
{}
332+
end
333+
334+
response = @client_stub.make_http_request(
335+
verb,
336+
uri: uri,
337+
body: body || "",
338+
params: query_string_params,
339+
method_name: "query_data",
340+
options: options
341+
)
342+
operation = ::Gapic::Rest::TransportOperation.new response
343+
result = ::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataResponse.decode_json response.body, ignore_unknown_fields: true
344+
catch :response do
345+
yield result, operation if block_given?
346+
result
347+
end
348+
end
349+
310350
##
311351
# @private
312352
#
@@ -434,6 +474,28 @@ def self.transcode_list_messages_request request_pb
434474
)
435475
transcoder.transcode request_pb
436476
end
477+
478+
##
479+
# @private
480+
#
481+
# GRPC transcoding helper method for the query_data REST call
482+
#
483+
# @param request_pb [::Google::Cloud::GeminiDataAnalytics::V1beta::QueryDataRequest]
484+
# A request object representing the call parameters. Required.
485+
# @return [Array(String, [String, nil], Hash{String => String})]
486+
# Uri, Body, Query string parameters
487+
def self.transcode_query_data_request request_pb
488+
transcoder = Gapic::Rest::GrpcTranscoder.new
489+
.with_bindings(
490+
uri_method: :post,
491+
uri_template: "/v1beta/{parent}:queryData",
492+
body: "*",
493+
matches: [
494+
["parent", %r{^projects/[^/]+/locations/[^/]+/?$}, false]
495+
]
496+
)
497+
transcoder.transcode request_pb
498+
end
437499
end
438500
end
439501
end

0 commit comments

Comments
 (0)