Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 3 additions & 6 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,6 @@ var dnsZoneIndex = {
sqlServer: 9
search: 10
}
// List of DNS zone indices that correspond to AI-related services.
var aiRelatedDnsZoneIndices = [
dnsZoneIndex.cognitiveServices
dnsZoneIndex.openAI
dnsZoneIndex.aiServices
]

// ===================================================
// DEPLOY PRIVATE DNS ZONES
Expand Down Expand Up @@ -1575,6 +1569,9 @@ module webSiteBackend 'modules/web-sites.bicep' = {
SOLUTION_NAME: solutionSuffix
APP_ENV: 'Prod'
AZURE_CLIENT_ID: backendUserAssignedIdentity.outputs.clientId
AZURE_BASIC_LOGGING_LEVEL: 'INFO'
AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING'
AZURE_LOGGING_PACKAGES: ''
}
// WAF aligned configuration for Monitoring
applicationInsightResourceId: enableMonitoring ? applicationInsights!.outputs.resourceId : null
Expand Down
154 changes: 76 additions & 78 deletions infra/main.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions infra/scripts/run_process_data_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo "Fetching Key Vault and Managed Identity from resource group: $resourceGrou
keyVaultName=$(az keyvault list --resource-group "$resourceGroupName" --query "[0].name" -o tsv)

# === Retrieve the ID of the first user-assigned identity with name starting with 'id-' ===
managedIdentityResourceId=$(az identity list --resource-group "$resourceGroupName" --query "[?starts_with(name, 'id-') && !starts_with(name, 'id-sql-')].id | [0]" -o tsv)
managedIdentityResourceId=$(az identity list --resource-group "$resourceGroupName" --query "[?starts_with(name, 'id-') && !starts_with(name, 'id-backend-')].id | [0]" -o tsv)

# === Normalize managedIdentityResourceId (necessary for compatibility in Git Bash on Windows) ===
managedIdentityResourceId=$(echo "$managedIdentityResourceId" | sed -E 's|.*(/subscriptions/)|\1|')
Expand All @@ -34,7 +34,7 @@ managedIdentityResourceId=$(echo "$managedIdentityResourceId" | sed -E 's|.*(/su
sqlServerLocation=$(az sql server list --resource-group "$resourceGroupName" --query "[0].location" -o tsv)

# === Retrieve the principal ID of the first user-assigned identity with name starting with 'id-' ===
managedIdentityClientId=$(az identity list --resource-group "$resourceGroupName" --query "[?starts_with(name, 'id-') && !starts_with(name, 'id-sql-')].clientId | [0]" -o tsv)
managedIdentityClientId=$(az identity list --resource-group "$resourceGroupName" --query "[?starts_with(name, 'id-') && !starts_with(name, 'id-backend-')].clientId | [0]" -o tsv)

# === Check for VNet deployment ===
echo "Checking for VNet deployment in resource group: $resourceGroupName"
Expand Down
20 changes: 1 addition & 19 deletions src/App/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,6 @@ const Dashboard: React.FC = () => {

const [ASSISTANT, TOOL, ERROR, USER] = ["assistant", "tool", "error", "user"];

const getLastRagResponse = (messages: ChatMessage[]) => {
const lastAssistantObj = [...messages]
.reverse()
.find((obj) => obj.role === ASSISTANT && typeof obj.content === "string");
if (typeof lastAssistantObj?.content === "string") {
return lastAssistantObj.content.trim();
}
return null;
};

const onSelectConversation = async (id: string) => {
if (!id) {
console.error("No conversation ID found");
Expand All @@ -257,10 +247,6 @@ const Dashboard: React.FC = () => {
type: actionConstants.UPDATE_SELECTED_CONV_ID,
payload: id,
});
dispatch({
type: actionConstants.SET_LAST_RAG_RESPONSE,
payload: null,
});
try {
const responseMessages = await historyRead(id);

Expand All @@ -273,11 +259,7 @@ const Dashboard: React.FC = () => {
},
});
}
const lastRagResponse = getLastRagResponse(responseMessages);
dispatch({
type: actionConstants.SET_LAST_RAG_RESPONSE,
payload: lastRagResponse,
});

} catch (error) {
console.error("Error fetching conversation messages:", error);
} finally {
Expand Down
41 changes: 2 additions & 39 deletions src/App/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,8 @@ export async function callConversationApi(
"X-Ms-Client-Principal-Id": userId || "",
},
body: JSON.stringify({
messages: options.messages,
conversation_id: options.id,
last_rag_response: options.last_rag_response
query: options.query,
conversation_id: options.id
}),
signal: abortSignal,
});
Expand Down Expand Up @@ -432,42 +431,6 @@ export const historyEnsure = async (): Promise<CosmosDBHealth> => {
return response;
};

