JSON 재고 목록 만들기
LLM으로 구조화된 출력을 생성할 수 있으면, 최소한의 후처리로 시스템 간 정보를 안정적으로 교환할 수 있습니다.
이 연습에서는 자연어로 작성된 재고 목록을 JSON 형식으로 변환하면서 프롬프트 작성 능력을 점검해 보세요. 사용할 모델과 시스템 프롬프트는 이미 준비되어 있습니다.
이 연습은 강의의 일부입니다
Llama 3 다루기
연습 안내
- JSON 형식의 응답을 생성하도록
response_format딕셔너리를 완성하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
output = llm.create_chat_completion(
messages=[
{"role": "system", "content": "You convert inventory lists from text to JSON, extracting item counts and names from the text as keys and values in the form: item: count; for example, 'banana': 32.",},
{"role": "user", "content": "Fifteen apples, thirty-three oranges, and five thousand fifty-two potatoes."},
],
# Specify output format to JSON
response_format={
"type": ____,
}
)
print(output['choices'][0]['message']['content'])