-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathProgram.cs
More file actions
45 lines (35 loc) · 1.27 KB
/
Program.cs
File metadata and controls
45 lines (35 loc) · 1.27 KB
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
45
using Microsoft.Extensions.AI;
using System.ComponentModel;
var ollamaEndpoint = "http://localhost:11434";
var chatModel = "llama3.2";
IChatClient client = new OllamaChatClient(
endpoint: ollamaEndpoint,
modelId: chatModel)
.AsBuilder()
.UseFunctionInvocation()
.Build();
ChatOptions options = new ChatOptions
{
Tools = [
AIFunctionFactory.Create(GetTheWeather)
]
};
var question = "Solve 2+2. Provide an accurate and short answer";
Console.WriteLine($"question: {question}");
var response = await client.GetResponseAsync(question, options);
Console.WriteLine($"response: {response}");
Console.WriteLine();
question = "Do I need an umbrella today?. Provide an accurate and short answer";
Console.WriteLine($"question: {question}");
response = await client.GetResponseAsync(question, options);
Console.WriteLine($"response: {response}");
[Description("Get the weather")]
static string GetTheWeather()
{
Console.WriteLine("\tGetTheWeather function invoked.");
var temperature = Random.Shared.Next(5, 20);
var conditions = Random.Shared.Next(0, 1) == 0 ? "sunny" : "rainy";
var weather = $"The weather is {temperature} degrees C and {conditions}.";
Console.WriteLine($"\tGetTheWeather result: {weather}.");
return weather;
}