export const historyGenerate = async (
options: ConversationRequest,
abortSignal: AbortSignal,
convId?: string
): Promise<Response> => {
let body;
if (convId) {
body = JSON.stringify({
conversation_id: convId,
messages: options.messages,
});
} else {
body = JSON.stringify({
messages: options.messages,
});
}
const userId = getUserIdFromLocalStorage();
const response = await fetch(`${baseURL}/history/generate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Ms-Client-Principal-Id": userId || "",
},
body: body,
signal: abortSignal,
})
.then((res) => {
return res;
})
.catch((_err) => {
console.error("There was an issue fetching your data.");
return new Response();
});
return response;
};

export const fetchCitationContent = async (body: any) => {
try {
const response = await fetch(`${baseURL}/api/fetch-azure-search-content`, {
Expand Down
85 changes: 20 additions & 65 deletions src/App/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const Chat: React.FC<ChatProps> = ({
}
}, []);

const saveToDB = async (messages: ChatMessage[], convId: string, reqType: string = 'Text') => {
if (!convId || !messages.length) {
const saveToDB = async (newMessages: ChatMessage[], convId: string, reqType: string = 'Text') => {
if (!convId || !newMessages.length) {
return;
}
const isNewConversation = reqType !== 'graph' ? !state.selectedConversationId : false;
Expand All @@ -73,14 +73,14 @@ const Chat: React.FC<ChatProps> = ({
payload: true,
});

if (((reqType !== 'graph' && reqType !== 'error') && messages[messages.length - 1].role !== ERROR) && isCharthDisplayDefault ){
if (((reqType !== 'graph' && reqType !== 'error') && newMessages[newMessages.length - 1].role !== ERROR) && isCharthDisplayDefault ){
setIsChartLoading(true);
setTimeout(()=>{
makeApiRequestForChart('show in a graph by default', convId, messages[messages.length - 1].content as string)
makeApiRequestForChart('show in a graph by default', convId, newMessages[newMessages.length - 1].content as string)
},5000)

}
await historyUpdate(messages, convId)
await historyUpdate(newMessages, convId)
.then(async (res) => {
if (!res.ok) {
if (!messages) {
Expand All @@ -96,7 +96,7 @@ const Chat: React.FC<ChatProps> = ({
const newConversation: Conversation = {
id: responseJson?.data?.conversation_id,
title: responseJson?.data?.title,
messages: messages,
messages: state.chat.messages,
date: responseJson?.data?.date,
updatedAt: responseJson?.data?.date,
};
Expand Down Expand Up @@ -218,10 +218,7 @@ const Chat: React.FC<ChatProps> = ({

const request: ConversationRequest = {
id: conversationId,
messages: [...state.chat.messages, newMessage].filter(
(messageObj) => messageObj.role !== ERROR
),
last_rag_response: lrg
query: question
};

const streamMessage: ChatMessage = {
Expand Down Expand Up @@ -271,7 +268,7 @@ const Chat: React.FC<ChatProps> = ({
content: errorMsg,
date: new Date().toISOString(),
};
updatedMessages = [...state.chat.messages, newMessage, errorMessage];
updatedMessages = [newMessage, errorMessage];
dispatch({
type: actionConstants.UPDATE_MESSAGES,
payload: [errorMessage],
Expand All @@ -294,11 +291,7 @@ const Chat: React.FC<ChatProps> = ({
parsedChartResponse.object as unknown as ChartDataResponse,
date: new Date().toISOString(),
};
updatedMessages = [
...state.chat.messages,
newMessage,
chartMessage,
];
updatedMessages = [newMessage, chartMessage];
// Update messages with the response content
dispatch({
type: actionConstants.UPDATE_MESSAGES,
Expand All @@ -313,11 +306,7 @@ const Chat: React.FC<ChatProps> = ({
content: "Error while generating Chart.",
date: new Date().toISOString(),
};
updatedMessages = [
...state.chat.messages,
newMessage,
chartMessage,
];
updatedMessages = [newMessage, chartMessage];
dispatch({
type: actionConstants.UPDATE_MESSAGES,
payload: [chartMessage],
Expand Down Expand Up @@ -357,13 +346,9 @@ const Chat: React.FC<ChatProps> = ({
console.log("Caught with an error while chat and save", e);
if (abortController.signal.aborted) {
if (streamMessage.content) {
updatedMessages = [
...state.chat.messages,
newMessage,
...[streamMessage],
];
updatedMessages = [newMessage, streamMessage];
} else {
updatedMessages = [...state.chat.messages, newMessage];
updatedMessages = [newMessage];
}
console.log(
"@@@ Abort Signal detected: Formed updated msgs",
Expand Down Expand Up @@ -429,13 +414,7 @@ const Chat: React.FC<ChatProps> = ({

const request: ConversationRequest = {
id: conversationId,
messages: [...state.chat.messages, newMessage].filter(
(messageObj) => messageObj.role !== ERROR
),
last_rag_response:
isChartQuery(userMessage) && state.chat.lastRagResponse
? JSON.stringify(state.chat.lastRagResponse)
: null,
query: question
};

const streamMessage: ChatMessage = {
Expand Down Expand Up @@ -550,7 +529,7 @@ const Chat: React.FC<ChatProps> = ({
content: errorMsg,
date: new Date().toISOString(),
};
updatedMessages = [...state.chat.messages, newMessage, errorMessage];
updatedMessages = [newMessage, errorMessage];
dispatch({
type: actionConstants.UPDATE_MESSAGES,
payload: [errorMessage],
Expand Down Expand Up @@ -593,11 +572,7 @@ const Chat: React.FC<ChatProps> = ({
chartResponse as unknown as ChartDataResponse,
date: new Date().toISOString(),
};
updatedMessages = [
...state.chat.messages,
newMessage,
chartMessage,
];
updatedMessages = [newMessage, chartMessage];
// Update messages with the response content
dispatch({
type: actionConstants.UPDATE_MESSAGES,
Expand All @@ -612,11 +587,7 @@ const Chat: React.FC<ChatProps> = ({
content: "Error while generating Chart.",
date: new Date().toISOString(),
};
updatedMessages = [
...state.chat.messages,
newMessage,
chartMessage,
];
updatedMessages = [newMessage, chartMessage];
dispatch({
type: actionConstants.UPDATE_MESSAGES,
payload: [chartMessage],
Expand Down Expand Up @@ -646,11 +617,7 @@ const Chat: React.FC<ChatProps> = ({
content: errorMsg,
date: new Date().toISOString(),
};
updatedMessages = [
...state.chat.messages,
newMessage,
errorMessage,
];
updatedMessages = [newMessage, errorMessage];
dispatch({
type: actionConstants.UPDATE_MESSAGES,
payload: [errorMessage],
Expand All @@ -661,15 +628,7 @@ const Chat: React.FC<ChatProps> = ({
console.log("Error while parsing charts response", e);
}
} else if (!isChartResponseReceived) {
dispatch({
type: actionConstants.SET_LAST_RAG_RESPONSE,
payload: streamMessage?.content as string,
});
updatedMessages = [
...state.chat.messages,
newMessage,
...[streamMessage],
];
updatedMessages = [newMessage, streamMessage];
}
}
if (updatedMessages[updatedMessages.length-1]?.role !== "error") {
Expand All @@ -679,13 +638,9 @@ const Chat: React.FC<ChatProps> = ({
console.log("Caught with an error while chat and save", e);
if (abortController.signal.aborted) {
if (streamMessage.content) {
updatedMessages = [
...state.chat.messages,
newMessage,
...[streamMessage],
];
updatedMessages = [newMessage, streamMessage];
} else {
updatedMessages = [...state.chat.messages, newMessage];
updatedMessages = [newMessage];
}
console.log(
"@@@ Abort Signal detected: Formed updated msgs",
Expand Down
1 change: 0 additions & 1 deletion src/App/src/state/ActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const actionConstants = {
ADD_NEW_CONVERSATION_TO_CHAT_HISTORY: "ADD_NEW_CONVERSATION_TO_CHAT_HISTORY",
UPDATE_APP_SPINNER_STATUS: "UPDATE_APP_SPINNER_STATUS",
UPDATE_HISTORY_UPDATE_API_FLAG: "UPDATE_HISTORY_UPDATE_API_FLAG",
SET_LAST_RAG_RESPONSE: "SET_LAST_RAG_RESPONSE",
UPDATE_MESSAGE_BY_ID: "UPDATE_MESSAGE_BY_ID",
UPDATE_STREAMING_FLAG: "UPDATE_STREAMING_FLAG",
UPDATE_CHARTS_FETCHING_FLAG: "UPDATE_CHARTS_FETCHING_FLAG",
Expand Down
6 changes: 0 additions & 6 deletions src/App/src/state/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type AppState = {
generatingResponse: boolean;
messages: ChatMessage[];
userMessage: string;
lastRagResponse: string | null;
isStreamingInProgress: boolean;
citations: string |null;
};
Expand Down Expand Up @@ -71,7 +70,6 @@ const initialState: AppState = {
generatingResponse: false,
messages: [],
userMessage: "",
lastRagResponse: null,
citations: "",
isStreamingInProgress: false,
},
Expand Down Expand Up @@ -187,10 +185,6 @@ export type Action =
type: typeof actionConstants.UPDATE_HISTORY_UPDATE_API_FLAG;
payload: boolean;
}
| {
type: typeof actionConstants.SET_LAST_RAG_RESPONSE;
payload: string | null;
}
| {
type: typeof actionConstants.UPDATE_MESSAGE_BY_ID;
payload: ChatMessage;
Expand Down
10 changes: 1 addition & 9 deletions src/App/src/state/AppReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const appReducer = (state: AppState, action: Action): AppState => {
case actionConstants.NEW_CONVERSATION_START:
return {
...state,
chat: { ...state.chat, messages: [], lastRagResponse: null },
chat: { ...state.chat, messages: [] },
selectedConversationId: "",
generatedConversationId: generateUUIDv4(),
};
Expand Down Expand Up @@ -199,14 +199,6 @@ const appReducer = (state: AppState, action: Action): AppState => {
isHistoryUpdateAPIPending: action.payload,
},
};
case actionConstants.SET_LAST_RAG_RESPONSE:
return {
...state,
chat: {
...state.chat,
lastRagResponse: action.payload,
},
};
case actionConstants.UPDATE_MESSAGE_BY_ID:
const messageID = action.payload.id;
// console.log("aaction::",action.payload)
Expand Down
Loading
Loading