-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
198 lines (181 loc) · 8.71 KB
/
Program.cs
File metadata and controls
198 lines (181 loc) · 8.71 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using ContentUnderstanding.Common.Extensions;
using Management.Interfaces;
using Management.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Text;
namespace Management
{
public class Program
{
public static async Task Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
var services = await ContentUnderstandingBootstrapper.BootstrapAsync(
configureServices: (context, services) =>
{
services.AddSingleton<IManagementService, ManagementService>();
}
);
if (services == null)
{
Console.WriteLine("Failed to initialize. Exiting...");
return;
}
Console.WriteLine("=".PadRight(80, '='));
Console.WriteLine("Azure AI Content Understanding - Management Sample");
Console.WriteLine("=".PadRight(80, '='));
Console.WriteLine();
var service = services.GetRequiredService<IManagementService>();
var configuration = services.GetRequiredService<IConfiguration>();
// Get model deployment names from configuration
string? GetConfigValue(string key) => configuration.GetValue<string>(key) ?? Environment.GetEnvironmentVariable(key);
string? gpt41Deployment = GetConfigValue("GPT_4_1_DEPLOYMENT");
string? gpt41MiniDeployment = GetConfigValue("GPT_4_1_MINI_DEPLOYMENT");
string? textEmbedding3LargeDeployment = GetConfigValue("TEXT_EMBEDDING_3_LARGE_DEPLOYMENT");
// 1. Update defaults (set model deployment mappings)
Console.WriteLine("=== Update Defaults ===");
if (!string.IsNullOrEmpty(gpt41Deployment) && !string.IsNullOrEmpty(gpt41MiniDeployment) && !string.IsNullOrEmpty(textEmbedding3LargeDeployment))
{
Console.WriteLine("Configuring default model deployments...");
Console.WriteLine($" GPT-4.1 deployment: {gpt41Deployment}");
Console.WriteLine($" GPT-4.1-mini deployment: {gpt41MiniDeployment}");
Console.WriteLine($" text-embedding-3-large deployment: {textEmbedding3LargeDeployment}");
Console.WriteLine();
var modelDeployments = new Dictionary<string, string?>
{
["gpt-4.1"] = gpt41Deployment,
["gpt-4.1-mini"] = gpt41MiniDeployment,
["text-embedding-3-large"] = textEmbedding3LargeDeployment
};
await service.UpdateDefaultsAsync(modelDeployments);
}
else
{
Console.WriteLine("⚠️ Warning: Model deployment configuration not found in appsettings.json or environment variables.");
Console.WriteLine(" Skipping defaults update. Model deployments may not be configured.");
}
Console.WriteLine();
// 2. Get defaults (retrieve model deployment mappings)
Console.WriteLine("=== Get Defaults ===");
await service.GetDefaultsAsync();
Console.WriteLine();
// Generate analyzer ID with timestamp
string analyzerId = $"management_sample_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
// Create a custom analyzer using dictionary format
var contentAnalyzer = new Dictionary<string, object>
{
["baseAnalyzerId"] = "prebuilt-callCenter",
["description"] = "Sample call recording analytics",
["config"] = new Dictionary<string, object>
{
["returnDetails"] = true,
["locales"] = new[] { "en-US" }
},
["fieldSchema"] = new Dictionary<string, object>
{
["fields"] = new Dictionary<string, object>
{
["Summary"] = new Dictionary<string, object>
{
["type"] = "string",
["method"] = "generate",
["description"] = "A one-paragraph summary"
},
["Topics"] = new Dictionary<string, object>
{
["type"] = "array",
["method"] = "generate",
["description"] = "Top 5 topics mentioned",
["items"] = new Dictionary<string, object>
{
["type"] = "string"
}
},
["Companies"] = new Dictionary<string, object>
{
["type"] = "array",
["method"] = "generate",
["description"] = "List of companies mentioned",
["items"] = new Dictionary<string, object>
{
["type"] = "string"
}
},
["People"] = new Dictionary<string, object>
{
["type"] = "array",
["method"] = "generate",
["description"] = "List of people mentioned",
["items"] = new Dictionary<string, object>
{
["type"] = "object",
["properties"] = new Dictionary<string, object>
{
["Name"] = new Dictionary<string, object>
{
["type"] = "string",
["description"] = "Person's name"
},
["Role"] = new Dictionary<string, object>
{
["type"] = "string",
["description"] = "Person's title/role"
}
}
}
},
["Sentiment"] = new Dictionary<string, object>
{
["type"] = "string",
["method"] = "classify",
["description"] = "Overall sentiment",
["enum"] = new[] { "Positive", "Neutral", "Negative" }
},
["Categories"] = new Dictionary<string, object>
{
["type"] = "array",
["method"] = "classify",
["description"] = "List of relevant categories",
["items"] = new Dictionary<string, object>
{
["type"] = "string",
["enum"] = new[]
{
"Agriculture",
"Business",
"Finance",
"Health",
"Insurance",
"Mining",
"Pharmaceutical",
"Retail",
"Technology",
"Transportation"
}
}
}
}
},
["models"] = new Dictionary<string, object>
{
["completion"] = "gpt-4.1"
}
};
// 1. Create a simple analyzer
Console.WriteLine("=== Create Analyzer ===");
await service!.CreateAnalyzerAsync(analyzerId, contentAnalyzer);
Console.WriteLine();
// 2. List all analyzers
Console.WriteLine("=== List All Analyzers ===");
await service.ListAnalyzersAsync();
// 3. Get analyzer details
Console.WriteLine("=== Get Analyzer Details ===");
await service.GetAnalyzerDetailsAsync(analyzerId);
Console.WriteLine();
// 4. Delete analyzer
Console.WriteLine("=== Delete Analyzer ===");
await service.DeleteAnalyzerAsync(analyzerId);
}
}
}