jeevan commited on
Commit
e33920b
1 Parent(s): 31e2acf

flag to enable azure deployment

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +7 -5
.gitignore CHANGED
@@ -3,3 +3,4 @@ venv/*
3
  __pycache__/*
4
  .vscode/launch.json
5
  .vscode/settings.json
 
 
3
  __pycache__/*
4
  .vscode/launch.json
5
  .vscode/settings.json
6
+ .notes
app.py CHANGED
@@ -23,17 +23,19 @@ unique_id = uuid4().hex[0:8]
23
  os.environ["LANGCHAIN_TRACING_V2"] = "true"
24
  os.environ["LANGCHAIN_PROJECT"] = f"LangSmith LCEL RAG - {unique_id}"
25
 
 
 
26
  # Utility functions
27
- def save_file(file: AskFileResponse,file_ext:str) -> str:
28
  if file_ext == "application/pdf":
29
  file_ext = ".pdf"
30
  elif file_ext == "text/plain":
31
  file_ext = ".txt"
32
  else:
33
  raise ValueError(f"Unknown file type: {file_ext}")
34
-
35
  with tempfile.NamedTemporaryFile(
36
- mode="wb", delete=False, suffix=file_ext
37
  ) as temp_file:
38
  temp_file_path = temp_file.name
39
  temp_file.write(file.content)
@@ -83,8 +85,8 @@ async def on_chat_start():
83
  ## Load file and split into chunks
84
  msg = cl.Message(content=f"Processing `{files[0].name}`...")
85
  await msg.send()
86
-
87
- current_file_path = save_file(files[0], files[0].type)
88
  loader_splitter = TextLoaderAndSplitterWrapper(ChunkingStrategy.RECURSIVE_CHARACTER_CHAR_SPLITTER, current_file_path)
89
  documents = loader_splitter.load_documents()
90
 
 
23
  os.environ["LANGCHAIN_TRACING_V2"] = "true"
24
  os.environ["LANGCHAIN_PROJECT"] = f"LangSmith LCEL RAG - {unique_id}"
25
 
26
+ is_azure = False if os.environ.get("AZURE_DEPLOYMENT") is None else True
27
+
28
  # Utility functions
29
+ def save_file(file: AskFileResponse,file_ext:str,is_azure:bool) -> str:
30
  if file_ext == "application/pdf":
31
  file_ext = ".pdf"
32
  elif file_ext == "text/plain":
33
  file_ext = ".txt"
34
  else:
35
  raise ValueError(f"Unknown file type: {file_ext}")
36
+ dir = "/tmp" if is_azure else None
37
  with tempfile.NamedTemporaryFile(
38
+ mode="wb", delete=False, suffix=file_ext,dir=dir
39
  ) as temp_file:
40
  temp_file_path = temp_file.name
41
  temp_file.write(file.content)
 
85
  ## Load file and split into chunks
86
  msg = cl.Message(content=f"Processing `{files[0].name}`...")
87
  await msg.send()
88
+
89
+ current_file_path = save_file(files[0], files[0].type,is_azure)
90
  loader_splitter = TextLoaderAndSplitterWrapper(ChunkingStrategy.RECURSIVE_CHARACTER_CHAR_SPLITTER, current_file_path)
91
  documents = loader_splitter.load_documents()
92