-
Notifications
You must be signed in to change notification settings - Fork 855
/
Copy pathProgram.cs
44 lines (37 loc) · 1.29 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Azure.AI.Inference;
using Azure;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using System.ComponentModel;
var githubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
if (string.IsNullOrEmpty(githubToken))
{
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
githubToken = config["GITHUB_TOKEN"];
}
ChatOptions options = new ChatOptions
{
Tools = [
AIFunctionFactory.Create(GetTheWeather)
]
};
IChatClient client = new ChatCompletionsClient(
endpoint: new Uri("https://models.inference.ai.azure.com"),
new AzureKeyCredential(githubToken))
.AsChatClient("gpt-4o-mini")
.AsBuilder()
.UseFunctionInvocation()
.Build();
var question = "Do I need an umbrella today?";
Console.WriteLine($"question: {question}");
var response = await client.GetResponseAsync(question, options);
Console.WriteLine($"response: {response}");
[Description("Get the weather")]
static string GetTheWeather()
{
var temperature = Random.Shared.Next(5, 20);
var conditions = Random.Shared.Next(0, 1) == 0 ? "sunny" : "rainy";
var weatherInfo = $"The weather is {temperature} degrees C and {conditions}.";
Console.WriteLine($"\tFunction Call - Returning weather info: {weatherInfo}");
return weatherInfo;
}