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: [DiscoveryEngine] support conversational / multi-turn search #6501

Merged
merged 2 commits into from
Jul 27, 2023
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
11 changes: 7 additions & 4 deletions DiscoveryEngine/metadata/V1Beta/CompletionService.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
79 changes: 79 additions & 0 deletions DiscoveryEngine/metadata/V1Beta/ConversationalSearchService.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified DiscoveryEngine/metadata/V1Beta/SearchService.php
Binary file not shown.
Binary file modified DiscoveryEngine/metadata/V1Beta/UserEvent.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START discoveryengine_v1beta_generated_ConversationalSearchService_ConverseConversation_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\DiscoveryEngine\V1beta\Client\ConversationalSearchServiceClient;
use Google\Cloud\DiscoveryEngine\V1beta\ConverseConversationRequest;
use Google\Cloud\DiscoveryEngine\V1beta\ConverseConversationResponse;
use Google\Cloud\DiscoveryEngine\V1beta\TextInput;

/**
* Converses a conversation.
*
* @param string $formattedName The resource name of the Conversation to get. Format:
* `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/{conversation_id}`.
* Use
* `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/-`
* to activate auto session mode, which automatically creates a new
* conversation inside a ConverseConversation session. Please see
* {@see ConversationalSearchServiceClient::conversationName()} for help formatting this field.
*/
function converse_conversation_sample(string $formattedName): void
{
// Create a client.
$conversationalSearchServiceClient = new ConversationalSearchServiceClient();

// Prepare the request message.
$query = new TextInput();
$request = (new ConverseConversationRequest())
->setName($formattedName)
->setQuery($query);

// Call the API and handle any network failures.
try {
/** @var ConverseConversationResponse $response */
$response = $conversationalSearchServiceClient->converseConversation($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = ConversationalSearchServiceClient::conversationName(
'[PROJECT]',
'[LOCATION]',
'[DATA_STORE]',
'[CONVERSATION]'
);

converse_conversation_sample($formattedName);
}
// [END discoveryengine_v1beta_generated_ConversationalSearchService_ConverseConversation_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START discoveryengine_v1beta_generated_ConversationalSearchService_CreateConversation_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\DiscoveryEngine\V1beta\Client\ConversationalSearchServiceClient;
use Google\Cloud\DiscoveryEngine\V1beta\Conversation;
use Google\Cloud\DiscoveryEngine\V1beta\CreateConversationRequest;

/**
* Creates a Conversation.
*
* If the [Conversation][google.cloud.discoveryengine.v1beta.Conversation] to
* create already exists, an ALREADY_EXISTS error is returned.
*
* @param string $formattedParent Full resource name of parent data store. Format:
* `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}`
* Please see {@see ConversationalSearchServiceClient::dataStoreName()} for help formatting this field.
*/
function create_conversation_sample(string $formattedParent): void
{
// Create a client.
$conversationalSearchServiceClient = new ConversationalSearchServiceClient();

// Prepare the request message.
$conversation = new Conversation();
$request = (new CreateConversationRequest())
->setParent($formattedParent)
->setConversation($conversation);

// Call the API and handle any network failures.
try {
/** @var Conversation $response */
$response = $conversationalSearchServiceClient->createConversation($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = ConversationalSearchServiceClient::dataStoreName(
'[PROJECT]',
'[LOCATION]',
'[DATA_STORE]'
);

create_conversation_sample($formattedParent);
}
// [END discoveryengine_v1beta_generated_ConversationalSearchService_CreateConversation_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START discoveryengine_v1beta_generated_ConversationalSearchService_DeleteConversation_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\DiscoveryEngine\V1beta\Client\ConversationalSearchServiceClient;
use Google\Cloud\DiscoveryEngine\V1beta\DeleteConversationRequest;

/**
* Deletes a Conversation.
*
* If the [Conversation][google.cloud.discoveryengine.v1beta.Conversation] to
* delete does not exist, a NOT_FOUND error is returned.
*
* @param string $formattedName The resource name of the Conversation to delete. Format:
* `projects/{project_number}/locations/{location_id}/collections/{collection}/dataStores/{data_store_id}/conversations/{conversation_id}`
* Please see {@see ConversationalSearchServiceClient::conversationName()} for help formatting this field.
*/
function delete_conversation_sample(string $formattedName): void
{
// Create a client.
$conversationalSearchServiceClient = new ConversationalSearchServiceClient();

// Prepare the request message.
$request = (new DeleteConversationRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
$conversationalSearchServiceClient->deleteConversation($request);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = ConversationalSearchServiceClient::conversationName(
'[PROJECT]',
'[LOCATION]',
'[DATA_STORE]',
'[CONVERSATION]'
);

delete_conversation_sample($formattedName);
}
// [END discoveryengine_v1beta_generated_ConversationalSearchService_DeleteConversation_sync]
Loading