-
Notifications
You must be signed in to change notification settings - Fork 5.1k
add RAG sample #47736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add RAG sample #47736
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
402 changes: 402 additions & 0 deletions
402
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/.gitignore
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/AzureSimpleRAG.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <UserSecretsId>017b91ec-85fc-4da9-8279-348386920e8c</UserSecretsId> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Azure.CloudMachine.All" Version="1.0.0-alpha.20241213.1" /> | ||
| </ItemGroup> | ||
| </Project> | ||
24 changes: 24 additions & 0 deletions
24
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/AzureSimpleRAG.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}") = "AzureSimpleRAG", "AzureSimpleRAG.csproj", "{975B7535-0A67-4222-51AC-54660CFE778D}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {975B7535-0A67-4222-51AC-54660CFE778D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {975B7535-0A67-4222-51AC-54660CFE778D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {975B7535-0A67-4222-51AC-54660CFE778D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {975B7535-0A67-4222-51AC-54660CFE778D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {9D880DBA-F11A-4C6E-ABA6-C39DE1BA8513} | ||
| EndGlobalSection | ||
| EndGlobal |
26 changes: 26 additions & 0 deletions
26
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Error.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| @page | ||
| @model ErrorModel | ||
| @{ | ||
| ViewData["Title"] = "Error"; | ||
| } | ||
|
|
||
| <h1 class="text-danger">Error.</h1> | ||
| <h2 class="text-danger">An error occurred while processing your request.</h2> | ||
|
|
||
| @if (Model.ShowRequestId) | ||
| { | ||
| <p> | ||
| <strong>Request ID:</strong> <code>@Model.RequestId</code> | ||
| </p> | ||
| } | ||
|
|
||
| <h3>Development Mode</h3> | ||
| <p> | ||
| Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred. | ||
| </p> | ||
| <p> | ||
| <strong>The Development environment shouldn't be enabled for deployed applications.</strong> | ||
| It can result in displaying sensitive information from exceptions to end users. | ||
| For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> | ||
| and restarting the app. | ||
| </p> |
27 changes: 27 additions & 0 deletions
27
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Error.cshtml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using System.Diagnostics; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
|
||
| namespace AzureSimpleRAG.Pages; | ||
christothes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
| [IgnoreAntiforgeryToken] | ||
| public class ErrorModel : PageModel | ||
christothes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public string? RequestId { get; set; } | ||
|
|
||
| public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
|
|
||
| private readonly ILogger<ErrorModel> _logger; | ||
|
|
||
| public ErrorModel(ILogger<ErrorModel> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public void OnGet() | ||
| { | ||
| RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; | ||
| } | ||
| } | ||
|
|
||
159 changes: 159 additions & 0 deletions
159
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Index.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| @page | ||
| @model IndexModel | ||
| @{ | ||
| ViewData["Title"] = "Home page"; | ||
| } | ||
| <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | ||
| <div class="row justify-content-end"> | ||
| <p> | ||
| <div class="collapse col-5 me-3" id="collapseExample"> | ||
| <div class="card card-body"> | ||
| <form id="fileUploadForm" method="post" enctype="multipart/form-data"> | ||
| <div class="form-group"> | ||
| <label for="file" class="fw-normal">Upload file:</label> | ||
| <input type="file" id="file" name="file" class="form-control-file" /> | ||
| </div> | ||
| </form> | ||
| <div id="liveAlertPlaceholder"></div> | ||
| </div> | ||
| </div> | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="container mt-5"> | ||
| <div class="row justify-content-center mt-4"> | ||
| <span class="text-center fs-1 col-4">Ask Your Data</span> | ||
| </div> | ||
| <div class="row justify-content-center mt-4"> | ||
| <div class="col-md-8"> | ||
| <div id="chatHistory" class="border p-3 mb-3" style="height: 600px; overflow-y: scroll;"> | ||
| @* Chat history will be appended here *@ | ||
| </div> | ||
| <div class="input-group mb-3"> | ||
| <button class="btn btn-outline-secondary" type="button" id="filebtn"> | ||
| <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M9 7C9 4.23858 11.2386 2 14 2C16.7614 2 19 4.23858 19 7V15C19 18.866 15.866 22 12 22C8.13401 22 5 18.866 5 15V9C5 8.44772 5.44772 8 6 8C6.55228 8 7 8.44772 7 9V15C7 17.7614 9.23858 20 12 20C14.7614 20 17 17.7614 17 15V7C17 5.34315 15.6569 4 14 4C12.3431 4 11 5.34315 11 7V15C11 15.5523 11.4477 16 12 16C12.5523 16 13 15.5523 13 15V9C13 8.44772 13.4477 8 14 8C14.5523 8 15 8.44772 15 9V15C15 16.6569 13.6569 18 12 18C10.3431 18 9 16.6569 9 15V7Z" fill="currentColor"></path></svg> | ||
| </button> | ||
| <input type="text" id="chatPrompt2" class="form-control" aria-label="chat" placeholder="Type your prompt here..."> | ||
| <button class="btn btn-outline-secondary" type="button" id="sendPrompt2"> | ||
| <svg width="32" height="32" viewBox="0 0 32 32" fill="white" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.1918 8.90615C15.6381 8.45983 16.3618 8.45983 16.8081 8.90615L21.9509 14.049C22.3972 14.4953 22.3972 15.2189 21.9509 15.6652C21.5046 16.1116 20.781 16.1116 20.3347 15.6652L17.1428 12.4734V22.2857C17.1428 22.9169 16.6311 23.4286 15.9999 23.4286C15.3688 23.4286 14.8571 22.9169 14.8571 22.2857V12.4734L11.6652 15.6652C11.2189 16.1116 10.4953 16.1116 10.049 15.6652C9.60265 15.2189 9.60265 14.4953 10.049 14.049L15.1918 8.90615Z" fill="white"></path></svg> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <script> | ||
| $(document).ready(function () { | ||
| var allowedExtensions = ['.txt', '.md', '.json']; | ||
|
|
||
| $('#sendPrompt2').click(function () { | ||
| var prompt = $('#chatPrompt2').val(); | ||
| if (prompt.trim() === '') { | ||
| return; | ||
| } | ||
|
|
||
| // Clear the chat prompt textbox | ||
| $('#chatPrompt2').val(''); | ||
|
|
||
| // Add the prompt to the chat history | ||
| $('#chatHistory').append('<p><strong>You:</strong> ' + prompt + '</p>'); | ||
|
|
||
| // Send the prompt to the backend via AJAX | ||
| $.ajax({ | ||
| url: '/chat', | ||
| type: 'POST', | ||
| contentType: 'application/json', | ||
| data: prompt, | ||
| success: function (response) { | ||
| // Add the response to the chat history | ||
| $('#chatHistory').append('<p><strong>Agent:</strong> ' + response + '</p>'); | ||
| // Scroll to the bottom of the chat history | ||
| $('#chatHistory').scrollTop($('#chatHistory')[0].scrollHeight); | ||
| }, | ||
| error: function (jqXHR, textStatus, errorThrown) { | ||
| // Display an error message in the chat history | ||
| $('#chatHistory').append('<p><strong>Agent:</strong> Error occurred while processing your request: ' + jqXHR.responseText + '</p>'); | ||
| // Scroll to the bottom of the chat history | ||
| $('#chatHistory').scrollTop($('#chatHistory')[0].scrollHeight); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| $('#filebtn').click(function () { | ||
| $('#file').click(); | ||
| }); | ||
|
|
||
| $('#file').change(function () { | ||
| if ($('#file').val()) { | ||
| if (validateFileType()) { | ||
| $('#fileUploadForm').submit(); | ||
| } else { | ||
| alert('Unsupported file type. Please select one of the supported file types: ' + allowedExtensions.slice(0, -1).join(', ') + ', and ' + allowedExtensions.slice(-1) + '.'); | ||
| $('#file').val(''); // Clear the file input | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| $('#fileUploadForm').submit(function (e) { | ||
| e.preventDefault(); // Prevent the default form submission | ||
|
|
||
| // var formData = new FormData(this); | ||
| var formData = new FormData(); | ||
| var fileInput = document.getElementById('file'); | ||
| var file = fileInput.files[0]; | ||
|
|
||
| // Append the file with a specific content type | ||
| formData.append('file', new Blob([file], { type: 'text/plain' }), file.name); | ||
|
|
||
| $.ajax({ | ||
| url: '/upload', // Replace with your actual upload endpoint | ||
| type: 'POST', | ||
| data: formData, | ||
| contentType: false, | ||
| processData: false, | ||
| success: function (response) { | ||
| // Handle success response | ||
| appendAlert('File uploaded successfully!', 'success'); | ||
| const fileList = document.getElementById('fileList'); | ||
| const wrapper = document.createElement('li'); | ||
| wrapper.innerHTML = '<a class="dropdown-item" href="#">' + file.name + '</a>'; | ||
| fileList.append(wrapper); | ||
|
|
||
| $('#file').val(''); // Clear the file input | ||
| }, | ||
| error: function (jqXHR, textStatus, errorThrown) { | ||
| // Handle error response | ||
| alert('Error occurred while uploading the file: ' + jqXHR.responseText); | ||
| } | ||
| }); | ||
| }); | ||
| const alertPlaceholder = document.getElementById('liveAlertPlaceholder'); | ||
| const appendAlert = (message, type) => { | ||
| const wrapper = document.createElement('div'); | ||
| wrapper.innerHTML = [ | ||
| `<div class="alert alert-${type} alert-dismissible" role="alert">`, | ||
| ` <div>${message}</div>`, | ||
| ' <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>', | ||
| '</div>' | ||
| ].join('') | ||
|
|
||
| alertPlaceholder.append(wrapper) | ||
| } | ||
|
|
||
| // Add keypress event listener to chatPrompt input | ||
| $('#chatPrompt2').keypress(function (e) { | ||
| if (e.which === 13) { // Enter key pressed | ||
| $('#sendPrompt2').click(); | ||
| return false; // Prevent the default form submission | ||
| } | ||
| }); | ||
|
|
||
| // Function to validate the file type | ||
| function validateFileType() { | ||
| var fileInput = document.getElementById('file'); | ||
| var filePath = fileInput.value; | ||
| var fileExtension = filePath.substring(filePath.lastIndexOf('.')).toLowerCase(); | ||
| return allowedExtensions.includes(fileExtension); | ||
| } | ||
| }); | ||
| </script> |
19 changes: 19 additions & 0 deletions
19
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Index.cshtml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
|
||
| namespace AzureSimpleRAG.Pages; | ||
|
|
||
| public class IndexModel : PageModel | ||
christothes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private readonly ILogger<IndexModel> _logger; | ||
|
|
||
| public IndexModel(ILogger<IndexModel> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public void OnGet() | ||
| { | ||
|
|
||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Privacy.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @page | ||
| @model PrivacyModel | ||
| @{ | ||
| ViewData["Title"] = "Privacy Policy"; | ||
| } | ||
| <h1>@ViewData["Title"]</h1> | ||
|
|
||
| <p>Use this page to detail your site's privacy policy.</p> |
19 changes: 19 additions & 0 deletions
19
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Privacy.cshtml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
|
||
| namespace AzureSimpleRAG.Pages; | ||
|
|
||
| public class PrivacyModel : PageModel | ||
| { | ||
| private readonly ILogger<PrivacyModel> _logger; | ||
|
|
||
| public PrivacyModel(ILogger<PrivacyModel> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public void OnGet() | ||
| { | ||
| } | ||
| } | ||
|
|
56 changes: 56 additions & 0 deletions
56
sdk/cloudmachine/Azure.CloudMachine/samples/AzureSImpleRAG/Pages/Shared/_Layout.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" data-bs-theme="dark"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>@ViewData["Title"] - AzureSimpleRAG</title> | ||
| <script type="importmap"></script> | ||
| <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> | ||
| <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> | ||
| <link rel="stylesheet" href="~/AzureSimpleRAG.styles.css" asp-append-version="true" /> | ||
| </head> | ||
| <body> | ||
| <header> | ||
| <nav class="navbar navbar-expand-lg bg-body-tertiary"> | ||
| <div class="container-fluid"> | ||
| <a class="navbar-brand" asp-area="" asp-page="/Index">AzureSimpleRAG</a> | ||
| <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" | ||
| aria-expanded="false" aria-label="Toggle navigation"> | ||
| <span class="navbar-toggler-icon"></span> | ||
| </button> | ||
| <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> | ||
| <ul class="navbar-nav flex-grow-1"> | ||
| <li class="nav-item"> | ||
| <a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a> | ||
| </li> | ||
| <li class="nav-item dropdown"> | ||
| <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> | ||
| Files Uploaded | ||
| </a> | ||
| <ul id="fileList" class="dropdown-menu"> | ||
| </ul> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </nav> | ||
| </header> | ||
| <div class="container"> | ||
| <main role="main" class="pb-3"> | ||
| @RenderBody() | ||
| </main> | ||
| </div> | ||
|
|
||
| <footer class="border-top footer text-muted"> | ||
| <div class="container"> | ||
| © 2024 - AzureSimpleRAG - <a asp-area="" asp-page="/Privacy">Privacy</a> | ||
| </div> | ||
| </footer> | ||
|
|
||
| <script src="~/lib/jquery/dist/jquery.min.js"></script> | ||
| <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> | ||
| <script src="~/js/site.js" asp-append-version="true"></script> | ||
|
|
||
| @await RenderSectionAsync("Scripts", required: false) | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.