본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

방법: Java SDK에서 Dapr Conversation AI 작성 및 관리하기

원문 보기 위키 갱신

Dapr Java SDK를 사용해서 Conversation AI를 빠르게 시작하는 방법을 알아볼게요. 이 데모의 일부로, Conversation API를 사용해서 대규모 언어 모델(LLM)과 대화하는 방법을 살펴볼 거예요. API는 주어진 프롬프트에 대한 LLM의 응답을 반환해요. 제공된 conversation ai 예제를 사용하면 다음을 할 수 있어요.

  • Conversation AI 예제를 사용해서 프롬프트를 제공하기
  • 개인 식별 정보(PII, Personally identifiable information)를 필터링하기

이 예제는 셀프호스트 모드에서 dapr init의 기본 구성을 사용해요.

출처: Dapr 문서

본문

사전 요구 사항 (Prerequisites)

  • Dapr CLI 및 초기화된 환경.

  • Java JDK 11(이상):Oracle JDK, 또는

  • OpenJDK

  • Apache Maven, 버전 3.x.

  • Docker Desktop

환경 설정하기

Java SDK 리포지토리를 클론하고 그 안으로 이동할게요.

git clone https://github.com/dapr/java-sdk.git
cd java-sdk

Dapr Java SDK로 Conversation AI 예제를 실행하기 위한 요구 사항을 설치하려면 다음 명령을 실행해요.

mvn clean install -DskipTests

Java SDK 루트 디렉터리에서 examples 디렉터리로 이동할게요.

cd examples

Dapr 사이드카를 실행해요.

dapr run --app-id conversationapp --dapr-grpc-port 51439 --dapr-http-port 3500 --app-port 8080

이제 Dapr은 http://localhost:3500에서 HTTP 요청을, http://localhost:51439에서 gRPC 요청을 듣고 있어요.

개인 식별 정보(PII)가 있는 프롬프트를 Conversation AI API에 보내기

DemoConversationAI에는 DaprPreviewClient 아래의 converse 메서드를 사용해서 프롬프트를 보내는 단계들이 있어요.

public class DemoConversationAI {
/**
* The main method to start the client.
*
* @param args Input arguments (unused).
*/
public static void main(String[] args) {
try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
System.out.println("Sending the following input to LLM: Hello How are you? This is the my number 672-123-4567");

ConversationInput daprConversationInput = new ConversationInput("Hello How are you? "
+ "This is the my number 672-123-4567");

// Component name is the name provided in the metadata block of the conversation.yaml file.
Mono<ConversationResponse> responseMono = client.converse(new ConversationRequest("echo",
List.of(daprConversationInput))
.setContextId("contextId")
.setScrubPii(true).setTemperature(1.1d));
ConversationResponse response = responseMono.block();
System.out.printf("Conversation output: %s", response.getConversationOutputs().get(0).getResult());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

다음 명령으로 DemoConversationAI를 실행해요.

java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.conversation.DemoConversationAI

샘플 출력

== APP == Conversation output: Hello How are you? This is the my number <ISBN>

출력에서 볼 수 있듯이 API로 보낸 번호는 난독화되어 의 형태로 반환돼요. 위의 예제는 입력 메시지를 단순히 그대로 반환하는 테스트용 "echo" 컴포넌트를 사용해요. OpenAI나 Claude 같은 LLM과 통합하면, 에코된 입력 대신 의미 있는 응답을 받게 될 거예요.

다음 단계

  • Conversation AI에 대해 자세히 알아보기
  • Conversation AI API 레퍼런스

더 알아보기 (Learn more)