Skip to content

Commit e291580

Browse files
Merge pull request #194 from microsoft/dev
fix: Merging Dev fixes to main branch
2 parents 10447a2 + ff247d9 commit e291580

File tree

5 files changed

+104
-19
lines changed

5 files changed

+104
-19
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ DPS.API.KernelMemory kernelMemory
4949
Summary = $"{fileExtension} file is Unsupported file type" });
5050
}
5151

52+
// Checking File Size: O byte/kb file not allowed
53+
if (file == null || file.Length == 0)
54+
{
55+
return Results.BadRequest(new DocumentImportedResult()
56+
{
57+
DocumentId = string.Empty,
58+
MimeType = contentType,
59+
Summary = "The file is empty and cannot be uploaded. Please select a valid file."
60+
});
61+
}
62+
5263
var result = await kernelMemory.ImportDocument(fileStream, file.FileName, contentType);
5364

5465
//Return HTTP 202 with Location Header

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

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,41 @@ public async Task<ChatResponse> Chat(ChatRequest chatRequest)
191191
}
192192
};
193193

194-
//Get Response from ChatCompletionService
195-
ChatMessageContent returnedChatMessageContent = await _chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings);
194+
ChatMessageContent returnedChatMessageContent;
195+
try
196+
{
196197

198+
//Get Response from ChatCompletionService
199+
returnedChatMessageContent = await _chatCompletionService.GetChatMessageContentAsync(chatHistory, executionSettings);
200+
}
201+
catch (HttpOperationException ex) when (ex.Message.Contains("content_filter", StringComparison.OrdinalIgnoreCase))
202+
{
203+
204+
Console.WriteLine($"Exception Message: {ex.Message}");
205+
206+
//if content filter triggered providing fallback response
207+
returnedChatMessageContent = new ChatMessageContent
208+
{
209+
Content = "Sorry, your request couldn't be processed as it may contain sensitive or restricted content. Please rephrase your query and try again."
210+
};
211+
}
212+
catch(Exception ex)
213+
{
214+
Console.WriteLine($"unexpected error: {ex.Message}");
215+
216+
returnedChatMessageContent = new ChatMessageContent
217+
{
218+
Content = "An error occured while processing request, try again"
219+
};
220+
221+
}
222+
if (returnedChatMessageContent == null)
223+
{
224+
returnedChatMessageContent = new ChatMessageContent
225+
{
226+
Content = "No response"
227+
};
228+
}
197229
//Just in case returnedChatMessageContent.Content has ```json ``` block, Strip it first
198230
if (returnedChatMessageContent.Content != null && returnedChatMessageContent.Content.Contains("```json", StringComparison.OrdinalIgnoreCase))
199231
returnedChatMessageContent.Content = returnedChatMessageContent.Content.Replace("```json", "").Replace("```", "");
@@ -202,13 +234,21 @@ public async Task<ChatResponse> Chat(ChatRequest chatRequest)
202234

203235
try
204236
{
205-
//Adding for non English Response.
206-
returnedChatMessageContent.Content = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(returnedChatMessageContent.Content));
207-
answerObject = JsonSerializer.Deserialize<Answer>(returnedChatMessageContent.Content, options: new JsonSerializerOptions
237+
if (returnedChatMessageContent != null && !string.IsNullOrWhiteSpace(returnedChatMessageContent.Content))
208238
{
209-
PropertyNameCaseInsensitive = true,
210-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
211-
});
239+
240+
//Adding for non English Response.
241+
returnedChatMessageContent.Content = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(returnedChatMessageContent.Content));
242+
answerObject = JsonSerializer.Deserialize<Answer>(returnedChatMessageContent.Content, options: new JsonSerializerOptions
243+
{
244+
PropertyNameCaseInsensitive = true,
245+
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
246+
});
247+
}
248+
else
249+
{
250+
throw new NullReferenceException("returnedChatMessageContent or its Content is null.");
251+
}
212252
}
213253
catch
214254
{

App/frontend-app/src/components/chat/chatRoom.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ export function ChatRoom({ searchResultDocuments, selectedDocuments, chatWithDoc
289289
};
290290

291291
function handleSend(ev: TextareaSubmitEvents, data: TextareaValueData) {
292-
makeApiRequest(data.value);
292+
if (data.value.trim() !='') {
293+
makeApiRequest(data.value);
294+
}
293295
}
294296

295297
// const handleOpenReference = async (referenceId: string, chunkTexts: string[]) => {

App/frontend-app/src/components/uploadButton/uploadButton.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getFileTypeIconProps } from "@fluentui/react-file-type-icons";
2424
const UploadDocumentsDialog = () => {
2525
const [isOpen, setIsOpen] = useState(false);
2626
const [uploadingFiles, setUploadingFiles] = useState<
27-
{ name: string; progress: number; status: string }[]
27+
{ name: string; progress: number; status: string; errorMsg:string }[]
2828
>([]);
2929
const [isUploading, setIsUploading] = useState(false);
3030

@@ -35,6 +35,7 @@ const UploadDocumentsDialog = () => {
3535
name: file.name,
3636
progress: 0,
3737
status: "uploading",
38+
errorMsg : ""
3839
}));
3940
setUploadingFiles((prev) => [...prev, ...newFiles]);
4041

