@@ -85,7 +85,6 @@ After adding the chat interface, we can set up the Azure OpenAI client using Sem
85
85
string apiKey = _config [" API_KEY" ];
86
86
string modelId = _config [" MODEL_ID" ];
87
87
88
- // Semantic Kernel builder
89
88
var builder = Kernel .CreateBuilder ();
90
89
91
90
// Chat completion service
@@ -98,15 +97,14 @@ After adding the chat interface, we can set up the Azure OpenAI client using Sem
98
97
99
98
var kernel = builder .Build ();
100
99
101
- // Create a Semantic Kernel template for chat
100
+ // Create prompt template
102
101
var chat = kernel .CreateFunctionFromPrompt (
103
102
@" {{$history}}
104
103
User: {{$request}}
105
104
Assistant: " );
106
105
107
- ChatHistory chatHistory = new (""" You are a helpful assistant that answers questions about my data. """ );
106
+ ChatHistory chatHistory = new (""" You are a helpful assistant that answers questions""" );
108
107
109
- // Get chat response and use user input
110
108
var chatResult = kernel .InvokeStreamingAsync <StreamingChatMessageContent >(
111
109
chat ,
112
110
new ()
@@ -116,7 +114,6 @@ After adding the chat interface, we can set up the Azure OpenAI client using Sem
116
114
}
117
115
);
118
116
119
- // Stream the response
120
117
string message = " " ;
121
118
await foreach (var chunk in chatResult )
122
119
{
240
237
241
238
await using var command = new SqlCommand (sql , connection );
242
239
243
- // add SqlParameter to SqlCommand
240
+ // add parameter to SqlCommand
244
241
command .Parameters .Add (param );
245
242
246
243
await using var reader = await command .ExecuteReaderAsync ();
253
250
254
251
// add results to chat history
255
252
chatHistory .AddSystemMessage (reader .GetString (1 ) + " , " + reader .GetString (2 ));
256
-
257
253
}
258
254
}
259
255
catch (SqlException e )
@@ -363,7 +359,7 @@ Here's the full example of the added *OpenAI.razor* page:
363
359
364
360
var kernel = builder .Build ();
365
361
366
- // Create a Semantic Kernel template for chat
362
+ // Create prompt template
367
363
var chat = kernel .CreateFunctionFromPrompt (
368
364
@" {{$history}}
369
365
User: {{$request}}
@@ -421,7 +417,7 @@ Here's the full example of the added *OpenAI.razor* page:
421
417
422
418
await using var command = new SqlCommand (sql , connection );
423
419
424
- // add SqlParameter to SqlCommand
420
+ // add parameter to SqlCommand
425
421
command .Parameters .Add (param );
426
422
427
423
await using var reader = await command .ExecuteReaderAsync ();
@@ -449,7 +445,6 @@ Here's the full example of the added *OpenAI.razor* page:
449
445
Console .WriteLine (" Done" );
450
446
#endregion
451
447
452
- // Get chat response and use user input
453
448
var chatResult = kernel .InvokeStreamingAsync <StreamingChatMessageContent >(
454
449
chat ,
455
450
new ()
@@ -459,14 +454,13 @@ Here's the full example of the added *OpenAI.razor* page:
459
454
}
460
455
);
461
456
462
- // Stream the response
463
457
string message = " " ;
464
458
await foreach (var chunk in chatResult )
465
459
{
466
460
message += chunk ;
467
461
}
468
462
469
- // Append to history
463
+ // Append messages to chat history
470
464
chatHistory .AddUserMessage (userMessage ! );
471
465
chatHistory .AddAssistantMessage (message );
472
466
0 commit comments