acpotts commited on
Commit
1c3fad8
1 Parent(s): f443ff6
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -10,10 +10,8 @@ from aimakerspace.openai_utils.prompts import (
10
  from aimakerspace.openai_utils.embedding import EmbeddingModel
11
  from aimakerspace.vectordatabase import VectorDatabase
12
  from aimakerspace.openai_utils.chatmodel import ChatOpenAI
13
- from langchain_experimental.text_splitter import SemanticChunker
14
- from langchain_openai.embeddings import OpenAIEmbeddings
15
  import chainlit as cl
16
- from langchain_community.document_loaders.pdf import PyPDFLoader
17
 
18
  system_template = """\
19
  Use the following context to answer a users question. If you cannot find the answer in the context, say you don't know the answer."""
@@ -22,7 +20,6 @@ system_role_prompt = SystemRolePrompt(system_template)
22
  user_prompt_template = """\
23
  Context:
24
  {context}
25
-
26
  Question:
27
  {question}
28
  """
@@ -50,11 +47,12 @@ class RetrievalAugmentedQAPipeline:
50
 
51
  return {"response": generate_response(), "context": context_list}
52
 
53
- # text_splitter = CharacterTextSplitter()
54
- text_splitter = SemanticChunker(OpenAIEmbeddings(), breakpoint_threshold_type="standard_deviation")
55
 
56
  def process_text_file(file: AskFileResponse):
57
  import tempfile
 
58
 
59
  with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=file.name) as temp_file:
60
  temp_file_path = temp_file.name
@@ -82,7 +80,7 @@ async def on_chat_start():
82
  # Wait for the user to upload a file
83
  while files == None:
84
  files = await cl.AskFileMessage(
85
- content="Please upload a Text File or PDF to begin!",
86
  accept=["text/plain", "application/pdf"],
87
  max_size_mb=2,
88
  timeout=180,
 
10
  from aimakerspace.openai_utils.embedding import EmbeddingModel
11
  from aimakerspace.vectordatabase import VectorDatabase
12
  from aimakerspace.openai_utils.chatmodel import ChatOpenAI
 
 
13
  import chainlit as cl
14
+ from langchain_text_splitters import RecursiveCharacterTextSplitter
15
 
16
  system_template = """\
17
  Use the following context to answer a users question. If you cannot find the answer in the context, say you don't know the answer."""
 
20
  user_prompt_template = """\
21
  Context:
22
  {context}
 
23
  Question:
24
  {question}
25
  """
 
47
 
48
  return {"response": generate_response(), "context": context_list}
49
 
50
+ text_splitter = RecursiveCharacterTextSplitter()
51
+
52
 
53
  def process_text_file(file: AskFileResponse):
54
  import tempfile
55
+ from langchain_community.document_loaders.pdf import PyPDFLoader
56
 
57
  with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=file.name) as temp_file:
58
  temp_file_path = temp_file.name
 
80
  # Wait for the user to upload a file
81
  while files == None:
82
  files = await cl.AskFileMessage(
83
+ content="Please upload a Text file or a PDF to begin!",
84
  accept=["text/plain", "application/pdf"],
85
  max_size_mb=2,
86
  timeout=180,