Skip to content

Commit 94fe09f

Browse files
Improved code quality issues
1 parent ce71d54 commit 94fe09f

38 files changed

Lines changed: 111 additions & 251 deletions

File tree

App/backend-api/Microsoft.GS.DPS.Host/API/ChatHost/Chat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void AddAPIs(WebApplication app)
1717
ChatRequestValidator validator,
1818
ChatHost chatHost) =>
1919
{
20-
if(validator.Validate(request).IsValid == false)
20+
if (!validator.Validate(request).IsValid)
2121
{
2222
return Results.BadRequest();
2323
}
@@ -37,7 +37,7 @@ public static void AddAPIs(WebApplication app)
3737
ChatRequestValidator validator,
3838
ChatHost chatHost) =>
3939
{
40-
if (validator.Validate(request).IsValid == false)
40+
if (!validator.Validate(request).IsValid)
4141
{
4242
return Results.BadRequest();
4343
}

App/backend-api/Microsoft.GS.DPS.Host/API/KernelMemory/KernelMemory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ DPS.API.KernelMemory kernelMemory
9393
await kernelMemory.DeleteDocument(documentId);
9494
return Results.Ok(new DocumentDeletedResult() { IsDeleted = true });
9595
}
96+
#pragma warning disable CA1031 // Must catch all to log and keep the process alive
9697
catch (Exception ex)
9798
{
99+
app.Logger.LogError(ex, "An error occurred while deleting document {DocumentId}.", documentId);
98100
return Results.BadRequest(new DocumentDeletedResult() { IsDeleted = false });
99101
}
102+
#pragma warning restore CA1031
100103
})
101104
.DisableAntiforgery();
102105

@@ -197,7 +200,6 @@ DPS.API.KernelMemory kernelMemory
197200

198201
if (status.RemainingSteps.Count == 0)
199202
{
200-
completeFlag = true;
201203
break;
202204
}
203205
var totalSteps = status.Steps.Count;

App/backend-api/Microsoft.GS.DPS.Host/API/UserInterface/UserInterface.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public static void AddAPIs(WebApplication app)
3030
var document = await documentRepository.FindByDocumentIdAsync(DocumentId);
3131

