함수 호출과 함께하는 스트리밍
함수 호출 기능을 갖춘 LLM이 얼마나 다양한 활용 사례를 열어주는지 이미 살펴보셨을 텐데요, 함수 호출에는 별도의 이벤트 유형이 존재합니다. 이를 활용하면 모델이 도구를 호출하려 할 때 사용자에게 실시간 피드백을 제공하거나, 도구 사용 현황을 추적하기 위한 로깅에 활용할 수 있습니다.
앞서 정의한 convert_timezone() 함수와 Responses API용 함수 정의가 포함된 tools 목록은 이미 준비되어 있습니다.
이 연습은 강의의 일부입니다
OpenAI Responses API 활용하기
연습 안내
client.responses.create()를 호출해 스트리밍 컨텍스트 관리자를 완성하세요. 이때 모델로"gpt-5.4-mini",prompt,tools목록을 전달합니다.- 루프 내에서
"function_call_arguments.delta"이벤트인지 확인하세요. "function_call_arguments.done"이벤트를 확인하는 조건을 추가하세요.- 이벤트 유형이
"response.completed"인지 확인하는 마지막 조건을 추가하고, 완료 메시지를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
prompt = "What time is 2:30pm on January 20th in New York in Tokyo time?"
# Open the streaming connection and enable tool-calling
with ____ as stream:
for event in stream:
# Filter for function call arguments delta events
if ____:
print(f"\nTool args streaming: {event.delta}")
# Filter for function call arguments complete events
elif ____:
print("Tool call args complete.")
# Filter for response completed events
elif ____:
print("\n--- Completed ---")