아이템을 활용한 사용자 지정 처리
디버깅을 위해 상세한 로깅이 필요한 챗봇을 만들고 있어요. 이 챗봇은 reasoning 기능이 활성화된 모델을 사용하며, reasoning 요약과 assistant 응답을 명확히 구분하는 사용자 지정 출력 메시지를 만들고자 합니다. 이전 API 호출에서 받은 response 객체에는 여러 개의 출력 아이템이 들어 있습니다.
이 연습은 강의의 일부입니다
OpenAI Responses API 활용하기
연습 안내
response.output의 각 아이템을 순회하세요.- 아이템 유형이
'reasoning'이면, 존재할 경우 reasoning 요약을 보여주는 형식의 메시지를 출력하세요. - 아이템 유형이
'message'이면, assistant의 텍스트 출력을 포함한 형식의 메시지를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Loop through each item in the response output
for item in response.____:
# Check if the item is a reasoning item
if item.____ == '____':
if item.____:
print(f"Reasoning: {item.____[0]}")
else:
print("No reasoning summary found.")
# Check if the item is a message item
if item.____ == 'message':
print(f"Assistant: {item.____[0].text}")