始める無料で始める

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'])
コードを編集して実行