-
챗봇크루메이트 코드 리뷰!! 2020. 9. 18. 05:16
챗봇에 내용을 입력
@RequestMapping(value="chatbot") public ModelAndView detectIntentTexts(String projectId, String sessionId, String languageCode, ModelAndView andView, @RequestParam(value="chatbotInput", required = false) String sendMessage, HttpServletRequest request )throws IOException, ApiException { String result=null; List<String> texts = new ArrayList<>(); texts.add(sendMessage); projectId = "testagent-crvsfc"; sessionId = request.getSession().getId(); // sessionId="testAgent"; languageCode="ko"; Map<String, QueryResult> queryResults = Maps.newHashMap(); // Instantiates a client try (SessionsClient sessionsClient = SessionsClient.create()) { // Set the session name using the sessionId (UUID) and projectID (my-project-id) SessionName session = SessionName.of(projectId, sessionId); System.out.println("Session Path: " + session.toString()); // Detect intents for each text input for (String text : texts) { // Set the text (hello) and language code (en-US) for the query TextInput.Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(languageCode); // Build the query with the TextInput QueryInput queryInput = QueryInput.newBuilder().setText(textInput).build(); // Performs the detect intent request DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput); // Display the query result QueryResult queryResult = response.getQueryResult(); System.out.println("===================="); System.out.format("Query Text: '%s'\n", queryResult.getQueryText()); System.out.format( "Detected Intent: %s (confidence: %f)\n", queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence()); System.out.format("Fulfillment Text: '%s'\n", queryResult.getFulfillmentText()); result = queryResult.getFulfillmentText(); queryResults.put(text, queryResult); } } System.out.println("queryREsults : " + queryResults); andView.addObject("answer", result); andView.setViewName("jsonConvertView"); return andView; } @RequestMapping("clientTest") static void authImplicit() { // If you don't specify credentials when constructing the client, the client library will // look for credentials via the environment variable GOOGLE_APPLICATION_CREDENTIALS. Storage storage = StorageOptions.getDefaultInstance().getService(); System.out.println("Buckets:"); Page<Bucket> buckets = storage.list(); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.toString()); } }
'크루메이트 코드 리뷰!!' 카테고리의 다른 글
채팅 (0) 2020.09.18 식단 관리 - 다이어트 일기장 (0) 2020.09.18 식단 관리 - 열량 차트 (0) 2020.09.18 식단 관리 - 나의 식단표 (0) 2020.09.18 식단 관리 - 회원 정보 조회, 등록, 수정, 삭제 (0) 2020.09.18