読み方のヒント

矢印ボタン(または ← → キー)でページを移動できます。

第3節 Python SDKで最初の要求を送る

3.2 最初の要求を読む

midori/first_call.py の中心は、次の部分です。

def draft_reply(client: OpenAI, inquiry: str) -> str:
    response = client.responses.create(
        model=model_main(),
        instructions="あなたは茶園のネットショップの担当です。丁寧な敬語で、5文以内の返信の下書きを書きます。",
        input=inquiry,
        max_output_tokens=800,
    )
    return response.output_text
引数意味
model使うモデルの名前。環境変数 MIDORI_MODEL_MAIN から読む
instructionsモデルに守らせる前提(役割、書き方)
input頼む文。ここでは問い合わせの本文
max_output_tokens返させる長さの上限(トークン)

response.output_text には、モデルが書いた文がまとめて入っています。

python -m midori.first_call
解答

instructions の「5文以内」を「3文以内」に変え、max_output_tokens=800 を max_output_tokens=500 に変えます。

11 / 20