diff --git a/docs/getting-started.md b/docs/getting-started.md index 7833d074..69cad254 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -779,6 +779,77 @@ python weather_assistant.py +
+.NET + +Create a new console project and update `Program.cs`: + +```csharp +using GitHub.Copilot.SDK; +using Microsoft.Extensions.AI; +using System.ComponentModel; + +// Define the weather tool using AIFunctionFactory +var getWeather = AIFunctionFactory.Create( + ([Description("The city name")] string city) => + { + var conditions = new[] { "sunny", "cloudy", "rainy", "partly cloudy" }; + var temp = Random.Shared.Next(50, 80); + var condition = conditions[Random.Shared.Next(conditions.Length)]; + return new { city, temperature = $"{temp}°F", condition }; + }, + "get_weather", + "Get the current weather for a city"); + +await using var client = new CopilotClient(); +await using var session = await client.CreateSessionAsync(new SessionConfig +{ + Model = "gpt-4.1", + Streaming = true, + Tools = [getWeather] +}); + +// Listen for response chunks +session.On(ev => +{ + if (ev is AssistantMessageDeltaEvent deltaEvent) + { + Console.Write(deltaEvent.Data.DeltaContent); + } + if (ev is SessionIdleEvent) + { + Console.WriteLine(); + } +}); + +Console.WriteLine("🌤️ Weather Assistant (type 'exit' to quit)"); +Console.WriteLine(" Try: 'What's the weather in Paris?' or 'Compare weather in NYC and LA'\n"); + +while (true) +{ + Console.Write("You: "); + var input = Console.ReadLine(); + + if (string.IsNullOrEmpty(input) || input.Equals("exit", StringComparison.OrdinalIgnoreCase)) + { + break; + } + + Console.Write("Assistant: "); + await session.SendAndWaitAsync(new MessageOptions { Prompt = input }); + Console.WriteLine("\n"); +} +``` + +Run with: + +```bash +dotnet run +``` + +
+ + **Example session:** ```