스마트 답장

스마트 답장은 상담사와 최종 사용자 간의 대화를 따라가며 상담사에게 추천 응답을 표시합니다. 추천 응답은 자체 대화 스크립트 데이터를 사용하여 학습된 커스텀 모델을 통해 계산됩니다.

이 문서에서는 API를 사용하여 스마트 답장을 구현하고 런타임 중에 이 기능으로 추천을 받는 과정을 안내합니다. 설계 중에 Agent Assist 콘솔을 사용해 데이터를 업로드하고 모델을 학습시키며 스마트 답장 결과를 테스트해야 합니다. 런타임 중에 스마트 답장 추천을 보려면 API를 직접 호출해야 합니다. Agent Assist 콘솔을 사용하여 모델을 학습시키고 성능을 테스트하는 방법에 대한 자세한 내용은 스마트 답장 튜토리얼을 참조하세요.

시작하기 전에

이 가이드를 시작하기 전에 다음을 수행해야 합니다.

  1. 자체 스크립트 데이터를 사용하여 대화 데이터 세트를 만듭니다.
  2. 대화 데이터 세트를 사용하여 스마트 답장 모델을 학습시킵니다.
  3. 대화 프로필을 만듭니다.
  4. Agent Assist 시뮬레이터를 사용하여 스마트 답장 결과를 테스트합니다.

개인 식별 정보 및 아동 데이터의 처리

이 API로 데이터를 전송하면 API에서 모든 개인 식별 정보(PII)를 수정하려고 시도합니다. 모델에 PII가 포함되지 않도록 하려면 데이터를 API로 보내기 전에 삭제해야 합니다.

아동에게서 수집한 정보가 데이터에 포함된 경우 아동 데이터를 API로 보내기 전에 삭제해야 합니다.

런타임 중 대화 처리

최종 사용자와 상담사의 대화가 시작될 때 대화를 만듭니다. 추천을 보려면 최종 사용자 참여자와 상담사 참여자를 모두 만들어 대화에 추가해야 합니다. 다음 섹션에서는 이러한 프로세스를 안내합니다.

대화 만들기

대화를 만들려면 Conversation 리소스에서 create 메서드를 호출합니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_PROFILE_ID: 대화 프로필을 만들 때 받은 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations

JSON 요청 본문:

{
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
}

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "IN_PROGRESS",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z"
}

conversations 다음의 경로 세그먼트에 새 대화 ID가 있습니다.

Python

def create_conversation(project_id, conversation_profile_id):
    """Creates a conversation with given values

    Args:
        project_id:  The GCP project linked with the conversation.
        conversation_profile_id: The conversation profile id used to create
        conversation."""

    client = dialogflow.ConversationsClient()
    conversation_profile_client = dialogflow.ConversationProfilesClient()
    project_path = client.common_project_path(project_id)
    conversation_profile_path = conversation_profile_client.conversation_profile_path(
        project_id, conversation_profile_id
    )
    conversation = {"conversation_profile": conversation_profile_path}
    response = client.create_conversation(
        parent=project_path, conversation=conversation
    )

    print("Life Cycle State: {}".format(response.lifecycle_state))
    print("Conversation Profile Name: {}".format(response.conversation_profile))
    print("Name: {}".format(response.name))
    return response

최종 사용자 참여자 만들기

추천을 보려면 최종 사용자 및 상담사 참여자를 모두 대화에 추가해야 합니다. 최종 사용자 참여자를 만들려면 Participant 리소스에서 create 메서드를 호출합니다. 대화 ID를 제공하고 role 필드에 END_USER를 입력합니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_ID: 대화 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants

JSON 요청 본문:

{
  "role": "END_USER",
}

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "END_USER"
}

participants 다음의 경로 세그먼트에 새로운 최종 사용자 참여자 ID가 있습니다.

Python

def create_participant(project_id, conversation_id, role):
    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print("Role: {}".format(response.role))
        print("Name: {}".format(response.name))

        return response

상담사 참여자 만들기

상담사 참여자를 만들려면 Participant 리소스에서 create 메서드를 호출합니다. 대화 ID를 제공하고 role 필드에 HUMAN_AGENT를 입력합니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_ID: 대화 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants

JSON 요청 본문:

{
  "role": "HUMAN_AGENT",
}

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "HUMAN_AGENT"
}

participants 다음의 경로 세그먼트에 새로운 상담사 참여자 ID가 있습니다.

Python

def create_participant(project_id, conversation_id, role):
    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print("Role: {}".format(response.role))
        print("Name: {}".format(response.name))

        return response

