-   Notifications  You must be signed in to change notification settings 
- Fork 33
feat (code-style): [website] libs, formatting, and conventions #40
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  
  ckittel merged 55 commits into Azure-Samples:main from ferantivero:feature/419568_website-general-upd        Apr 22, 2025  
    Merged  
 Changes from all commits
 Commits 
  Show all changes 
  55 commits   Select commit Hold shift + click to select a range 
 2b1db8b  add devcontainer NET8 
  ferantivero 62d8c5a  streamline: remove sln for visual studio 
  ferantivero 66408e8  sort usings following .NET conventions 
  ferantivero 51b20cd  streamline: use primery contructors 
  ferantivero 27f6079  streamline: dict initialization 
  ferantivero 843bf70  streamline: use var if can be inferred from context 
  ferantivero e1f9348  fix: guard null api configuration values 
  ferantivero b97b3fe  streamline: remove dup code 
  ferantivero 150cda2  fix: stdout headers 
  ferantivero dae1fea  refact: add structure and more expresive logging capabs 
  ferantivero cff2100  fix: prompt null check 
  ferantivero 5c6bddf  ai naming convention: replace query var name by prompt 
  ferantivero 7965ed2  cleanup: address warnings removing dead code 
  ferantivero c188a98  cleanup: not currently in use UserSecretsId 
  ferantivero 749f2fb  update: to System.Text.Json 
  ferantivero 1648a10  streamline: remove not in use endpoint 
  ferantivero d897def  streamline: remove apparently not in use authZ capabs 
  ferantivero 8d4e641  cleanup: remove unused dev appsettings 
  ferantivero e8a2eb5  fix: add expected app settings 
  ferantivero bbb4960  configure console log level and structure log entry 
  ferantivero fa8d13a  udpdate: use modern async js function with fetch instead of jq 
  ferantivero 1bef5af  update: remove jq dep 
  ferantivero b12129c  cleanup: remove unused style 
  ferantivero 40b3b47  udpate: use options for settings 
  ferantivero c7adc4d  cleanup: use controller placeholder convention for route 
  ferantivero d721cf0  cleanup: simplify http client init 
  ferantivero 49846ab  cleanup: inline content init 
  ferantivero cdfecfe  cleanup: post and content stream invoking 
  ferantivero 2eeff48  streamline: response hanlding 
  ferantivero aa6b7b5  improve: logging messages 
  ferantivero 15b561e  update: register the httpclient 
  ferantivero 88169c2  improve: naming conventions endpoint for an ai context 
  ferantivero 69f290d  improve: js naming conventions 
  ferantivero 37da25f  improve js query elements 
  ferantivero 1fa0639  improve: add trycatch when sending a prompt 
  ferantivero c7ffe60  streamline js sendPrompr function 
  ferantivero ae7d588  streamline js addChatMessage 
  ferantivero 523035e  streamline js formatDate function 
  ferantivero e2a9014  cleanup: distilled unused markup element 
  ferantivero 24c32f3  improve: screen readers read new messages 
  ferantivero ea05d66  minors: indent, add semantic html element and more 
  ferantivero e8e0fe8  streamline: use file-scoped namespace 
  ferantivero 7eae87e  streamline: launch profile and settings 
  ferantivero 745a479  fix: remove message label that slipped through 
  ferantivero bddf108  refact: use record for inmuntale dto 
  ferantivero 124f6f0  improve: prompt guard 
  ferantivero 871922c  update zip 
  ferantivero c58d11d  Address PR Feedback: change app name 
  ferantivero 64e6969  Address PR Feedback: fix assistant behavior 
  ferantivero c47591b  Address PR Feedback: change bot name 
  ferantivero 030eba5  Address PR Feedback: change logging entry level for troubleshooting p… 
  ferantivero 78a035e  Address PR Feedback: make naming convetions gpt-agnostic 
  ferantivero eabf6ae  Address PR Feedback: support settings hot reload 
  ferantivero a42814b  Address PR Feedback: use custom httpclienthanlder validation only in dev 
  ferantivero cf8f7c6  update zip after addressing pr feedback 
  ferantivero 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
   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,18 @@ | ||
| { | ||
| "name": "Azure OpenAI end-to-end basic reference implementation", | ||
| "image": "mcr.microsoft.com/devcontainers/dotnet:dev-8.0-jammy", | ||
| "runArgs": ["--network=host"], | ||
| "remoteUser": "vscode", | ||
| "features": { | ||
| }, | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "ms-dotnettools.csdevkit", | ||
| "ms-azuretools.vscode-bicep" | ||
| ], | ||
| "settings": {} | ||
| } | ||
| }, | ||
| "forwardPorts": [] | ||
| } | 
   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   
     This file was deleted.
  Oops, something went wrong.  
  Binary file not shown. 
    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,16 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
