-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (36 loc) · 1.53 KB
/
Program.cs
File metadata and controls
44 lines (36 loc) · 1.53 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
using OpenTelemetry;
using OpenTelemetry.Trace;
using MAF_ImageGen_01;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
// get mcp tools
var (mcpClient, tools) = await HuggingFaceMCP.GetHuggingFaceMCPClientAndToolsAsync();
foreach (var tool in tools)
{
Console.WriteLine($"Connected to server with tools: {tool.Name}");
}
Console.WriteLine($"===");
// get chat client
IChatClient chatClient = ChatClientProvider.GetChatClient();
// Create a TracerProvider that exports to the console
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("agent-telemetry-source")
.AddConsoleExporter()
.Build();
// create image generator agent
var imageGenerator = chatClient.AsAIAgent(
name: "Image Generator",
instructions: "You are an image generator agent that uses the tools from the Hugging Face MCP Server. If the user ask to create an image, use the Flux1 tool [gr1_flux1_schnell_infer]. If the user ask to generate an image, the image should always be pixelated.",
description: "An AI agent that uses the Hugging Face MCP tools to generate images.",
tools: [.. tools])
.AsBuilder()
.UseOpenTelemetry(sourceName: "agent-telemetry-source")
.Build();
// test agent
//var message = "tell me a joke about kittens";
//var message = "create an image of a racoon in Canada";
var message = "What is the name of the user logged in to the Hugging Face MCP Server";
AgentResponse response = await imageGenerator.RunAsync(
message: message);
Console.WriteLine(response.Text);
await mcpClient.DisposeAsync();