@@ -52,18 +53,19 @@ const UploadDocumentsDialog = () => {
5253
setUploadingFiles((prev) =>
5354
prev.map((f, index) =>
5455
index === prev.length - acceptedFiles.length + i
55-
? { ...f, progress: 100, status: "success" }
56+
? { ...f, progress: 100, status: "success", errorMsg: "" }
5657
: f
5758
)
5859
);
59-
} catch (error) {
60-
console.error("Error uploading file:", error);
60+
} catch (error:any) {
61+
const errorMessage = error.message.replace(/^Error:\s*/, ""); // Remove "Error: " prefix
62+
const parsedError = JSON.parse(errorMessage);
6163

6264
// Update file status to error
6365
setUploadingFiles((prev) =>
6466
prev.map((f, index) =>
6567
index === prev.length - acceptedFiles.length + i
66-
? { ...f, progress: 100, status: "error" }
68+
? { ...f, progress: 100, status: "error", errorMsg: parsedError.summary}
6769
: f
6870
)
6971
);
@@ -188,13 +190,17 @@ const UploadDocumentsDialog = () => {
188190
)}
189191
</div>
190192
<ProgressBar value={file.progress} />
191-
<span>
193+
<span
194+
style={{
195+
color: file.status === "error" ? "red" : "inherit", // Apply red color only for error messages
196+
}}>
192197
{file.status === "uploading"
193198
? "Uploading..."
194199
: file.status === "success"
195200
? "Upload complete"
196-
: "Upload failed"}
201+
: file.errorMsg}
197202
</span>
203+
<span>{}</span>
198204
</div>
199205
))}
200206
</DialogContent>

Deployment/resourcedeployment.ps1

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,18 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
176176
if ($LASTEXITCODE -ne 0) {
177177
Write-Host "There might be something wrong with your deployment." -ForegroundColor Red
178178
Write-Host $whatIfResult -ForegroundColor Red
179+
failureBanner
179180
exit 1
180181
}
181182
# Proceed with the actual deployment
182183
Write-Host "Proceeding with Deployment..." -ForegroundColor Yellow
183184
$deploymentResult = az deployment sub create --template-file .\main.bicep --location $location --name $deploymentName --parameters modeldatacenter=$modelLocation
184-
185+
# Check if deploymentResult is valid
186+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult -variableName "Deployment Result"
185187
if ($LASTEXITCODE -ne 0) {
186188
Write-Host "Deployment failed. Stopping execution." -ForegroundColor Red
187189
Write-Host $deploymentResult -ForegroundColor Red
190+
failureBanner
188191
exit 1
189192
}
190193

