Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,7 +40,7 @@ llm = ChatOpenAI(
|
|
| 40 |
# List of product names
|
| 41 |
products = []
|
| 42 |
for id in db.index_to_docstore_id.values():
|
| 43 |
-
prod_name = db.docstore.search(id).metadata
|
| 44 |
products.append(prod_name)
|
| 45 |
|
| 46 |
|
|
@@ -153,11 +153,9 @@ def retrieve_products(query):
|
|
| 153 |
if correct_prods:
|
| 154 |
prods_mp = {}
|
| 155 |
for prod in correct_prods:
|
| 156 |
-
print(prod)
|
| 157 |
# Retrieve from db, each product 4-chunks
|
| 158 |
-
docs = db.similarity_search(query = "", filter = {'Product Name': prod
|
| 159 |
-
|
| 160 |
-
prods_mp[prod['Product Name']] = "\n".join([doc.page_content for doc in docs])
|
| 161 |
|
| 162 |
return prods_mp
|
| 163 |
return False
|
|
@@ -222,7 +220,7 @@ def qa_retrieve(chatlog,):
|
|
| 222 |
|
| 223 |
Answer the following question: {query}
|
| 224 |
Use the following documents for each product:
|
| 225 |
-
{
|
| 226 |
|
| 227 |
Only use the factual information from the documents to answer the question. You are very careful in the products or theory name and will not invent or imagine names.
|
| 228 |
Make sure to always answer the question with the same language the question is in. If it's in chinese make sure to answer in chinese. If it's in english answer in english.
|
|
@@ -236,7 +234,7 @@ def qa_retrieve(chatlog,):
|
|
| 236 |
# llm = BardLLM()
|
| 237 |
chain = LLMChain(llm=llm, prompt = prompt)
|
| 238 |
|
| 239 |
-
response = chain.run(query=query, products=mp_products)
|
| 240 |
|
| 241 |
|
| 242 |
chatlog[-1][1] = response
|
|
|
|
| 40 |
# List of product names
|
| 41 |
products = []
|
| 42 |
for id in db.index_to_docstore_id.values():
|
| 43 |
+
prod_name = db.docstore.search(id).metadata['Product Name']
|
| 44 |
products.append(prod_name)
|
| 45 |
|
| 46 |
|
|
|
|
| 153 |
if correct_prods:
|
| 154 |
prods_mp = {}
|
| 155 |
for prod in correct_prods:
|
|
|
|
| 156 |
# Retrieve from db, each product 4-chunks
|
| 157 |
+
docs = db.similarity_search(query = "", filter = {'Product Name': prod}, k = 4, fetch_k = 49190)
|
| 158 |
+
prods_mp[prod] = "\n".join([doc.page_content for doc in docs])
|
|
|
|
| 159 |
|
| 160 |
return prods_mp
|
| 161 |
return False
|
|
|
|
| 220 |
|
| 221 |
Answer the following question: {query}
|
| 222 |
Use the following documents for each product:
|
| 223 |
+
{products}
|
| 224 |
|
| 225 |
Only use the factual information from the documents to answer the question. You are very careful in the products or theory name and will not invent or imagine names.
|
| 226 |
Make sure to always answer the question with the same language the question is in. If it's in chinese make sure to answer in chinese. If it's in english answer in english.
|
|
|
|
| 234 |
# llm = BardLLM()
|
| 235 |
chain = LLMChain(llm=llm, prompt = prompt)
|
| 236 |
|
| 237 |
+
response = chain.run(query=query, products="\n".join(mp_products))
|
| 238 |
|
| 239 |
|
| 240 |
chatlog[-1][1] = response
|