答えを JSON で受け取る
const schema = {
type: "object",
properties: {
summary: { type: "string" },
needsUmbrella: { type: "boolean" },
},
required: ["summary", "needsUmbrella"],
};
const result = await session.prompt(text,
{ responseConstraint: schema });
const { needsUmbrella } = JSON.parse(result);
返ってくるもの
スキーマどおりの JSON 文字列
使い道
if (needsUmbrella) で分岐できる
選択肢を限る
enum: ["なし", "小雨", "大雨"]