상담사의 메시지 추가 및 분석

참여자가 대화에 메시지를 입력할 때마다 처리를 위해 해당 메시지를 API에 전송해야 합니다. Agent Assist에서는 상담사 및 최종 사용자 메시지 분석을 기반으로 추천을 제공합니다. 대화의 상담사 메시지를 추가하고 분석하려면 Participant 리소스에서 analyzeContent 메서드를 호출합니다. 대화 ID 및 상담사 참여자 ID를 제공합니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_ID: 대화 ID
  • PARTICIPANT_ID: 상담사 참여자 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

JSON 요청 본문:

{
  "textInput": {
    "text": "How may I help you?",
    "languageCode": "en-US"
  }
}

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "How may I help you?",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "HUMAN_AGENT",
    "createTime": "2020-02-13T00:01:30.683Z"
  },
  "humanAgentSuggestionResults": [
    {
      "suggestSmartRepliesResponse": {
      "smartReplyAnswers": [
          {
            "reply": "I am here to help you.",
            "confidence": 0.5,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_1"
          },
          {
            "reply": "Sorry for the wait, we have a high volume of chats right now.",
            "confidence": 0.3,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_2"
          },
          {
            "reply": "Thank you for contacting us!",
            "confidence": 0.1,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_3"
          }
        ]
      }
    }
  ]
}

Python

def analyze_content_text(project_id, conversation_id, participant_id, text):
    """Analyze text message content from a participant.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant_id: Id of the participant.
        text: the text message that participant typed."""

    client = dialogflow.ParticipantsClient()
    participant_path = client.participant_path(
        project_id, conversation_id, participant_id
    )
    text_input = {"text": text, "language_code": "en-US"}
    response = client.analyze_content(
        participant=participant_path, text_input=text_input
    )
    print("AnalyzeContent Response:")
    print("Reply Text: {}".format(response.reply_text))

    for suggestion_result in response.human_agent_suggestion_results:
        if suggestion_result.error is not None:
            print("Error: {}".format(suggestion_result.error.message))
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print("Article Suggestion Answer: {}".format(answer.title))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print("Faq Answer: {}".format(answer.answer))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print("Smart Reply: {}".format(answer.reply))
                print("Answer Record: {}".format(answer.answer_record))

    for suggestion_result in response.end_user_suggestion_results:
        if suggestion_result.error:
            print("Error: {}".format(suggestion_result.error.message))
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print("Article Suggestion Answer: {}".format(answer.title))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print("Faq Answer: {}".format(answer.answer))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print("Smart Reply: {}".format(answer.reply))
                print("Answer Record: {}".format(answer.answer_record))

    return response

최종 사용자의 메시지 추가 및 분석

대화의 최종 사용자 메시지를 추가하고 분석하려면 Participant 리소스에서 analyzeContent 메서드를 호출합니다. 대화 ID 및 최종 사용자 참여자 ID를 제공합니다.

응답에 메시지 ID가 포함됩니다. 대화 프로필에서 SuggestionFeatureConfig.enable_inline_suggestion을 true로 설정하면 응답에 스마트 답장 추천 목록이 포함됩니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_ID: 대화 ID
  • PARTICIPANT_ID: 최종 사용자 참여자 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

JSON 요청 본문:

{
  "textInput": {
    "text": "I want to reserve a room.",
    "languageCode": "en-US"
  }
}

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "I want to reserve a room.",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "END_USER",
    "createTime": "2020-02-13T00:07:35.925Z"
  },
  "humanAgentSuggestionResults": [
    {
      "suggestSmartRepliesResponse": {
      "smartReplyAnswers": [
          {
            "reply": "Where would you like to reserve a room?",
            "confidence": 0.5,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_1"
          },
          {
            "reply": "What type of rooms would you like to reserve?",
            "confidence": 0.3,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_2"
          },
          {
            "reply": "How long do you want to stay?",
            "confidence": 0.1,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_3"
          }
        ]
      }
    }
  ]
}

Python

