File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed
AI.HelloWorld.AppHost/Properties Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 1010 <PackageVersion Include =" OpenTelemetry.Exporter.OpenTelemetryProtocol" Version =" 1.11.2" />
1111 <PackageVersion Include =" OpenTelemetry.Extensions.Hosting" Version =" 1.11.2" />
1212 <PackageVersion Include =" OpenTelemetry.Instrumentation.Runtime" Version =" 1.11.1" />
13+ <PackageVersion Include =" Spectre.Console" Version =" 0.50.0" />
14+ <PackageVersion Include =" Spectre.Console.Cli" Version =" 0.50.0" />
1315 </ItemGroup >
1416</Project >
Original file line number Diff line number Diff line change 1+ {
2+ "$schema" : " https://json.schemastore.org/launchsettings.json" ,
3+ "profiles" : {
4+ "AI.HelloWorld.AppHost" : {
5+ "commandName" : " Project" ,
6+ "dotnetRunMessages" : true ,
7+ "launchBrowser" : true ,
8+ "applicationUrl" : " https://localhost:17142;http://localhost:15099" ,
9+ "environmentVariables" : {
10+ "ASPNETCORE_ENVIRONMENT" : " Development" ,
11+ "DOTNET_ENVIRONMENT" : " Development" ,
12+ "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL" : " https://localhost:21049" ,
13+ "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL" : " https://localhost:22281"
14+ }
15+ }
16+ }
17+ }
Original file line number Diff line number Diff line change 99 <ItemGroup >
1010 <PackageReference Include =" CommunityToolkit.Aspire.OllamaSharp" />
1111 <PackageReference Include =" Microsoft.Extensions.Hosting" />
12+ <PackageReference Include =" Spectre.Console" />
13+ <PackageReference Include =" Spectre.Console.Cli" />
1214 </ItemGroup >
1315
1416 <ItemGroup >
Original file line number Diff line number Diff line change 22using Microsoft . Extensions . Hosting ;
33using Microsoft . Extensions . AI ;
44using Microsoft . Extensions . DependencyInjection ;
5+ using Spectre . Console ;
56
67var builder = new HostApplicationBuilder ( ) ;
78
2223
2324var chatClient = app . Services . GetRequiredService < IChatClient > ( ) ;
2425
25- using var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 30 ) ) ;
26- var resp = await chatClient . GetResponseAsync ( "How many feet are in a meter?" , cancellationToken : cts . Token ) ;
27-
28- Console . WriteLine ( resp ) ;
26+ AnsiConsole . WriteLine ( ":robot: AI Hello World is ready for your questions! :rocket:" ) ;
27+ AnsiConsole . WriteLine ( "Type 'exit' to quit." ) ;
28+
29+ var textPrompt = await AnsiConsole . AskAsync < string > ( "What would you like to ask the AI?" ) ;
30+ while ( ! textPrompt . Equals ( "exit" , StringComparison . InvariantCultureIgnoreCase ) )
31+ {
32+ using var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 30 ) ) ;
33+ var resp = await chatClient . GetResponseAsync ( textPrompt , cancellationToken : cts . Token ) ;
34+
35+ foreach ( var u in resp . Messages )
36+ {
37+ AnsiConsole . WriteLine ( u . Text ) ;
38+ }
39+
40+ textPrompt = await AnsiConsole . AskAsync < string > ( "What would you like to ask the AI?" ) ;
41+ }
42+
2943await app . WaitForShutdownAsync ( ) ;
You can’t perform that action at this time.
0 commit comments