Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions App/backend-api/Microsoft.GS.DPS.Host/API/ChatHost/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void AddAPIs(WebApplication app)
ChatRequestValidator validator,
ChatHost chatHost) =>
{
if(validator.Validate(request).IsValid == false)
if (!validator.Validate(request).IsValid)
{
return Results.BadRequest();
}
Expand All @@ -37,7 +37,7 @@ public static void AddAPIs(WebApplication app)
ChatRequestValidator validator,
ChatHost chatHost) =>
{
if (validator.Validate(request).IsValid == false)
if (!validator.Validate(request).IsValid)
{
return Results.BadRequest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@
await kernelMemory.DeleteDocument(documentId);
return Results.Ok(new DocumentDeletedResult() { IsDeleted = true });
}
#pragma warning disable CA1031 // Must catch all to log and keep the process alive
catch (Exception ex)
{
app.Logger.LogError(ex, "An error occurred while deleting document {DocumentId}.", documentId);
Comment thread Fixed
return Results.BadRequest(new DocumentDeletedResult() { IsDeleted = false });
}
#pragma warning restore CA1031
})
.DisableAntiforgery();

Expand Down Expand Up @@ -197,7 +200,6 @@

if (status.RemainingSteps.Count == 0)
{
completeFlag = true;
break;
}
var totalSteps = status.Steps.Count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static void AddAPIs(WebApplication app)
var document = await documentRepository.FindByDocumentIdAsync(DocumentId);