def analyze_content_text(project_id, conversation_id, participant_id, text):
    """Analyze text message content from a participant.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant_id: Id of the participant.
        text: the text message that participant typed."""

    client = dialogflow.ParticipantsClient()
    participant_path = client.participant_path(
        project_id, conversation_id, participant_id
    )
    text_input = {"text": text, "language_code": "en-US"}
    response = client.analyze_content(
        participant=participant_path, text_input=text_input
    )
    print("AnalyzeContent Response:")
    print("Reply Text: {}".format(response.reply_text))

    for suggestion_result in response.human_agent_suggestion_results:
        if suggestion_result.error is not None:
            print("Error: {}".format(suggestion_result.error.message))
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print("Article Suggestion Answer: {}".format(answer.title))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print("Faq Answer: {}".format(answer.answer))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print("Smart Reply: {}".format(answer.reply))
                print("Answer Record: {}".format(answer.answer_record))

    for suggestion_result in response.end_user_suggestion_results:
        if suggestion_result.error:
            print("Error: {}".format(suggestion_result.error.message))
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print("Article Suggestion Answer: {}".format(answer.title))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print("Faq Answer: {}".format(answer.answer))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print("Smart Reply: {}".format(answer.reply))
                print("Answer Record: {}".format(answer.answer_record))

    return response

추천 받기(선택사항)

언제든지 추천을 받을 수 있습니다. 원하는 경우 메시지의 메시지 ID를 지정하여 메시지에 따른 추천을 받을 수 있습니다. 이 필드를 설정하지 않으면 기본적으로 참여자의 최신 메시지를 기반으로 추천이 제공됩니다.

추천을 받으려면 Suggestion 리소스에서 suggestSmartReplies 메서드를 호출합니다. 대화 ID, 상담사 참여자 ID, 참여자의 메시지 ID(선택사항)를 입력합니다.

응답에 스마트 답장 추천이 포함됩니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_ID: 대화 ID
  • PARTICIPANT_ID: 최종 사용자 참여자 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

JSON 요청 본문:

{
  "textInput": {
    "text": "I want to reserve a room.",
    "languageCode": "en-US"
  }
}

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "I want to reserve a room.",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "END_USER",
    "createTime": "2020-02-13T00:07:35.925Z"
  },
  "humanAgentSuggestionResults": [
    {
      "suggestSmartRepliesResponse": {
      "smartReplyAnswers": [
          {
            "reply": "Where would you like to reserve a room?",
            "confidence": 0.5,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_1"
          },
          {
            "reply": "What type of rooms would you like to reserve?",
            "confidence": 0.3,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_2"
          },
          {
            "reply": "How long do you want to stay?",
            "confidence": 0.1,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_3"
          }
        ]
      }
    }
  ]
}

Python

def analyze_content_text(project_id, conversation_id, participant_id, text):
    """Analyze text message content from a participant.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant_id: Id of the participant.
        text: the text message that participant typed."""

    client = dialogflow.ParticipantsClient()
    participant_path = client.participant_path(
        project_id, conversation_id, participant_id
    )
    text_input = {"text": text, "language_code": "en-US"}
    response = client.analyze_content(
        participant=participant_path, text_input=text_input
    )
    print("AnalyzeContent Response:")
    print("Reply Text: {}".format(response.reply_text))

    for suggestion_result in response.human_agent_suggestion_results:
        if suggestion_result.error is not None:
            print("Error: {}".format(suggestion_result.error.message))
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print("Article Suggestion Answer: {}".format(answer.title))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print("Faq Answer: {}".format(answer.answer))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print("Smart Reply: {}".format(answer.reply))
                print("Answer Record: {}".format(answer.answer_record))

    for suggestion_result in response.end_user_suggestion_results:
        if suggestion_result.error:
            print("Error: {}".format(suggestion_result.error.message))
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print("Article Suggestion Answer: {}".format(answer.title))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print("Faq Answer: {}".format(answer.answer))
                print("Answer Record: {}".format(answer.answer_record))
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print("Smart Reply: {}".format(answer.reply))
                print("Answer Record: {}".format(answer.answer_record))

    return response

대화 완료

대화를 완료하려면 conversations 리소스에서 complete 메서드를 호출합니다. 대화 ID를 제공합니다.

REST 및 명령줄

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: GCP 프로젝트 ID
  • CONVERSATION_ID: 대화를 만들 때 받은 ID

HTTP 메서드 및 URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID:complete

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "COMPLETED",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z",
  "endTime": "2018-11-06T03:50:26.930Z"
}

Python

def complete_conversation(project_id, conversation_id):
    """Completes the specified conversation. Finished conversations are purged from the database after 30 days.

    Args:
        project_id: The GCP project linked with the conversation.
        conversation_id: Id of the conversation."""

    client = dialogflow.ConversationsClient()
    conversation_path = client.conversation_path(project_id, conversation_id)
    conversation = client.complete_conversation(name=conversation_path)
    print("Completed Conversation.")
    print("Life Cycle State: {}".format(conversation.lifecycle_state))
    print("Conversation Profile Name: {}".format(conversation.conversation_profile))
    print("Name: {}".format(conversation.name))
    return conversation