-
Notifications
You must be signed in to change notification settings - Fork 87
/
Program.cs
27 lines (22 loc) · 1019 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Microsoft.SemanticKernel;
var openAIChatCompletionModelName = "gpt-3.5-turbo"; // this could be other models like "gpt-4o".
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKernel();
// This should work for any other service you can decided to use E.g Mistral.
var kernel = builder.Services.AddOpenAIChatCompletion(openAIChatCompletionModelName, Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
var app = builder.Build();
app.MapGet("/WeatherForecast", async (Kernel kernel) =>
{
int temp = Random.Shared.Next(-20, 55);
return new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now),
temp,
await kernel.InvokePromptAsync<string>($"Short description of weather at {temp} degrees Celsius") // This description will be generated by the AI model for the given temperature.
);
});
app.Run();
internal record WeatherForecast(DateOnly Date, int TempratureC, string Summary)
{
public int TemperatureF => 32 + (int)(TempratureC / 0.5556);
}