Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Apps/WadeTheMeteorologist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ namespace GenAI.Reference.Samples.Apps
{
internal class WadeTheMeteorologist
{
internal static async Task Execute(string weatherApiKey, Kernel kernel)
internal static async Task Execute(string weatherApiKey, string weatherApiUrl, Kernel kernel)
{
var rule = new Rule("[bold white on green4]:: Wade - the AI Meteorlogist ::[/]");
AnsiConsole.Write(rule);
Console.WriteLine();

var weatherService = new WeatherService(weatherApiKey);
var weatherService = new WeatherService(weatherApiKey, weatherApiUrl);
kernel.ImportPluginFromObject(weatherService);

var settings = new OpenAIPromptExecutionSettings() { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions };
Expand Down
13 changes: 7 additions & 6 deletions Core/WeatherService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel;

namespace SKAgentApp.Core
{
Expand All @@ -7,19 +7,20 @@ namespace SKAgentApp.Core
/// </summary>
internal class WeatherService
{
private string _weatherApiKey;
private readonly string _weatherApiKey;
private readonly string _weatherApiUrl;

public WeatherService(string weatherApiKey)
public WeatherService(string weatherApiKey, string weatherApiUrl)
{
this._weatherApiKey = weatherApiKey;
_weatherApiKey = weatherApiKey;
_weatherApiUrl = weatherApiUrl;
}

// Add a method a kernel function to get detailed weather report data from weatherapi.com
[KernelFunction]
public async Task<string> GetWeather(string location)
{
// TODO: api url should be in App Settings and retrieved from there via Configuration
string apiUrl = $"https://api.weatherapi.com/v1/current.json?key={_weatherApiKey}&q={location}&aqi=no";
string apiUrl = $"{_weatherApiUrl}?key={_weatherApiKey}&q={location}&aqi=no";
using (var client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(apiUrl);
Expand Down
6 changes: 5 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
using Microsoft.SemanticKernel;

var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.AddUserSecrets<Program>();
var configuration = builder.Build();

string weatherApiUrl = configuration["WeatherApi:Url"]
?? throw new ArgumentNullException(nameof(weatherApiUrl), "The WeatherApi Url is not configured.");

string weatherApiKey = configuration["AI:WeatherApi:ApiKey"]
?? throw new ArgumentNullException(nameof(weatherApiKey), "The weatherApi Key is not set as a user secret.");

Expand All @@ -25,7 +29,7 @@
Kernel kernel = kernelBuilder.Build();

// #1 Wade, the Meteorologist
// await WadeTheMeteorologist.Execute(weatherApiKey, kernel);
// await WadeTheMeteorologist.Execute(weatherApiKey, weatherApiUrl, kernel);

// #2 TaxImpactAnalyzer - AgentGroupChat
await TaxImpactAnalyzer.Execute(kernel);
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ GenAI.Reference.Samples has 2 samples:

### 2. Configure User Secrets

Add your Azure OpenAI API Key and Endpoint to the user secrets:
Add your Azure OpenAI API Key, Endpoint, and Weather API settings to the user secrets:

```bash
dotnet user-secrets set "AI:EASub:AzureOpenAI:Endpoint" "<azure openai endpoint goes here>"
dotnet user-secrets set "AI:EASub:AzureOpenAI:Endpoint" "<azure openai endpoint goes here>"
dotnet user-secrets set "AI:EASub:AzureOpenAI:ApiKey" "<azure openai api key goes here>"
dotnet user-secrets set "AI:WeatherApi:ApiKey" "<weather api key goes here>"
dotnet user-secrets set "WeatherApi:Url" "https://api.weatherapi.com/v1/current.json"
```


Expand Down Expand Up @@ -96,4 +97,4 @@ Contains the SP (System Prompt) instructions for the `TaxImpactAnalyzerAgent`. T
Contains the SP (System Prompt) instructions for the `TaxImpactReviewerAgent`. This agent reviews the Tax Impact Analysis provided by the `TaxImpactAnalyzerAgent` and asks the user key questions to provide a recommendation.

### WeatherService.cs
Provides weather data from weatherapi.com using Semantic Kernel's KernelFunction invokation
Provides weather data from weatherapi.com using Semantic Kernel's KernelFunction invokation
5 changes: 5 additions & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"WeatherApi": {
"Url": "https://api.weatherapi.com/v1/current.json"
}
}