Skip to content
Draft
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
18 changes: 14 additions & 4 deletions infra/modules/ca-chat/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,20 @@ resource "azapi_resource" "ca_back" {
{
name = "AZURE_CLIENT_ID"
value = "${var.managed_identity_client_id}"
},
{
name = "APP_LOG_LEVEL"
value = "DEBUG"
},
{
name = "APP_LOG_LEVEL"
value = "DEBUG"
},
{
name = "DEFAULT_QUESTIONS"
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment variable DEFAULT_QUESTIONS won’t map to the nested config key ChatOnYourData:DefaultQuestions. Use ChatOnYourData__DefaultQuestions to match ASP.NET Core’s environment variable binding convention.

Suggested change
name = "DEFAULT_QUESTIONS"
name = "ChatOnYourData__DefaultQuestions"

Copilot uses AI. Check for mistakes.
value = jsonencode([
"Make me a summary of the document",
"Get me the most relevant topics of the document",
"Explain the document for a CEO",
"Explain the document for a kid",
"Translate the main topics of the document to X language"
])
}
],
},
Expand Down
12 changes: 10 additions & 2 deletions src/AIHub/Controllers/ChatOnYourDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ namespace MVCWeb.Controllers;
public class ChatOnYourDataController : Controller
{
private readonly ILogger<ChatOnYourDataController> _logger;
private readonly IConfiguration _configuration;

public ChatOnYourDataController(ILogger<ChatOnYourDataController> logger)
public ChatOnYourDataController(ILogger<ChatOnYourDataController> logger, IConfiguration configuration)
{
_logger = logger;
_configuration = configuration;
}

public IActionResult ChatOnYourData()
{
return View();
var model = new ChatOnYourDataModel
{
Link = _configuration.GetValue<string>("ChatOnYourData:Link") ?? string.Empty,
DefaultQuestions = _configuration.GetSection("ChatOnYourData:DefaultQuestions").Get<List<string>>() ?? new List<string>()
};

return View(model);
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
Expand Down
7 changes: 7 additions & 0 deletions src/AIHub/Models/ChatOnYourDataModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MVCWeb.Models;

public class ChatOnYourDataModel
{
public string Link { get; set; } = string.Empty;
public List<string> DefaultQuestions { get; set; } = new List<string>();
}
84 changes: 82 additions & 2 deletions src/AIHub/Views/ChatOnYourData/ChatOnYourData.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IConfiguration Configuration
@model ChatOnYourDataModel
@{
ViewData["Title"] = "Chat On Your Data";
}
Expand All @@ -25,9 +25,34 @@
<div class="col-lg-12">
<div class="card">
<div class="card-body">
@if (Model.DefaultQuestions != null && Model.DefaultQuestions.Any())
{
<div class="row mb-3">
<div class="col-12">
<h5 class="card-title">Suggested Questions</h5>
<p class="text-muted">Try these sample questions to get started with your document analysis:</p>
<div class="row">
@foreach (var question in Model.DefaultQuestions)
{
<div class="col-lg-6 col-md-12 mb-2">
<div class="card border-light">
<div class="card-body p-3">
<button type="button" class="btn btn-outline-primary btn-sm w-100 text-start question-btn"
data-question="@question">
<i class="mdi mdi-chat-question me-1"></i>
@question
</button>
</div>
</div>
</div>
}
</div>
</div>
</div>
}

<div id="chat-frame" class="ratio ratio-16x9">
<iframe id="bigframe" src="@Configuration["ChatOnYourData:Link"]" frameborder="0"></iframe>
<iframe id="bigframe" src="@Model.Link" frameborder="0"></iframe>
</div>

</div>
Expand All @@ -38,3 +63,58 @@

</div>
<!-- container -->

<style>
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inline CSS in the Razor view can make maintenance harder. Consider moving these styles into a shared stylesheet or component-specific CSS file.

Copilot uses AI. Check for mistakes.
.question-btn {
text-align: left !important;
white-space: normal;
height: auto;
padding: 10px 15px;
transition: all 0.2s ease;
}

.question-btn:hover {
background-color: #0d6efd;
border-color: #0d6efd;
color: white;
}

.question-btn.active {
background-color: #0d6efd;
border-color: #0d6efd;
color: white;
}

.question-btn i {
margin-right: 8px;
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
const questionButtons = document.querySelectorAll('.question-btn');
const iframe = document.getElementById('bigframe');

questionButtons.forEach(button => {
button.addEventListener('click', function() {
const question = this.getAttribute('data-question');

// Try to send the question to the iframe via postMessage
if (iframe && iframe.contentWindow) {
try {
iframe.contentWindow.postMessage({
type: 'set_question',
question: question
}, '*');
Copy link

Copilot AI Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using '*' as the targetOrigin in postMessage is insecure. Specify the exact origin of the iframe (e.g. new URL(Model.Link).origin) to prevent message spoofing.

Suggested change
}, '*');
}, iframeOrigin); // Use the extracted origin

Copilot uses AI. Check for mistakes.
} catch (error) {
console.log('Could not send question to iframe:', error);
}
}

// Visual feedback - highlight the clicked button
questionButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
});
});
});
</script>
10 changes: 10 additions & 0 deletions src/AIHub/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ChatOnYourData": {
"Link": "http://localhost:5000",
"DefaultQuestions": [
"Make me a summary of the document",
"Get me the most relevant topics of the document",
"Explain the document for a CEO",
"Explain the document for a kid",
"Translate the main topics of the document to X language"
]
}
}
9 changes: 8 additions & 1 deletion src/AIHub/appsettings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@
"DeploymentName": "gpt-4"
},
"ChatOnYourData": {
"Link": "<Link to Chat>"
"Link": "<Link to Chat>",
"DefaultQuestions": [
"Make me a summary of the document",
"Get me the most relevant topics of the document",
"Explain the document for a CEO",
"Explain the document for a kid",
"Translate the main topics of the document to X language"
]
},
"Storage": {
"ConnectionString": "<Storage connString>",
Expand Down