|  | ||
| namespace chatui.Configuration; | ||
|  | ||
| public class ChatApiOptions | ||
| { | ||
| [Url] | ||
| public string ChatApiEndpoint { get; init; } = default!; | ||
|  | ||
| [Required] | ||
| public string ChatApiKey { get; init; } = default!; | ||
|  | ||
| public string ChatInputName { get; init; } = "chat_input"; | ||
|  | ||
| public string ChatOutputName { get; init; } = "chat_output"; | ||
| } | 
   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,68 @@ | ||
| using System.Net.Http.Headers; | ||
| using System.Text.Json; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Microsoft.Extensions.Options; | ||
| using chatui.Configuration; | ||
| using chatui.Models; | ||
|  | ||
| namespace chatui.Controllers; | ||
|  | ||
| [ApiController] | ||
| [Route("[controller]/[action]")] | ||
|  | ||
| public class ChatController( | ||
| IHttpClientFactory httpClientFactory, | ||
| IOptionsMonitor<ChatApiOptions> options, | ||
| ILogger<ChatController> logger) : ControllerBase | ||
| { | ||
| private readonly HttpClient _client = httpClientFactory.CreateClient("ChatClient"); | ||
| private readonly IOptionsMonitor<ChatApiOptions> _options = options; | ||
| private readonly ILogger<ChatController> _logger = logger; | ||
|  | ||
| [HttpPost] | ||
| public async Task<IActionResult> Completions([FromBody] string prompt) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(prompt)) | ||
| throw new ArgumentException("Prompt cannot be null, empty, or whitespace.", nameof(prompt)); | ||
|  | ||
| _logger.LogDebug("Prompt received {Prompt}", prompt); | ||
|  | ||
| var _config = _options.CurrentValue; | ||
|  | ||
| var requestBody = JsonSerializer.Serialize(new Dictionary<string, string> | ||
| { | ||
| [_config.ChatInputName] = prompt | ||
| }); | ||
|  | ||
| using var request = new HttpRequestMessage(HttpMethod.Post, _config.ChatApiEndpoint) | ||
| { | ||
| Content = new StringContent(requestBody, System.Text.Encoding.UTF8, "application/json"), | ||
| }; | ||
| request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _config.ChatApiKey); | ||
|  | ||
| var response = await _client.SendAsync(request); | ||
| var responseContent = await response.Content.ReadAsStringAsync(); | ||
|  | ||
| _logger.LogInformation("HTTP status code: {StatusCode}", response.StatusCode); | ||
|  | ||
| if (!response.IsSuccessStatusCode) | ||
| { | ||
| _logger.LogError("Error response: {Content}", responseContent); | ||
|  | ||
| foreach (var (key, value) in response.Headers) | ||
| _logger.LogDebug("Header {Key}: {Value}", key, string.Join(", ", value)); | ||
|  | ||
| foreach (var (key, value) in response.Content.Headers) | ||
| _logger.LogDebug("Content-Header {Key}: {Value}", key, string.Join(", ", value)); | ||
|  | ||
| return BadRequest(responseContent); | ||
| } | ||
|  | ||
| _logger.LogInformation("Successful response: {Content}", responseContent); | ||
|  | ||
| var result = JsonSerializer.Deserialize<Dictionary<string, string>>(responseContent); | ||
| var output = result?.GetValueOrDefault(_config.ChatOutputName) ?? string.Empty; | ||
|  | ||
| return Ok(new HttpChatResponse(true, output)); | ||
| } | ||
| } | 
This file was deleted.
  Oops, something went wrong.  
    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 | 
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
|  | ||
| namespace chatui.Controllers | ||
| namespace chatui.Controllers; | ||
|  | ||
| public class HomeController : Controller | ||
| { | ||
| public class HomeController : Controller | ||
| public IActionResult Index() | ||
| { | ||
| public IActionResult Index() | ||
| { | ||
| return View(); | ||
| } | ||
| return View(); | ||
| } | ||
| } | 
This file was deleted.
  Oops, something went wrong.  
    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 | 
|---|---|---|
| @@ -1,33 +1,3 @@ | ||
| namespace chatui.Models | ||
| { | ||
| public class HttpChatGPTResponse | ||
| { | ||
| public bool Success { get; set; } | ||
| public string Data { get; set; } | ||
| public string Error { get; set; } | ||
| } | ||
| namespace chatui.Models; | ||
|  | ||
| public class ChatResponse | ||
| { | ||
| public string id { get; set; } | ||
| public string _object { get; set; } | ||
| public int created { get; set; } | ||
| public Choice[] choices { get; set; } | ||
| public Usage usage { get; set; } | ||
| } | ||
|  | ||
| public class Usage | ||
| { | ||
| public int prompt_tokens { get; set; } | ||
| public int completion_tokens { get; set; } | ||
| public int total_tokens { get; set; } | ||
| } | ||
|  | ||
| public class Choice | ||
| { | ||
| public int index { get; set; } | ||
| public Message message { get; set; } | ||
| public string finish_reason { get; set; } | ||
| } | ||
|  | ||
| } | ||
| public record HttpChatResponse(bool Success, string Data); | 
   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   
        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   
       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.