Skip to content

Commit

Permalink
Merge branch 'vNext-Dev' into nhwkuhns/295-auto-delete-funct-take2
Browse files Browse the repository at this point in the history
  • Loading branch information
dayland authored Jan 5, 2024
2 parents ce03fa8 + 6011ebf commit 8bd1c55
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> [!IMPORTANT]
> As of November 15, 2023, Azure Cognitive Search has been renamed to Azure AI Search. Azure Cognitive Services have also been renamed to Azure AI Services.
## Table of Contents
## Table of Contents

- [Features](#features)
- [Azure account requirements](#azure-account-requirements)
Expand Down
24 changes: 24 additions & 0 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"AZURE_BLOB_STORAGE_ENDPOINT": None,
"AZURE_BLOB_STORAGE_KEY": None,
"AZURE_BLOB_STORAGE_CONTAINER": "content",
"AZURE_BLOB_STORAGE_UPLOAD_CONTAINER": "upload",
"AZURE_SEARCH_SERVICE": "gptkb",
"AZURE_SEARCH_SERVICE_ENDPOINT": None,
"AZURE_SEARCH_SERVICE_KEY": None,
Expand Down Expand Up @@ -394,6 +395,29 @@ async def get_all_tags():
raise HTTPException(status_code=500, detail=str(ex))
return results

@app.post("/retryFile")
async def retryFile(request: Request):

json_body = await request.json()
filePath = json_body.get("filePath")

try:

file_path_parsed = filePath.replace(ENV["AZURE_BLOB_STORAGE_UPLOAD_CONTAINER"] + "/", "")
blob = blob_client.get_blob_client(ENV["AZURE_BLOB_STORAGE_UPLOAD_CONTAINER"], file_path_parsed)

if blob.exists():
raw_file = blob.download_blob().readall()

# Overwrite the existing blob with new data
blob.upload_blob(raw_file, overwrite=True)

except Exception as ex:
logging.exception("Exception in /retryFile")
raise HTTPException(status_code=500, detail=str(ex))
return {"status": 200}


app.mount("/", StaticFiles(directory="static"), name="static")

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion app/backend/approaches/chatreadretrieveread.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def run(self, history: Sequence[dict[str, str]], overrides: dict[str, Any]
'Accept': 'application/json',
'Content-Type': 'application/json',
}

response = requests.post(url, json=data,headers=headers,timeout=60)
if response.status_code == 200:
response_data = response.json()
Expand Down
2 changes: 1 addition & 1 deletion app/enrichment/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def poll_queue() -> None:
queue_client.send_message(message_string, visibility_timeout=backoff)
statusLog.upsert_document(blob_path, f'Message requeued to embeddings queue, attempt {str(requeue_count)}. Visible in {str(backoff)} seconds. Error: {str(error)}.',
StatusClassification.ERROR,
State.QUEUED)
State.QUEUED, additional_info={"Queue_Item": message_string })
else:
# max retries has been reached
statusLog.upsert_document(
Expand Down
19 changes: 19 additions & 0 deletions app/frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ export async function getAllUploadStatus(options: GetUploadStatusRequest): Promi
return results;
}

export async function retryFile(filePath: string): Promise<boolean> {
const response = await fetch("/retryFile", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
filePath: filePath
})
});

const parsedResponse: String = await response.json();
if (response.status > 299 || !response.ok) {
throw Error("Unknown error");
}

return true;
}

