카테고리 없음

[Flutter] Google Dialogflow ES vs CX 챗봇 구현 비교 가이드

mark340 2024. 10. 23. 17:57

Flutter 앱에서 Dialogflow를 사용하여 챗봇을 구현하면서 겪었던 경험을 바탕으로, Dialogflow ES(Essentials)와 CX의 차이점 및 각각의 구현 방법에 대해 상세히 알아봤습니다..

목차

  1. Dialogflow ES와 CX의 주요 차이점
  2. Flutter에서의 구현 방법 비교
  3. 실제 구현 중 발생한 문제와 해결 방법
  4. 어떤 버전을 선택해야 할까?

1. Dialogflow ES와 CX의 주요 차이점

1.1 복잡성과 사용 목적

  • Dialogflow ES
    • 간단한 챗봇 구현에 적합
    • 기본적인 대화 흐름 관리
    • 작은 규모의 프로젝트에 이상적
  • Dialogflow CX
    • 복잡한 대화 시나리오 처리 가능
    • 시각적 흐름 관리
    • 대규모 엔터프라이즈 프로젝트에 적합

1.2 주요 기능 비교

기능 Dialogflow ES Dialogflow CX
대화 흐름 의도(Intent) 기반 상태 머신 모델
시각적 빌더 기본적인 인터페이스 고급 시각적 흐름 빌더
가격 상대적으로 저렴 더 높은 비용
확장성 제한적 높은 확장성
통합 용이성 간단함 더 복잡함

2. Flutter에서의 구현 방법 비교

2.1 Dialogflow ES 구현

ES 버전은 dialogFlowtter 패키지를 사용하여 간단히 구현할 수 있습니다:

dependencies:
  dialogFlowtter: ^0.9.1

기본 구현 코드:

void sendMessage(String text) async {
  DialogAuthCredentials credentials = await DialogAuthCredentials.fromFile(
    path: "assets/dialog_flow_auth.json"
  );

  DialogFlowtter dialogFlowtter = DialogFlowtter(
    credentials: credentials,
  );

  DialogResponse response = await dialogFlowtter.detectIntent(
    queryInput: QueryInput(text: TextInput(text: text)),
  );

  // 응답 처리
  if (response.message != null) {
    // UI 업데이트
  }
}

2.2 Dialogflow CX 구현

CX 버전은 Google의 공식 API를 직접 사용해야 합니다:

dependencies:
  googleapis_auth: ^1.1.0
  googleapis: ^11.0.0

기본 구현 코드:

class ChatbotClient {
  final String projectId;
  final String agentId;
  final String location;

  Future<String> sendMessage(String sessionId, String message) async {
    final dialogflow = await AuthClient.getDialogflowApi();
    final sessionPath = 'projects/$projectId/locations/$location/agents/$agentId/sessions/$sessionId';

    final queryInput = GoogleCloudDialogflowCxV3QueryInput(
      languageCode: 'ko',
      text: GoogleCloudDialogflowCxV3TextInput(text: message),
    );

    final response = await dialogflow.projects.locations.agents.sessions.detectIntent(
      GoogleCloudDialogflowCxV3DetectIntentRequest(queryInput: queryInput),
      sessionPath,
    );

    return response.queryResult?.responseMessages?.first.text?.text?.first ?? '응답 없음';
  }
}

3. 실제 구현 중 발생한 문제와 해결 방법

3.1 ES 구현 시 발생한 문제

문제:

Exception: NOT_FOUND: com.google.apps.framework.request.NotFoundException: 
No DesignTimeAgent found for project 'project-id'

해결 방법:

  • Dialogflow ES 프로젝트를 새로 생성
  • 올바른 서비스 계정 키 설정
  • API 활성화 확인

3.2 CX 구현 시 발생한 문제

문제:

DetailedApiRequestError(status: 400, message: Please refer to 
https://cloud.google.com/dialogflow/cx/docs/concept/region#avail...)

해결 방법:

  1. 지역별 올바른 엔드포인트 설정
  2. final Endpoint = 'https://asia-northeast1-dialogflow.googleapis.com/';
  3. sessionPath 형식 수정
  4. final sessionPath = 'projects/$projectId/locations/$location/agents/$agentId/sessions/$sessionId';

4. 어떤 버전을 선택해야 할까?

ES를 선택해야 하는 경우:

  • 간단한 대화 시나리오
  • 빠른 프로토타이핑이 필요할 때
  • 비용 효율성이 중요할 때
  • Flutter 패키지 지원이 필요할 때

CX를 선택해야 하는 경우:

  • 복잡한 대화 흐름 관리가 필요할 때
  • 대규모 프로젝트
  • 시각적 흐름 관리가 중요할 때
  • 높은 확장성이 필요할 때

결론

제 경험을 바탕으로, 작은 규모의 챗봇 프로젝트라면 ES를, 복잡한 대화 흐름이 필요한 프로젝트라면 CX를 추천드립니다. ES는 구현이 간단하고 dialogFlowtter 패키지 덕분에 Flutter 통합이 쉽습니다. 반면 CX는 구현이 더 복잡하지만, 강력한 기능과 확장성을 제공합니다.

특히 주의할 점은 CX를 사용할 때 지역 설정과 엔드포인트 구성에 신경 써야 한다는 것입니다. 처음에는 ES로 시작하고, 필요에 따라 CX로 마이그레이션하는 것도 좋은 전략이 될 수 있습니다.

참고 자료