Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (49 loc) · 1.56 KB
/
Copy pathProgram.cs
File metadata and controls
54 lines (49 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2023 Vercel, Inc.
// Copyright 2026 Darío Kondratiuk
// SPDX-License-Identifier: Apache-2.0
using Vercel.AI;
using Vercel.AI.Gateway;
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AI_GATEWAY_API_KEY")))
{
Console.WriteLine("Set AI_GATEWAY_API_KEY to run this example.");
return;
}
#region generate-structured-data
var client = new AiClient(GatewayProvider.Create());
var result = await client.GenerateTextAsync(new GenerateTextOptions
{
ModelId = "openai/gpt-6-astra",
Output = OutputSpec.Object("""
{
"type": "object",
"properties": {
"recipe": {
"type": "object",
"properties": {
"name": { "type": "string" },
"ingredients": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"amount": { "type": "string" }
},
"required": ["name", "amount"],
"additionalProperties": false
}
},
"steps": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "ingredients", "steps"],
"additionalProperties": false
}
},
"required": ["recipe"],
"additionalProperties": false
}
"""),
Prompt = "Generate a lasagna recipe.",
});
Console.WriteLine(result.Output);
#endregion