export async function logStatus(status_log_entry: StatusLogEntry): Promise<StatusLogResponse> {
var response = await fetch("/logstatus", {
method: "POST",
Expand Down
51 changes: 43 additions & 8 deletions app/frontend/src/components/FileStatus/DocumentsDetailList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Licensed under the MIT license.

import { useState } from "react";
import { DetailsList, DetailsListLayoutMode, SelectionMode, IColumn, Selection, Label, BaseSelectedItemsList } from "@fluentui/react";
import { DetailsList, DetailsListLayoutMode, SelectionMode, IColumn, Selection, Label, Text, BaseSelectedItemsList } from "@fluentui/react";
import { TooltipHost } from '@fluentui/react';
import { retryFile } from "../../api";
import React, { useRef } from "react";

import styles from "./DocumentsDetailList.module.css";

Expand All @@ -13,6 +15,7 @@ export interface IDocument {
value: string;
iconName: string;
fileType: string;
filePath: string;
state: string;
state_description: string;
upload_timestamp: string;
Expand All @@ -25,6 +28,7 @@ interface Props {
}

export const DocumentsDetailList = ({ items, onFilesSorted}: Props) => {
const itemsRef = useRef(items);

const onColumnClick = (ev: React.MouseEvent<HTMLElement>, column: IColumn): void => {
const newColumns: IColumn[] = columns.slice();
Expand Down Expand Up @@ -57,6 +61,30 @@ export const DocumentsDetailList = ({ items, onFilesSorted}: Props) => {
alert(`Item invoked: ${item.name}`);
}

const [itemList, setItems] = useState<IDocument[]>(items);
function retryErroredFile(item: IDocument): void {
retryFile(item.filePath)
.then(() => {
// Create a new array with the updated item
const updatedItems = itemList.map((i) => {
if (i.key === item.key) {
return {
...i,
state: "Queued"
};
}
return i;
});

setItems(updatedItems); // Update the state with the new array
console.log("State updated, triggering re-render");
})
.catch((error) => {
console.error("Error retrying file:", error);
});
}


const [columns, setColumns] = useState<IColumn[]> ([
{
key: 'column1',
Expand Down Expand Up @@ -100,11 +128,12 @@ export const DocumentsDetailList = ({ items, onFilesSorted}: Props) => {
ariaLabel: 'Column operations for state, Press to sort by states',
onColumnClick: onColumnClick,
data: 'string',
// onRender: (item: IDocument) => (
// <TooltipHost content={`${item.state_description} `}>
// <span>{item.state}</span>
// </TooltipHost>
// ),
onRender: (item: IDocument) => (
<TooltipHost content={`${item.state} `}>
<span>{item.state}</span>
{item.state === 'Error' && <a href="javascript:void(0);" onClick={() => retryErroredFile(item)}> Retry File</a>}
</TooltipHost>
),
isPadded: true,
},
{
Expand Down Expand Up @@ -152,15 +181,21 @@ export const DocumentsDetailList = ({ items, onFilesSorted}: Props) => {
isCollapsible: true,
ariaLabel: 'Column operations for status detail',
data: 'string',
onColumnClick: onColumnClick
onColumnClick: onColumnClick,
onRender: (item: IDocument) => (
<TooltipHost content={`${item.state_description} `}>
<span>{item.state}</span>
</TooltipHost>
),
}
]);

return (
<div>
<span className={styles.footer}>{"(" + items.length as string + ") records."}</span>
<DetailsList
items={items}
// items={items}
items={itemList}
compact={true}
columns={columns}
selectionMode={SelectionMode.none}
Expand Down
1 change: 1 addition & 0 deletions app/frontend/src/components/FileStatus/FileStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const FileStatus = ({ className }: Props) => {
name: fileList[i].file_name,
iconName: FILE_ICONS[fileExtension.toLowerCase()],
fileType: fileExtension,
filePath: fileList[i].file_path,
state: fileList[i].state,
state_description: fileList[i].state_description,
upload_timestamp: fileList[i].start_timestamp,
Expand Down
1 change: 1 addition & 0 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ output BACKEND_URI string = backend.outputs.uri
output BACKEND_NAME string = backend.outputs.name
output RESOURCE_GROUP_NAME string = rg.name
output AZURE_OPENAI_CHAT_GPT_DEPLOYMENT string = !empty(chatGptDeploymentName) ? chatGptDeploymentName : !empty(chatGptModelName) ? chatGptModelName : 'gpt-35-turbo-16k'
output AZURE_OPENAI_CHATGPT_MODEL_NAME string = chatGptModelName
output AZURE_OPENAI_RESOURCE_GROUP string = azureOpenAIResourceGroup
output AZURE_FUNCTION_APP_NAME string = functions.outputs.name
output AZURE_COSMOSDB_URL string = cosmosdb.outputs.CosmosDBEndpointURL
Expand Down
4 changes: 4 additions & 0 deletions scripts/json-to-env.webapp.debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ jq -r '
{
"path": "deploymenT_KEYVAULT_NAME",
"env_var": "DEPLOYMENT_KEYVAULT_NAME"
},
{
"path": "azurE_OPENAI_CHATGPT_MODEL_NAME",
"env_var": "AZURE_OPENAI_CHATGPT_MODEL_NAME"
}
]
as $env_vars_to_extract
Expand Down

0 comments on commit 8bd1c55

Please sign in to comment.