//Check if the thumbnail is already in the cache
if (thumbnails.ContainsKey(document.MimeType))
if (thumbnails.TryGetValue(document.MimeType, out var thumbnail))
{
return Results.File(thumbnails[document.MimeType], "image/png");
return Results.File(thumbnail, "image/png");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public static void Inject(IHostApplicationBuilder builder)
.AddSingleton<Microsoft.GS.DPS.API.UserInterface.DataCacheManager>()
.AddSingleton<Microsoft.SemanticKernel.Kernel>(x =>
{
var aiService = x.GetRequiredService<IOptions<AIServices>>().Value;
return Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(deploymentName: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["ModelName"] ?? "",
endpoint: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["Endpoint"] ?? "",
Expand Down
9 changes: 4 additions & 5 deletions App/backend-api/Microsoft.GS.DPS/API/ChatHost/ChatHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static ChatHost()
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyDirectory = System.IO.Path.GetDirectoryName(assemblyLocation);
// binding assembly directory with file path (Prompts/Chat_SystemPrompt.txt)
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts/Chat_SystemPrompt.txt");
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts", "Chat_SystemPrompt.txt");
ChatHost.s_systemPrompt = System.IO.File.ReadAllText(systemPromptFilePath);
ChatHost.s_assistancePrompt =
@"
Expand All @@ -74,14 +74,13 @@ Please feel free to ask me any questions related to those documents and contents

private async Task<ChatSession> makeNewSession(string? chatSessionId)
{
var sessionId = string.Empty;
if(string.IsNullOrEmpty(chatSessionId))
{
sessionId = Guid.NewGuid().ToString();
this.sessionId = Guid.NewGuid().ToString();
}
else
{
sessionId = chatSessionId;
this.sessionId = chatSessionId;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static KernelMemory()
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyDirectory = System.IO.Path.GetDirectoryName(assemblyLocation);
// binding assembly directory with file path (Prompts/KeywordExtract_SystemPrompt.txt)
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts/KeywordExtract_SystemPrompt.txt");
var systemPromptFilePath = System.IO.Path.Combine(assemblyDirectory, "Prompts", "KeywordExtract_SystemPrompt.txt");
KernelMemory.keywordExtractorPrompt = System.IO.File.ReadAllText(systemPromptFilePath);
}

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

return keywordDict;
}
catch (Exception ex)
catch (Exception)
{
return new Dictionary<string, string>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task UpdateTags(string documentId, List<string> updatingTags)
try
{
var response = await _searchClient.MergeOrUploadDocumentsAsync(new[] { updateDocument });
Console.WriteLine($"Document with ID {document["id"]} updated successfully. - {response.GetRawResponse().ToString()}");
Console.WriteLine($"Document with ID {document["id"]} updated successfully. - {response.GetRawResponse()}");
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public async Task<IEnumerable<TEntity>> GetAllAsync()

public async Task<IEnumerable<TEntity>> GetAllAsync(IEnumerable<TIdentifier> identifiers)
{

List<TEntity> results = new List<TEntity>();
IMongoCollection<TEntity> collection = _database.GetCollection<TEntity>(typeof(TEntity).Name.ToLowerInvariant());
foreach (var i in identifiers)
{
results.Add(await this.GetAsync(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ async public Task<QueryResultSet> FindByDocumentIdsAsync(string[] documentIds,
//Just in case StartDate and EndDate is not null, define filter between StartDate and EndDate
//endDate should be converted from datetime to DateTime of end of day Day:23:59:59

FilterDefinition<Entities.Document> filter = Builders<Entities.Document>.Filter.Empty;

if (endDate.HasValue)
{
endDate = endDate?.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
filter = Builders<Entities.Document>.Filter.Gte(x => x.ImportedTime, startDate ?? DateTime.Now) &
Builders<Entities.Document>.Filter.Lte(x => x.ImportedTime, endDate ?? endDate);

var timeFilter = Builders<Entities.Document>.Filter.Gte(x => x.ImportedTime, startDate ?? DateTime.Now) &
Builders<Entities.Document>.Filter.Lte(x => x.ImportedTime, endDate.Value);
filterDefinition &= timeFilter;
}


Expand Down
4 changes: 1 addition & 3 deletions App/frontend-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { Suspense } from "react";
import { BrowserRouter } from "react-router-dom";
import { Layout } from "./components/layout/layout";
import { Telemetry } from "./utils/telemetry/telemetry";
import { AppInsightsContext, ReactPlugin } from "@microsoft/applicationinsights-react-js";
import { FluentProvider, makeStyles, webLightTheme } from "@fluentui/react-components";
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
import resolveConfig from "tailwindcss/resolveConfig";
import TailwindConfig from "../tailwind.config";
import AppRoutes from "./AppRoutes";
Expand Down
1 change: 0 additions & 1 deletion App/frontend-app/src/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode, createContext, useState } from 'react';
import { ChatApiResponse } from './api/apiTypes/chatTypes';
import { SearchFacet } from './types/searchRequest';

export interface IAppContext {
conversationAnswers: [prompt: string, response: ChatApiResponse, userTimestamp?: Date, answerTimestamp?: Date][];
Expand Down
2 changes: 0 additions & 2 deletions App/frontend-app/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Routes, Route } from "react-router-dom";
import { Home } from "./pages/home/home";
import { ChatPage } from "./pages/chat/chatPage";
// import { PersonalDocumentsPage } from "./pages/personalDocuments/personalDocumentsPage";
import { useState } from "react";
import { SearchFacet } from "./types/searchRequest";

function App() {

Expand Down
1 change: 0 additions & 1 deletion App/frontend-app/src/api/apiTypes/documentResults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Facets } from "../../types/facets";

export interface DocumentResults {
documents: Document[]
Expand Down
37 changes: 17 additions & 20 deletions App/frontend-app/src/api/documentsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SearchRequest } from "../types/searchRequest";
import { httpClient } from "../utils/httpClient/httpClient";
import { DocumentResults } from "./apiTypes/documentResults";
import { Embedded } from "./apiTypes/embedded";
import { SingleDocument } from "./apiTypes/singleDocument";



Expand Down Expand Up @@ -57,25 +56,23 @@ export const importDocuments = async (formData: FormData): Promise<any> => {
};




function formatKeywords(keywords: { [key: string]: string }): { [key: string]: string } {
// This function formats keywords into the desired comma-separated string for each category
const formattedKeywords: { [key: string]: string } = {};

Object.keys(keywords).forEach((category) => {
const keywordList = keywords[category];
if (Array.isArray(keywordList)) {
// If the keywords are in an array, join them into a comma-separated string
formattedKeywords[category] = keywordList.join(', ');
} else {
// If already a string (or incorrect format), preserve it
formattedKeywords[category] = keywordList;
}
});

return formattedKeywords;
}
// function formatKeywords(keywords: { [key: string]: string }): { [key: string]: string } {
// // This function formats keywords into the desired comma-separated string for each category
// const formattedKeywords: { [key: string]: string } = {};

// Object.keys(keywords).forEach((category) => {
// const keywordList = keywords[category];
// if (Array.isArray(keywordList)) {
// // If the keywords are in an array, join them into a comma-separated string
// formattedKeywords[category] = keywordList.join(', ');
// } else {
// // If already a string (or incorrect format), preserve it
// formattedKeywords[category] = keywordList;
// }
// });

// return formattedKeywords;
// }

// Update in your documentsService file
export const downloadDocument = async (documentId: string, fileName: string): Promise<Blob> => {
Expand Down
2 changes: 1 addition & 1 deletion App/frontend-app/src/components/chat/FeedbackForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@fluentui/react-components";
import { AddCircle24Regular, Dismiss24Regular, SubtractCircle24Regular } from "@fluentui/react-icons";
import { useState } from "react";
import { ChatMessage, History, Reference } from "../../api/apiTypes/chatTypes";
import { History, Reference } from "../../api/apiTypes/chatTypes";
import { ChatOptions } from "../../api/apiTypes/chatTypes";
import { PostFeedback } from "../../api/chatService";
import { useTranslation } from "react-i18next";
Expand Down
Loading
Loading