[Spring AI] ChatClient의 return value들
|
AI Summary
- Spring AI의 ChatClient에서
call()과 stream() 메서드의 반환값 타입을 정리했다. call() 메서드는 문자열 응답, 메타데이터를 포함한 ChatResponse, Java 엔티티 타입 등을 반환할 수 있다.entity() 메서드는 제네릭 타입, 컬렉션, 또는 StructuredOutputConverter를 사용해 특정 타입으로 변환된 결과를 반환한다.stream() 메서드는 AI가 생성하는 문자열이나 ChatResponse 객체를 Flux 형태로 반환한다.- 각 반환값은 응답 내용과 메타데이터를 다양하게 활용할 수 있도록 설계되어 있다.
Updated: 2025-11-22 15:37 UTCIntroduction
- ChatClient 에서
call() 메서드와 stream() 메서드 각각의 response 타입에 대해 정리해보자.
call() 의 return value 들
String content()ChatResponse chatResponse()- 여러 생성 결과와 응답에 대한 메타데이터 (예: 응답 생성에 사용된 토큰 수) 를 포함하는 ChatResponse 객체를 반환
entity()- Java 타입 반환
entity(ParameterizedTypeReference<T> type)- 엔티티 타입의
Collection 을 반환할 때 사용
entity(Class<T> type)entity(StructuredOutputConverter<T> structuredOutputConverter)String 을 엔티티 타입으로 변환하기 위한 StructuredOutputConverter 인스턴스를 지정할 때 사용
stream() 의 return value 들
Flux<String> content()- AI 모델이 생성하는 문자열의
Flux 를 반환
Flux<ChatResponse> chatResponse()- 응답에 대한 추가 메타데이터를 포함하는
ChatResponse 객체의 Flux 를 반환
References