1403 "properties": {1403 "properties": {
1404 "type": { "type": "string", "enum": ["div", "button", "header", "section", "field", "form"] },1404 "type": { "type": "string", "enum": ["div", "button", "header", "section", "field", "form"] },
1405 "label": { "type": "string" },1405 "label": { "type": "string" },
1406 "children": { "type": "array", "items": { "$ref": "#/$defs/component" } },
1407 "attributes": {1406 "attributes": {
1408 "type": "array",1407 "type": "array",
1409 "items": {1408 "items": {
1412 "required": ["name", "value"],1411 "required": ["name", "value"],
1413 "additionalProperties": false1412 "additionalProperties": false
1414 }1413 }
1415 }1414 },
1415 "children": { "type": "array", "items": { "$ref": "#/$defs/component" } }
1416 },1416 },
1417 "required": ["type", "label", "children", "attributes"],1417 "required": ["type", "label", "children", "attributes"],
1418 "additionalProperties": false1418 "additionalProperties": false
1424CreateResponseOptions options = new()1424CreateResponseOptions options = new()
1425{1425{
1426 Model = "gpt-6-astra",1426 Model = "gpt-6-astra",
1427 MaxOutputTokenCount = 4096,
1427 TextOptions = new ResponseTextOptions1428 TextOptions = new ResponseTextOptions
1428 {1429 {
1429 TextFormat = ResponseTextFormat.CreateJsonSchemaFormat(1430 TextFormat = ResponseTextFormat.CreateJsonSchemaFormat(
1434 },1435 },
1435};1436};
1436options.InputItems.Add(ResponseItem.CreateSystemMessageItem("You are a UI generator. Convert the user request into a component tree."));1437options.InputItems.Add(ResponseItem.CreateSystemMessageItem("You are a UI generator. Convert the user request into a component tree."));
1437options.InputItems.Add(ResponseItem.CreateUserMessageItem("Make a User Profile Form"));1438options.InputItems.Add(ResponseItem.CreateUserMessageItem(
1439 "Make a small user profile form with exactly three direct children: " +
1440 "a Name field, an Email field, and a Save button. Give each child no children. " +
1441 "Use short labels and at most two short attributes per component."
1442));
1438 1443
1439ResponseResult response = await client.CreateResponseAsync(options);1444ResponseResult response = await client.CreateResponseAsync(options);
1440using JsonDocument parsed = JsonDocument.Parse(response.GetOutputText());1445string text = response.GetOutputText();
1446bool refused = response.OutputItems.OfType<MessageResponseItem>()
1447 .SelectMany(message => message.Content)
1448 .Any(part => part.Kind == ResponseContentPartKind.Refusal);
1449if (response.Status != ResponseStatus.Completed || refused || string.IsNullOrWhiteSpace(text))
1450{
1451 throw new InvalidOperationException("UI generation did not complete.");
1452}
1453using JsonDocument parsed = JsonDocument.Parse(text);
1441Console.WriteLine(parsed.RootElement);1454Console.WriteLine(parsed.RootElement);
1442```1455```
1443 1456