microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
Samples/Samples.AI/Prompts/WeatherPrompt.cs
47lines · modeblame
19e4df96Aamir Jawaid8 months ago | 1 | using Microsoft.Teams.AI.Annotations; |
| 2 | using Microsoft.Teams.Api.Activities; | |
| 3 | using Microsoft.Teams.Apps; | |
| 4 | | |
| 5 | namespace Samples.AI.Prompts; | |
| 6 | | |
| 7 | [Prompt] | |
| 8 | [Prompt.Description("Weather assistant")] | |
| 9 | [Prompt.Instructions("You are a helpful assistant that can help the user get the weather. First get their location, then get the weather for that location.")] | |
| 10 | public class WeatherPrompt(IContext<IActivity> context) | |
| 11 | { | |
| 12 | [Function] | |
| 13 | [Function.Description("Gets the location of the user")] | |
| 14 | public string GetUserLocation() | |
| 15 | { | |
| 16 | var locations = new[] { "Seattle", "San Francisco", "New York" }; | |
| 17 | var random = new Random(); | |
| 18 | var location = locations[random.Next(locations.Length)]; | |
| 19 | | |
| 20 | context.Log.Info($"[PROMPT-FUNCTION] get_user_location called, returning mock location: '{location}'"); | |
| 21 | return location; | |
| 22 | } | |
| 23 | | |
| 24 | [Function] | |
| 25 | [Function.Description("Search for weather at a specific location")] | |
| 26 | public string WeatherSearch([Param] string location) | |
| 27 | { | |
| 28 | context.Log.Info($"[PROMPT-FUNCTION] weather_search called with location='{location}'"); | |
| 29 | | |
| 30 | var weatherByLocation = new Dictionary<string, (int Temperature, string Condition)> | |
| 31 | { | |
| 32 | ["Seattle"] = (65, "sunny"), | |
| 33 | ["San Francisco"] = (60, "foggy"), | |
| 34 | ["New York"] = (75, "rainy") | |
| 35 | }; | |
| 36 | | |
| 37 | if (!weatherByLocation.TryGetValue(location, out var weather)) | |
| 38 | { | |
| 39 | context.Log.Info($"[PROMPT-FUNCTION] Weather data not found for location '{location}'"); | |
| 40 | return "Sorry, I could not find the weather for that location"; | |
| 41 | } | |
| 42 | | |
| 43 | var result = $"The weather in {location} is {weather.Condition} with a temperature of {weather.Temperature}°F"; | |
| 44 | context.Log.Info($"[PROMPT-FUNCTION] Returning weather data: {result}"); | |
| 45 | return result; | |
| 46 | } | |
b6c66549Alex Acebo6 months ago | 47 | } |