Skip to content

Commit

Permalink
Merge branch 'vNext-Dev' into joshuakr/7365-Fix-Inoperable-Scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
dayland committed Apr 11, 2024
2 parents 806ffe5 + d501469 commit f0aedc6
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 14 deletions.
11 changes: 10 additions & 1 deletion app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"ENABLE_UNGROUNDED_CHAT": "false",
"ENABLE_MATH_ASSISTANT": "false",
"ENABLE_TABULAR_DATA_ASSISTANT": "false",
"ENABLE_MULTIMEDIA": "false"
"ENABLE_MULTIMEDIA": "false",
"MAX_CSV_FILE_SIZE": "7"
}

for key, value in ENV.items():
Expand Down Expand Up @@ -594,6 +595,14 @@ async def get_warning_banner():
}
return response

@app.get("/getMaxCSVFileSize")
async def get_max_csv_file_size():
"""Get the max csv size"""
response ={
"MAX_CSV_FILE_SIZE": ENV["MAX_CSV_FILE_SIZE"]
}
return response

@app.post("/getcitation")
async def get_citation(request: Request):
"""
Expand Down
2 changes: 1 addition & 1 deletion app/backend/approaches/tabulardataassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_image_data(image_path):

def save_chart(query):
temp_dir = tempfile.gettempdir()
q_s = """ you are CSV Assistant, you are a dataframe ally. you analyze every row, addressing all queries with unwavering precision.
q_s = f""" you are CSV Assistant, you are a dataframe ally. you analyze every row, addressing all queries with unwavering precision.
You DO NOT answer based on subset of dataframe or top 5 or based on head() output. You need to look at all rows and then answer questions. data is case insensitive.
If any charts or graphs or plots were created save them in the {temp_dir} directory
Expand Down
17 changes: 17 additions & 0 deletions app/frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ChatResponse,
DeleteItemRequest,
ResubmitItemRequest,
GetFeatureFlagsResponse,
getMaxCSVFileSizeType,
} from "./models";

export async function chatApi(options: ChatRequest): Promise<ChatResponse> {
Expand Down Expand Up @@ -417,6 +418,22 @@ export async function getWarningBanner(): Promise<GetWarningBanner> {
return parsedResponse;
}

export async function getMaxCSVFileSize(): Promise<getMaxCSVFileSizeType> {
const response = await fetch("/getMaxCSVFileSize", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
const parsedResponse: getMaxCSVFileSizeType = await response.json();
if (response.status > 299 || !response.ok) {
console.log(response);
throw Error(parsedResponse.error || "Unknown error");
}
console.log(parsedResponse);
return parsedResponse;
}

export async function getCitationObj(citation: string): Promise<ActiveCitation> {
const response = await fetch(`/getcitation`, {
method: "POST",
Expand Down
5 changes: 5 additions & 0 deletions app/frontend/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ export type GetWarningBanner = {
error?: string;
};

export type getMaxCSVFileSizeType = {
MAX_CSV_FILE_SIZE: string;
error?: string;
};

// These keys need to match case with the defined Enum in the
// shared code (functions/shared_code/status_log.py)
export const enum StatusLogClassification {
Expand Down
37 changes: 26 additions & 11 deletions app/frontend/src/pages/tda/Tda.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import styles from "./file-picker.module.css";
import { FilesList } from "./files-list";
import cstyle from "./Tda.module.css"
import Papa from "papaparse";
import {postTd, processCsvAgentResponse, refresh, getTempImages, streamTdData } from "../../api";
import { Accordion, Card, Button } from 'react-bootstrap';
import ReactMarkdown from "react-markdown";
import {postTd, processCsvAgentResponse, refresh, getTempImages, streamTdData, getMaxCSVFileSize, getMaxCSVFileSizeType } from "../../api";
import { Button } from 'react-bootstrap';
import estyles from "../../components/Example/Example.module.css";
import { Example } from "../../components/Example";
import { DocumentDataFilled, SparkleFilled, TableSearchFilled } from "@fluentui/react-icons";
import { DocumentDataFilled, TableSearchFilled } from "@fluentui/react-icons";
import CharacterStreamer from '../../components/CharacterStreamer/CharacterStreamer';


Expand All @@ -42,6 +41,7 @@ const Tda = ({folderPath, tags}: Props) => {
const [fileu, setFile] = useState<File | null>(null);
const [images, setImages] = useState<string[]>([]);
const eventSourceRef = useRef<EventSource | null>(null);
const [maxCSVFileSize, setMaxCSVFileSize] = useState<getMaxCSVFileSizeType | null>(null);


type ExampleModel = {
Expand All @@ -59,11 +59,6 @@ const EXAMPLES: ExampleModel[] = [
interface Props {
onExampleClicked: (value: string) => void;
}
const saveChart = (query: string) => {
const tempDir = window?.require?.('os')?.tmpdir?.();
const qs = ` If any charts or graphs or plots were created save them in the ${tempDir} directory".`;
return query + ' . ' + qs;
};

useEffect(() => {
const intervalId = setInterval(() => {
Expand Down Expand Up @@ -171,14 +166,24 @@ const fetchImages = async () => {
setUploadStarted(false);
}, []);

useEffect(() => {
const fetchMaxCSVFileSize = async () => {
const size = await getMaxCSVFileSize();
console.log(size.MAX_CSV_FILE_SIZE)
setMaxCSVFileSize(size);
};

fetchMaxCSVFileSize();
}, []);
// handle for removing files form the files list view
const handleClearFile = useCallback((id: any) => {
setFiles((prev: any) => prev.filter((file: any) => file.id !== id));
}, []);

// whether to show the progress bar or not
const canShowProgress = useMemo(() => files.length > 0, [files.length]);

const MAX_CSV_FILE_SIZE = Number(maxCSVFileSize?.MAX_CSV_FILE_SIZE) * 1024 * 1024; // 5 MB default

// execute the upload operation
const handleUpload = useCallback(async () => {
try {
Expand All @@ -188,6 +193,12 @@ const fetchImages = async () => {
setUploadStarted(true);
files.forEach(async (indexedFile: any) => {
var file = indexedFile.file as File;
console.log('MAX_CSV_FILE_SIZE:', MAX_CSV_FILE_SIZE);
if (file.size > MAX_CSV_FILE_SIZE) {
alert(`File is too large. Please upload a file smaller than ${maxCSVFileSize?.MAX_CSV_FILE_SIZE} MB.`);
setUploadStarted(false);
return;
}
Papa.parse(file, {
header: true,
dynamicTyping: true,
Expand All @@ -214,6 +225,7 @@ const fetchImages = async () => {
} catch (error) {
console.error('Error uploading files: ', error);
}

}, [files]);

// set progress to zero when there are no files
Expand Down Expand Up @@ -322,7 +334,10 @@ const handleCloseEvent = () => {

<DocumentDataFilled fontSize={"40px"} primaryFill={"#7719aa"} aria-hidden="true" aria-label="Data" />
<span className={cstyle.EmptyObjectivesListItemText}><b>Data</b><br />
csv
csv<br />
</span>
<span className={cstyle.EmptyObjectivesListItemText}>
Max file size: {maxCSVFileSize?.MAX_CSV_FILE_SIZE} MB
</span>
<br />
<div className={styles.wrapper}>
Expand Down
1 change: 1 addition & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ module "backend" {
ENABLE_MATH_ASSISTANT = var.enableMathAssitant
ENABLE_TABULAR_DATA_ASSISTANT = var.enableTabularDataAssistant
ENABLE_MULTIMEDIA = var.enableMultimedia
MAX_CSV_FILE_SIZE = var.maxCsvFileSize
}
aadClientId = module.entraObjects.azure_ad_web_app_client_id
Expand Down
3 changes: 3 additions & 0 deletions infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,7 @@ output "AZURE_AI_TEXT_ANALYTICS_DOMAIN" {

output "AZURE_ARM_MANAGEMENT_API" {
value = var.azure_arm_management_api
}
output "MAX_CSV_FILE_SIZE" {
value = var.maxCsvFileSize
}
4 changes: 4 additions & 0 deletions infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,8 @@ variable "video_indexer_api_version" {
variable "enableDevCode" {
type = bool
default = false
}
variable "maxCsvFileSize" {
type = string
default = "20"
}
3 changes: 3 additions & 0 deletions scripts/environments/local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ export VIDEO_INDEXER_API_VERSION="2024-01-01"

# Enable capabilities under development. This should be set to false
export ENABLE_DEV_CODE=false

# If you are deploying the solution with the ability to use the Tabular Data Assistant feature, you can set the following values to configure max file size of csv files to be uploaded.
export MAX_CSV_FILE_SIZE="20" #default is 20MB
4 changes: 4 additions & 0 deletions scripts/json-to-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ jq -r '
{
"path": "DEPLOYMENT_KEYVAULT_NAME",
"env_var": "DEPLOYMENT_KEYVAULT_NAME"
},
{
"path": "MAX_CSV_FILE_SIZE",
"env_var": "MAX_CSV_FILE_SIZE"
}
]
as $env_vars_to_extract
Expand Down
5 changes: 5 additions & 0 deletions scripts/json-to-env.webapp.debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ jq -r '
"path": "AZURE_ARM_MANAGEMENT_API",
"env_var": "AZURE_ARM_MANAGEMENT_API"
}
,
{
"path": "MAX_CSV_FILE_SIZE",
"env_var": "MAX_CSV_FILE_SIZE"
}
]
as $env_vars_to_extract
|
Expand Down
3 changes: 2 additions & 1 deletion scripts/prepare-tf-variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export TF_VAR_enableUngroundedChat=$ENABLE_UNGROUNDED_CHAT
export TF_VAR_enableMathAssitant=$ENABLE_MATH_ASSISTANT
export TF_VAR_enableTabularDataAssistant=$ENABLE_TABULAR_DATA_ASSISTANT
export TF_VAR_enableSharePointConnector=$ENABLE_SHAREPOINT_CONNECTOR
export TF_VAR_enableMultimedia=$ENABLE_MULTIMEDIA
export TF_VAR_enableMultimedia=$ENABLE_MULTIMEDIA
export TF_VAR_maxCsvFileSize=$MAX_CSV_FILE_SIZE

0 comments on commit f0aedc6

Please sign in to comment.