From 3f3744b69861cf599180429b428eafd4533f2af9 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Sat, 23 Nov 2024 13:05:30 -0800 Subject: [PATCH] minor enforcement of CSV length for internal processing (#3109) --- backend/danswer/llm/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/danswer/llm/utils.py b/backend/danswer/llm/utils.py index 24017146912..343f93147d8 100644 --- a/backend/danswer/llm/utils.py +++ b/backend/danswer/llm/utils.py @@ -136,9 +136,11 @@ def translate_history_to_basemessages( return history_basemessages, history_token_counts -def _process_csv_file(file: InMemoryChatFile) -> str: +# Processes CSV files to show the first 5 rows and max_columns (default 40) columns +def _process_csv_file(file: InMemoryChatFile, max_columns: int = 40) -> str: df = pd.read_csv(io.StringIO(file.content.decode("utf-8"))) - csv_preview = df.head().to_string() + + csv_preview = df.head().to_string(max_cols=max_columns) file_name_section = ( f"CSV FILE NAME: {file.filename}\n"