Spaces:
Running
on
Zero
Running
on
Zero
VanguardAI
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -91,11 +91,29 @@ def image_generation(query):
|
|
91 |
def doc_question_answering(query, file_path):
|
92 |
with open(file_path, 'r') as f:
|
93 |
file_content = f.read()
|
|
|
|
|
94 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
95 |
docs = text_splitter.create_documents([file_content])
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
db = Chroma.from_documents(docs, embeddings, persist_directory=".chroma_db")
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
return qa.run(query)
|
100 |
|
101 |
# Function to handle different input types and choose the right tool
|
|
|
91 |
def doc_question_answering(query, file_path):
|
92 |
with open(file_path, 'r') as f:
|
93 |
file_content = f.read()
|
94 |
+
|
95 |
+
# Split the document into smaller chunks
|
96 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
97 |
docs = text_splitter.create_documents([file_content])
|
98 |
+
|
99 |
+
# Create embeddings using the groq model
|
100 |
+
embeddings = OpenAIEmbeddings() # If you're using a custom embeddings model, replace this line with the corresponding embeddings model for groq
|
101 |
+
|
102 |
+
# Set up the Chroma database for document retrieval
|
103 |
db = Chroma.from_documents(docs, embeddings, persist_directory=".chroma_db")
|
104 |
+
|
105 |
+
# Create a custom function to use groq for the question-answering step
|
106 |
+
def groq_llm(query):
|
107 |
+
response = client.chat.completions.create(
|
108 |
+
model=MODEL,
|
109 |
+
messages=[{"role": "user", "content": query}]
|
110 |
+
)
|
111 |
+
return response.choices[0].message.content
|
112 |
+
|
113 |
+
# Set up the RetrievalQA chain using the custom groq LLM function
|
114 |
+
qa = RetrievalQA.from_chain_type(llm=groq_llm, chain_type="stuff", retriever=db.as_retriever())
|
115 |
+
|
116 |
+
# Run the QA process with the groq model
|
117 |
return qa.run(query)
|
118 |
|
119 |
# Function to handle different input types and choose the right tool
|