Spaces:
Sleeping
Sleeping
back to recursive
Browse files
app.py
CHANGED
@@ -12,8 +12,8 @@ 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 |
-
from langchain_experimental.text_splitter import SemanticChunker
|
16 |
-
from langchain_openai.embeddings import OpenAIEmbeddings
|
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."""
|
@@ -49,12 +49,12 @@ class RetrievalAugmentedQAPipeline:
|
|
49 |
|
50 |
return {"response": generate_response(), "context": context_list}
|
51 |
|
52 |
-
|
53 |
-
try:
|
54 |
-
|
55 |
-
except KeyError:
|
56 |
-
|
57 |
-
text_splitter = SemanticChunker(OpenAIEmbeddings(api_key=api_key), breakpoint_threshold_type="standard_deviation")
|
58 |
|
59 |
def process_text_file(file: AskFileResponse):
|
60 |
import tempfile
|
@@ -74,8 +74,8 @@ def process_text_file(file: AskFileResponse):
|
|
74 |
documents = pdf_loader.load()
|
75 |
else:
|
76 |
raise ValueError("Provide a .txt or .pdf file")
|
77 |
-
|
78 |
-
texts = [x.page_content for x in text_splitter.split_documents(documents)]
|
79 |
return texts
|
80 |
|
81 |
|
|
|
12 |
from aimakerspace.openai_utils.chatmodel import ChatOpenAI
|
13 |
import chainlit as cl
|
14 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
15 |
+
# from langchain_experimental.text_splitter import SemanticChunker
|
16 |
+
# from langchain_openai.embeddings import OpenAIEmbeddings
|
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."""
|
|
|
49 |
|
50 |
return {"response": generate_response(), "context": context_list}
|
51 |
|
52 |
+
text_splitter = RecursiveCharacterTextSplitter()
|
53 |
+
# try:
|
54 |
+
# api_key = os.environ["OPENAI_API_KEY"]
|
55 |
+
# except KeyError:
|
56 |
+
# print("Environment variable OPENAI_API_KEY not found")
|
57 |
+
# text_splitter = SemanticChunker(OpenAIEmbeddings(api_key=api_key), breakpoint_threshold_type="standard_deviation")
|
58 |
|
59 |
def process_text_file(file: AskFileResponse):
|
60 |
import tempfile
|
|
|
74 |
documents = pdf_loader.load()
|
75 |
else:
|
76 |
raise ValueError("Provide a .txt or .pdf file")
|
77 |
+
texts = [x.page_content for x in text_splitter.transform_documents(documents)]
|
78 |
+
# texts = [x.page_content for x in text_splitter.split_documents(documents)]
|
79 |
return texts
|
80 |
|
81 |
|