-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (60 loc) · 2.08 KB
/
Program.cs
File metadata and controls
67 lines (60 loc) · 2.08 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.ComponentModel;
using System.ClientModel;
using Microsoft.Extensions.AI;
using Microsoft.Agents.AI;
using OpenAI;
using DotNetEnv;
// Load environment variables from .env file
Env.Load("../../../../.env");
// Get GitHub Models configuration from environment variables
var github_endpoint = Environment.GetEnvironmentVariable("GITHUB_ENDPOINT")
?? throw new InvalidOperationException("GITHUB_ENDPOINT is not set.");
var github_model_id = Environment.GetEnvironmentVariable("GITHUB_MODEL_ID") ?? "gpt-4o-mini";
var github_token = Environment.GetEnvironmentVariable("GITHUB_TOKEN")
?? throw new InvalidOperationException("GITHUB_TOKEN is not set.");
// Configure OpenAI client for GitHub Models
var openAIOptions = new OpenAIClientOptions()
{
Endpoint = new Uri(github_endpoint)
};
// Agent Tool: Random Destination Generator
[Description("Provides a random vacation destination.")]
static string GetRandomDestination()
{
var destinations = new List<string>
{
"Paris, France",
"Tokyo, Japan",
"New York City, USA",
"Sydney, Australia",
"Rome, Italy",
"Barcelona, Spain",
"Cape Town, South Africa",
"Rio de Janeiro, Brazil",
"Bangkok, Thailand",
"Vancouver, Canada"
};
var random = new Random();
int index = random.Next(destinations.Count);
return destinations[index];
}
// Create AI Agent with basic instructions and tool
AIAgent agent = new OpenAIClient(new ApiKeyCredential(github_token), openAIOptions)
.GetChatClient(github_model_id)
.AsIChatClient()
.AsAIAgent(
name: "BasicAgent",
instructions: "You are a basic AI Agent that can answer questions and suggest random travel destinations.",
tools: [AIFunctionFactory.Create((Func<string>)GetRandomDestination)]
);
// Run agent with standard response
Console.WriteLine("=== Basic Agent Response ===");
Console.WriteLine(await agent.RunAsync("Suggest a vacation destination."));
// Run agent with streaming response
Console.WriteLine("\n=== Streaming Response ===");
await foreach (var update in agent.RunStreamingAsync("Suggest a vacation destination."))
{
Console.Write(update);
}
Console.WriteLine();