3232
//Check if the thumbnail is already in the cache
33-
if (thumbnails.ContainsKey(document.MimeType))
33+
if (thumbnails.TryGetValue(document.MimeType, out var thumbnail))
3434
{
35-
return Results.File(thumbnails[document.MimeType], "image/png");
35+
return Results.File(thumbnail, "image/png");
3636
}
3737
else
3838
{

App/backend-api/Microsoft.GS.DPS.Host/DependencyConfiguration/ServiceDependencies.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public static void Inject(IHostApplicationBuilder builder)
2828
.AddSingleton<Microsoft.GS.DPS.API.UserInterface.DataCacheManager>()
2929
.AddSingleton<Microsoft.SemanticKernel.Kernel>(x =>
3030
{
31-
var aiService = x.GetRequiredService<IOptions<AIServices>>().Value;
3231
return Kernel.CreateBuilder()
3332
.AddAzureOpenAIChatCompletion(deploymentName: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["ModelName"] ?? "",
3433
endpoint: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["Endpoint"] ?? "",

App/backend-api/Microsoft.GS.DPS/API/ChatHost/ChatHost.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static ChatHost()
4949
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
5050
var assemblyDirectory = System.IO.Path.GetDirectoryName(assemblyLocation);
5151
// binding assembly directory with file path (Prompts/Chat_SystemPrompt.txt)
52-
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts/Chat_SystemPrompt.txt");
52+
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts", "Chat_SystemPrompt.txt");
5353
ChatHost.s_systemPrompt = System.IO.File.ReadAllText(systemPromptFilePath);
5454
ChatHost.s_assistancePrompt =
5555
@"
@@ -74,14 +74,13 @@ Please feel free to ask me any questions related to those documents and contents
7474

7575
private async Task<ChatSession> makeNewSession(string? chatSessionId)
7676
{
77-
var sessionId = string.Empty;
7877
if(string.IsNullOrEmpty(chatSessionId))
7978
{
80-
sessionId = Guid.NewGuid().ToString();
79+
this.sessionId = Guid.NewGuid().ToString();
8180
}
8281
else
8382
{
84-
sessionId = chatSessionId;
83+
this.sessionId = chatSessionId;
8584
}
8685

8786
//Create New Chat History
@@ -92,7 +91,7 @@ private async Task<ChatSession> makeNewSession(string? chatSessionId)
9291
//Create a new ChatSession Entity for Saving into Azure Cosmos
9392
return new ChatSession()
9493
{
95-
SessionId = sessionId, // New Session ID
94+
SessionId = this.sessionId, // New Session ID
9695
StartTime = DateTime.UtcNow // Session Created Time
9796
};
9897

App/backend-api/Microsoft.GS.DPS/API/KernelMemory/KernelMemory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static KernelMemory()
3636
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
3737
var assemblyDirectory = System.IO.Path.GetDirectoryName(assemblyLocation);
3838
// binding assembly directory with file path (Prompts/KeywordExtract_SystemPrompt.txt)
39-
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts/KeywordExtract_SystemPrompt.txt");
39+
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts", "KeywordExtract_SystemPrompt.txt");
4040
KernelMemory.keywordExtractorPrompt = System.IO.File.ReadAllText(systemPromptFilePath);
4141
}
4242

@@ -197,7 +197,7 @@ private async Task<string> getSummary(string documentId, string fileName)
197197

198198
return keywordDict;
199199
}
200-
catch (Exception ex)
200+
catch (Exception)
201201
{
202202
return new Dictionary<string, string>();
203203
}

App/backend-api/Microsoft.GS.DPS/Storage/AISearch/TagUpdater.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task UpdateTags(string documentId, List<string> updatingTags)
4747
try
4848
{
4949
var response = await _searchClient.MergeOrUploadDocumentsAsync(new[] { updateDocument });
50-
Console.WriteLine($"Document with ID {document["id"]} updated successfully. - {response.GetRawResponse().ToString()}");
50+
Console.WriteLine($"Document with ID {document["id"]} updated successfully. - {response.GetRawResponse()}");
5151
}
5252
catch (Exception ex)
5353
{

App/backend-api/Microsoft.GS.DPS/Storage/Components/BusinessTransactionRepository.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ public async Task<IEnumerable<TEntity>> GetAllAsync()
8080

8181
public async Task<IEnumerable<TEntity>> GetAllAsync(IEnumerable<TIdentifier> identifiers)
8282
{
83-
8483
List<TEntity> results = new List<TEntity>();
85-
IMongoCollection<TEntity> collection = _database.GetCollection<TEntity>(typeof(TEntity).Name.ToLowerInvariant());
8684
foreach (var i in identifiers)
8785
{
8886
results.Add(await this.GetAsync(i));

App/backend-api/Microsoft.GS.DPS/Storage/Documents/DocumentRepository.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,12 @@ async public Task<QueryResultSet> FindByDocumentIdsAsync(string[] documentIds,
192192
//Just in case StartDate and EndDate is not null, define filter between StartDate and EndDate
193193
//endDate should be converted from datetime to DateTime of end of day Day:23:59:59
194194

195-
FilterDefinition<Entities.Document> filter = Builders<Entities.Document>.Filter.Empty;
196-
197195
if (endDate.HasValue)
198196
{
199197
endDate = endDate?.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
200-
filter = Builders<Entities.Document>.Filter.Gte(x => x.ImportedTime, startDate ?? DateTime.Now) &
201-
Builders<Entities.Document>.Filter.Lte(x => x.ImportedTime, endDate ?? endDate);
202-
198+
var timeFilter = Builders<Entities.Document>.Filter.Gte(x => x.ImportedTime, startDate ?? DateTime.Now) &
199+
Builders<Entities.Document>.Filter.Lte(x => x.ImportedTime, endDate.Value);
200+
filterDefinition &= timeFilter;
203201
}
204202

205203

App/frontend-app/src/App.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { Suspense } from "react";
22
import { BrowserRouter } from "react-router-dom";
33
import { Layout } from "./components/layout/layout";
4-
import { Telemetry } from "./utils/telemetry/telemetry";
5-
import { AppInsightsContext, ReactPlugin } from "@microsoft/applicationinsights-react-js";
6-
import { FluentProvider, makeStyles, webLightTheme } from "@fluentui/react-components";
4+
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
75
import resolveConfig from "tailwindcss/resolveConfig";
86
import TailwindConfig from "../tailwind.config";
97
import AppRoutes from "./AppRoutes";

0 commit comments

Comments
 (0)