@@ -197,6 +200,7 @@ function DeployAzureResources([string]$location, [string]$modelLocation) {
197200
Write-Host $_.Exception.Message -ForegroundColor Red
198201
Write-Host $_.InvocationInfo.PositionMessage -ForegroundColor Red
199202
Write-Host $_.ScriptStackTrace -ForegroundColor Red
203+
failureBanner
200204
exit 1
201205
}
202206
}
@@ -410,6 +414,7 @@ function Check-Docker {
410414
# Check if Docker is running before proceeding
411415
if (-not (Check-Docker)) {
412416
Write-Host "Docker is not running. Please start Docker and try again." -ForegroundColor Red
417+
failureBanner
413418
exit 1
414419
}
415420

@@ -439,6 +444,9 @@ try {
439444
# Step 2 : Get Secrets from Azure resources
440445
Show-Banner -Title "Step 2 : Get Secrets from Azure resources"
441446
###############################################################
447+
# Validate if the Storage Account Name is empty or null
448+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.StorageAccountName -variableName "Storage Account Name"
449+
442450
# Get the storage account key
443451
$storageAccountKey = az storage account keys list --account-name $deploymentResult.StorageAccountName --resource-group $deploymentResult.ResourceGroupName --query "[0].value" -o tsv
444452

@@ -596,6 +604,7 @@ try {
596604

597605
if ($retryCount -eq $maxRetries) {
598606
Write-Host "Max retries reached. Failed to update the AKS cluster." -ForegroundColor Red
607+
failureBanner
599608
exit 1
600609
}
601610

@@ -615,6 +624,7 @@ try {
615624
Write-Host "Error details:" -ForegroundColor Red
616625
Write-Host $_.Exception.Message -ForegroundColor Red
617626
Write-Host $_.Exception.StackTrace -ForegroundColor Red
627+
failureBanner
618628
exit 1
619629
}
620630

@@ -630,6 +640,7 @@ try {
630640
Write-Host "Error details:" -ForegroundColor Red
631641
Write-Host $_.Exception.Message -ForegroundColor Red
632642
Write-Host $_.Exception.StackTrace -ForegroundColor Red
643+
failureBanner
633644
exit 1
634645
}
635646

@@ -650,6 +661,7 @@ try {
650661
Write-Host "Error details:" -ForegroundColor Red
651662
Write-Host $_.Exception.Message -ForegroundColor Red
652663
Write-Host $_.Exception.StackTrace -ForegroundColor Red
664+
failureBanner
653665
exit 1
654666
}
655667

@@ -716,6 +728,9 @@ try {
716728
# Validate if System Assigned Identity is null or empty
717729
ValidateVariableIsNullOrEmpty -variableValue $systemAssignedIdentity -variableName "System-assigned managed identity"
718730

731+
# Validate if ResourceGroupId is null or empty
732+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.ResourceGroupId -variableName "ResourceGroupId"
733+
719734
# Assign the role for aks system assigned managed identity to App Configuration Data Reader role with the scope of Resourcegroup
720735
az role assignment create --assignee $systemAssignedIdentity --role "App Configuration Data Reader" --scope $deploymentResult.ResourceGroupId
721736

@@ -743,6 +758,7 @@ try {
743758
Write-Host "Error details:" -ForegroundColor Red
744759
Write-Host $_.Exception.Message -ForegroundColor Red
745760
Write-Host $_.Exception.StackTrace -ForegroundColor Red
761+
failureBanner
746762
exit 1
747763
}
748764

@@ -772,12 +788,21 @@ try {
772788

773789

774790
# 5.3 Update deploy.deployment.yaml.template file and save as deploy.deployment.yaml
791+
# Validate AzContainerRegistryName IsNull Or Empty.
792+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.AzContainerRegistryName -variableName "Azure Container Registry Name"
793+
775794
## Define Image Tags
776795
$acrNamespace = "kmgs"
777796
$acrAIServiceTag = "$($deploymentResult.AzContainerRegistryName).azurecr.io/$acrNamespace/aiservice"
778797
$acrKernelMemoryTag = "$($deploymentResult.AzContainerRegistryName).azurecr.io/$acrNamespace/kernelmemory"
779798
$acrFrontAppTag = "$($deploymentResult.AzContainerRegistryName).azurecr.io/$acrNamespace/frontapp"
780-
799+
800+
# Validate AI Service Tag IsNull Or Empty.
801+
ValidateVariableIsNullOrEmpty -variableValue $acrAIServiceTag -variableName "AI Service Tag"
802+
# Validate Kernel Memory Tag IsNull Or Empty.
803+
ValidateVariableIsNullOrEmpty -variableValue $acrKernelMemoryTag -variableName "Kernel Memory Tag"
804+
# Validate Front App Tag IsNull Or Empty.
805+
ValidateVariableIsNullOrEmpty -variableValue $acrFrontAppTag -variableName "Front App Tag"
781806

782807
$deploymentTemplatePlaceholders = @{
783808
'{{ aiservice-imagepath }}' = $acrAIServiceTag
@@ -821,8 +846,9 @@ try {
821846

822847

823848
#======================================================================================================================================================================
849+
# Validate AzAppConfigEndpoint IsNull Or Empty.
850+
ValidateVariableIsNullOrEmpty -variableValue $deploymentResult.AzAppConfigEndpoint -variableName "Azure App Configuration Endpoint"
824851
# App Deployment after finishing the AKS infrastructure setup
825-
826852
$appConfigServicePlaceholders = @{
827853
'{{ appconfig-url }}' = $deploymentResult.AzAppConfigEndpoint
828854
}

0 commit comments

Comments
 (0)