Skip to content
Merged
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
76 changes: 76 additions & 0 deletions AI/agent-with-retrieval-sample-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/

# Visual Studio cache files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files
.vscode/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Sensitive configuration files
appsettings.json
appsettings.*.json
!appsettings.example.json

# Environment files
.env
.env.local
.env.*.local

# Azure Functions
local.settings.json

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Dependency directories
node_modules/

# NuGet packages
*.nupkg
packages/
!packages/repositories.config
!packages/*/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Azure credentials cache
.azure/
117 changes: 117 additions & 0 deletions AI/agent-with-retrieval-sample-app/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SPEAgentWithRetrieval.Core.Models;
using SPEAgentWithRetrieval.Core.Services;

namespace SPEAgentWithRetrieval;

class Program
{
static async Task Main(string[] args)
{
// Build configuration
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();

// Build host with dependency injection
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
// Configure options
services.Configure<AzureAIFoundryOptions>(configuration.GetSection("AzureAIFoundry"));
services.Configure<Microsoft365Options>(configuration.GetSection("Microsoft365"));
services.Configure<ChatSettingsOptions>(configuration.GetSection("ChatSettings"));

// Register services. Singleton lifetime is appropriate for this single-user
// console app (services are resolved from the root provider for the app's lifetime).
services.AddSingleton<ITokenProvider, TokenProvider>();
services.AddSingleton<IRetrievalService, CopilotRetrievalService>();
services.AddSingleton<IFoundryService, FoundryService>();
services.AddSingleton<IChatService, ChatService>();

// Add logging
services.AddLogging(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Information);
});
})
.Build();

// Get the chat service and logger
var chatService = host.Services.GetRequiredService<IChatService>();
var logger = host.Services.GetRequiredService<ILogger<Program>>();

logger.LogInformation("Azure AI Chat Agent with SharePoint Embedded RAG started");

System.Console.WriteLine("=== Azure AI Chat Agent with SharePoint Embedded RAG ===");
System.Console.WriteLine("Ask questions about your Microsoft 365 content!");
System.Console.WriteLine("Type 'exit' or 'quit' to end the conversation.");
System.Console.WriteLine("Type 'clear' to clear the console.");
System.Console.WriteLine();

// Main chat loop
while (true)
{
System.Console.Write("You: ");
var userInput = System.Console.ReadLine();

if (string.IsNullOrWhiteSpace(userInput))
continue;

// Handle special commands
if (userInput.Equals("exit", StringComparison.OrdinalIgnoreCase) ||
userInput.Equals("quit", StringComparison.OrdinalIgnoreCase))
{
System.Console.WriteLine("Goodbye!");
break;
}

if (userInput.Equals("clear", StringComparison.OrdinalIgnoreCase))
{
System.Console.Clear();
System.Console.WriteLine("=== Azure AI Chat Agent with SharePoint Embedded RAG ===");
continue;
}

try
{
// Process the chat request
var chatRequest = new ChatRequest { Message = userInput };
var response = await chatService.ProcessChatAsync(chatRequest);

System.Console.WriteLine($"Assistant: {response.Response}");

// Show sources if available
if (response.Sources.Any())
{
System.Console.WriteLine();
System.Console.WriteLine("Sources:");
foreach (var source in response.Sources.Take(3)) // Show top 3 sources
{
System.Console.WriteLine($" • {source.Title}");
if (!string.IsNullOrEmpty(source.Url))
{
System.Console.WriteLine($" {source.Url}");
}
}
}

System.Console.WriteLine();
}
catch (Exception ex)
{
logger.LogError(ex, "Error in chat loop");
System.Console.WriteLine("Sorry, I encountered an error. Please try again.");
System.Console.WriteLine();
}
}

await host.StopAsync();
}
}
Loading