use of com.google.cloud.dialogflow.v2.KnowledgeBaseName in project java-dialogflow by googleapis.
the class CreateKnowledgeBaseTest method tearDown.
@After
public void tearDown() throws IOException {
if (knowledgeBaseName == null) {
return;
}
// Delete the created knowledge base
try (KnowledgeBasesClient client = KnowledgeBasesClient.create()) {
DeleteKnowledgeBaseRequest request = DeleteKnowledgeBaseRequest.newBuilder().setName(knowledgeBaseName).setForce(true).build();
client.deleteKnowledgeBase(request);
}
System.setOut(originalOutputStream);
}
use of com.google.cloud.dialogflow.v2.KnowledgeBaseName in project java-dialogflow by googleapis.
the class DetectIntentKnowledgeTest method testDetectIntentKnowledge.
@Test
public void testDetectIntentKnowledge() throws Exception {
KnowledgeBaseName knowledgeBaseName = KnowledgeBaseName.newBuilder().setProject(PROJECT_ID).setKnowledgeBase(TEST_KNOWLEDGE_BASE_ID).build();
DocumentName documentName = DocumentName.newBuilder().setProject(PROJECT_ID).setKnowledgeBase(TEST_KNOWLEDGE_BASE_ID).setDocument(TEST_DOCUMENT_ID).build();
Map<String, KnowledgeAnswers> allAnswers = DetectIntentKnowledge.detectIntentKnowledge(PROJECT_ID, knowledgeBaseName.toString(), SESSION_ID, LANGUAGE_CODE, TEXTS);
assertEquals(TEXTS.size(), allAnswers.size());
int answersFound = 0;
for (String text : TEXTS) {
KnowledgeAnswers knowledgeAnswers = allAnswers.get(text);
if (knowledgeAnswers.getAnswersCount() > 0) {
Answer answer = knowledgeAnswers.getAnswers(0);
if (text.equals(answer.getFaqQuestion()) && documentName.toString().equals(answer.getSource())) {
answersFound++;
}
}
}
// To make the test less flaky, check that half of the texts got a result.
assertThat(answersFound).isGreaterThan(TEXTS.size() / 2);
}
use of com.google.cloud.dialogflow.v2.KnowledgeBaseName in project java-dialogflow by googleapis.
the class ConversationProfileManagement method createConversationProfileArticleSuggestion.
// Create a conversation profile with given values about Article Suggestion.
public static void createConversationProfileArticleSuggestion(String projectId, String displayName, String location, Optional<String> articleSuggestionKnowledgeBaseId) throws ApiException, IOException {
try (ConversationProfilesClient conversationProfilesClient = ConversationProfilesClient.create()) {
// Create a builder for agent assistance configuration
SuggestionConfig.Builder suggestionConfigBuilder = SuggestionConfig.newBuilder();
// Add knowledge base for Article Suggestion feature
if (articleSuggestionKnowledgeBaseId.isPresent()) {
KnowledgeBaseName articleSuggestionKbName = KnowledgeBaseName.of(projectId, articleSuggestionKnowledgeBaseId.get());
// Build configuration for Article Suggestion feature
SuggestionFeatureConfig articleSuggestionFeatureConfig = SuggestionFeatureConfig.newBuilder().setSuggestionFeature(SuggestionFeature.newBuilder().setType(Type.ARTICLE_SUGGESTION).build()).setSuggestionTriggerSettings(buildSuggestionTriggerSettings()).setQueryConfig(buildSuggestionQueryConfig(articleSuggestionKbName)).build();
// Add Article Suggestion feature to agent assistance configuration
suggestionConfigBuilder.addFeatureConfigs(articleSuggestionFeatureConfig);
}
LocationName locationName = LocationName.of(projectId, location);
// Set a conversation profile with target configurations
ConversationProfile targetConversationProfile = ConversationProfile.newBuilder().setDisplayName(displayName).setLanguageCode("en-US").setHumanAgentAssistantConfig(HumanAgentAssistantConfig.newBuilder().setHumanAgentSuggestionConfig(suggestionConfigBuilder.build())).build();
// Create a conversation profile
ConversationProfile createdConversationProfile = conversationProfilesClient.createConversationProfile(CreateConversationProfileRequest.newBuilder().setParent(locationName.toString()).setConversationProfile(targetConversationProfile).build());
System.out.println("====================");
System.out.println("Conversation Profile created:\n");
System.out.format("Display name: %s\n", createdConversationProfile.getDisplayName());
System.out.format("Name: %s\n", createdConversationProfile.getName());
}
}
use of com.google.cloud.dialogflow.v2.KnowledgeBaseName in project java-dialogflow by googleapis.
the class DocumentsClientTest method listDocumentsTest.
@Test
public void listDocumentsTest() throws Exception {
Document responsesElement = Document.newBuilder().build();
ListDocumentsResponse expectedResponse = ListDocumentsResponse.newBuilder().setNextPageToken("").addAllDocuments(Arrays.asList(responsesElement)).build();
mockDocuments.addResponse(expectedResponse);
KnowledgeBaseName parent = KnowledgeBaseName.ofProjectKnowledgeBaseName("[PROJECT]", "[KNOWLEDGE_BASE]");
ListDocumentsPagedResponse pagedListResponse = client.listDocuments(parent);
List<Document> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDocumentsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDocuments.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDocumentsRequest actualRequest = ((ListDocumentsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations