Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@
using System.ClientModel;
using Microsoft.Extensions.AI;
using Microsoft.Agents.AI;
using Azure.AI.OpenAI;
using OpenAI;
using DotNetEnv;

// Load environment variables from .env file
Env.Load("../../../../.env");
Env.Load();

// Get GitHub Models configuration from environment variables
var github_endpoint = Environment.GetEnvironmentVariable("GITHUB_ENDPOINT")
// Get Azure OpenAI configuration from environment variables
var endpoint = Environment.GetEnvironmentVariable("GITHUB_ENDPOINT")
?? throw new InvalidOperationException("GITHUB_ENDPOINT is required");
var github_model_id = Environment.GetEnvironmentVariable("GITHUB_MODEL_ID") ?? "gpt-4o-mini";
var github_token = Environment.GetEnvironmentVariable("GITHUB_TOKEN")
var model_id = Environment.GetEnvironmentVariable("GITHUB_MODEL_ID") ?? "gpt-4o-mini";
var api_key = Environment.GetEnvironmentVariable("GITHUB_TOKEN")
?? throw new InvalidOperationException("GITHUB_TOKEN is required");

// Configure OpenAI client for GitHub Models
var openAIOptions = new OpenAIClientOptions()
{
Endpoint = new Uri(github_endpoint)
};

// Create AI Agent with custom tool
AIAgent agent = new OpenAIClient(new ApiKeyCredential(github_token), openAIOptions)
.GetChatClient(github_model_id)
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(api_key))
.GetChatClient(model_id)
.AsIChatClient()
.AsAIAgent(
name: "TravelAgent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@


<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.AI" Version="10.2.0" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.2.0-preview.1.26063.2" />
<PackageReference Include="OpenAI" Version="2.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="/Users/lokinfey/Desktop/AOAI/Foundry/agent-framework/dotnet/src/Microsoft.Agents.AI.OpenAI/Microsoft.Agents.AI.OpenAI.csproj" />
<ProjectReference Include="/Users/lokinfey/Desktop/AOAI/Foundry/agent-framework/dotnet/src/Microsoft.Agents.AI/Microsoft.Agents.AI.csproj" />
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.260209.1" />
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.260209.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-agent-framework-travelagent", "dotnet-agent-framework-travelagent.csproj", "{84534CF9-905D-F1F7-BE0B-AFD013A9C1AD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84534CF9-905D-F1F7-BE0B-AFD013A9C1AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84534CF9-905D-F1F7-BE0B-AFD013A9C1AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84534CF9-905D-F1F7-BE0B-AFD013A9C1AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84534CF9-905D-F1F7-BE0B-AFD013A9C1AD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1C76B464-0241-4BFB-B5D1-B18BA27355F2}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System.ClientModel;
using Microsoft.Extensions.AI;
using Microsoft.Agents.AI;
using OpenAI;
using Azure;
using Azure.AI.OpenAI;
using DotNetEnv;

// Load environment variables from .env file
Expand All @@ -16,11 +17,6 @@
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.")]
Expand All @@ -45,7 +41,7 @@ static string GetRandomDestination()
}

// Create AI Agent with basic instructions and tool
AIAgent agent = new OpenAIClient(new ApiKeyCredential(github_token), openAIOptions)
AIAgent agent = new AzureOpenAIClient(new Uri(github_endpoint), new AzureKeyCredential(github_token))
.GetChatClient(github_model_id)
.AsIChatClient()
.AsAIAgent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@


<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.8.0-beta.1" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.AI" Version="10.2.0" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.2.0-preview.1.26063.2" />
<PackageReference Include="OpenAI" Version="2.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="/Users/lokinfey/Desktop/AOAI/Foundry/agent-framework/dotnet/src/Microsoft.Agents.AI.OpenAI/Microsoft.Agents.AI.OpenAI.csproj" />
<ProjectReference Include="/Users/lokinfey/Desktop/AOAI/Foundry/agent-framework/dotnet/src/Microsoft.Agents.AI/Microsoft.Agents.AI.csproj" />
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.260209.1" />
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.260209.1" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.ClientModel;
using System.ClientModel.Primitives;
using System.IO;
using System.Reflection;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
Expand All @@ -9,7 +12,7 @@
using DotNetEnv;


Env.Load("/Users/lokinfey/Desktop/AOAI/Foundry/Agent-Framework-Samples/.env");
Env.Load("../../../../.env");

var endpoint = Environment.GetEnvironmentVariable("AZURE_AI_PROJECT_ENDPOINT") ?? throw new InvalidOperationException("AZURE_AI_PROJECT_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_AI_MODEL_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
Expand All @@ -22,9 +25,18 @@

// Upload the file that contains the data to be used for RAG to the Foundry service.
OpenAIFileClient fileClient = openAIClient.GetOpenAIFileClient();
ClientResult<OpenAIFile> uploadResult = await fileClient.UploadFileAsync(
filePath: "../document.md",
purpose: FileUploadPurpose.Assistants);
ClientResult<OpenAIFile> uploadResult;
try
{
uploadResult = await fileClient.UploadFileAsync(
filePath: "../document.md",
purpose: FileUploadPurpose.Assistants);
}
catch (ClientResultException ex)
{
LogDetailedClientError("File upload failed", ex);
throw;
}

#pragma warning disable OPENAI001
VectorStoreClient vectorStoreClient = openAIClient.GetVectorStoreClient();
Expand All @@ -50,5 +62,56 @@ Do not answer from general knowledge or reasoning. Do not make assumptions or ge

AgentSession session = await agent.CreateSessionAsync();

Console.WriteLine(await agent.RunAsync("Can you explain Contoso's travel insurance coverage?", session));
//Console.WriteLine(await agent.RunAsync("Can you explain Contoso's travel insurance coverage?", session));
Console.WriteLine(await agent.RunAsync("What is the weather in Ohio today?", session));

static void LogDetailedClientError(string context, ClientResultException ex)
{
Console.Error.WriteLine($"[Client Error] {context}");
Console.Error.WriteLine($"Status: {ex.Status}");
Console.Error.WriteLine($"Message: {ex.Message}");
var responseBody = TryExtractResponseBody(ex);
if (!string.IsNullOrWhiteSpace(responseBody))
{
Console.Error.WriteLine("Server response body:");
Console.Error.WriteLine(responseBody);
}
}

static string? TryExtractResponseBody(ClientResultException ex)
{
try
{
var responseField = typeof(ClientResultException).GetField("_response", BindingFlags.NonPublic | BindingFlags.Instance);
if (responseField?.GetValue(ex) is PipelineResponse response)
{
var stream = response.ContentStream;
if (stream == null)
{
return null;
}

if (stream.CanSeek)
{
stream.Position = 0;
}

using var reader = new StreamReader(stream, leaveOpen: true);
var body = reader.ReadToEnd();

if (stream.CanSeek)
{
stream.Position = 0;
}

return body;
}
}
catch
{
// Ignore reflection or IO errors when extracting diagnostics.
}

return null;
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.8.0-beta.1" />
<PackageReference Include="Azure.Identity" Version="1.17.1" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageVersion Include="Azure.AI.Projects" Version="1.2.0-beta.5" />
<PackageVersion Include="Azure.AI.Projects.OpenAI" Version="1.0.0-beta.5" />
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.8" />
<PackageReference Include="Azure.AI.Projects" Version="1.2.0-beta.5" />
<PackageReference Include="Azure.AI.Projects.OpenAI" Version="1.0.0-beta.5" />
<PackageReference Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.8" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.2.0-preview.1.26063.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="/Users/lokinfey/Desktop/AOAI/Foundry/agent-framework/dotnet/src/Microsoft.Agents.AI.AzureAI/Microsoft.Agents.AI.AzureAI.csproj" />
<ProjectReference Include="/Users/lokinfey/Desktop/AOAI/Foundry/agent-framework/dotnet/src/Microsoft.Agents.AI/Microsoft.Agents.AI.csproj" />
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.260209.1" />
<PackageReference Include="Microsoft.Agents.AI.AzureAI" Version="1.0.0-preview.260209.1" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions TempInspect/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Linq;

var type = Type.GetType("System.ClientModel.ClientResultException, System.ClientModel");
Console.WriteLine(type);
foreach (var prop in type.GetProperties())
{
Console.WriteLine($"Property: {prop.Name} - {prop.PropertyType}");
}
foreach (var field in type.GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance))
{
Console.WriteLine($"Field: {field.Name} - {field.FieldType}");
}
14 changes: 14 additions & 0 deletions TempInspect/TempInspect.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ClientModel" Version="1.4.0-beta.1" />
</ItemGroup>

</Project>