Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
f95ea5a
1
Parent(s):
ddcab83
Update app.py
Browse files
app.py
CHANGED
@@ -192,11 +192,23 @@ def query_rag(query_text: str):
|
|
192 |
db = Chroma(persist_directory=CHROMA_PATH, embedding_function=embedding_function)
|
193 |
results = db.similarity_search_with_score(query_text, k=5)
|
194 |
context_text = "\n\n---\n\n".join([doc.page_content for doc, _score in results])
|
|
|
195 |
prompt_template = ChatPromptTemplate.from_template(PROMPT_TEMPLATE)
|
196 |
prompt = prompt_template.format(context=context_text, question=query_text)
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
def save_pdf_and_update_database(media_url):
|
202 |
response = requests.get(media_url)
|
|
|
192 |
db = Chroma(persist_directory=CHROMA_PATH, embedding_function=embedding_function)
|
193 |
results = db.similarity_search_with_score(query_text, k=5)
|
194 |
context_text = "\n\n---\n\n".join([doc.page_content for doc, _score in results])
|
195 |
+
|
196 |
prompt_template = ChatPromptTemplate.from_template(PROMPT_TEMPLATE)
|
197 |
prompt = prompt_template.format(context=context_text, question=query_text)
|
198 |
+
|
199 |
+
response = ''
|
200 |
+
for chunk in AI71(AI71_API_KEY).chat.completions.create(
|
201 |
+
model="tiiuae/falcon-180b-chat",
|
202 |
+
messages=[
|
203 |
+
{"role": "system", "content": "You are the best agricultural assistant. Remember to give a response in not more than 2 sentences."},
|
204 |
+
{"role": "user", "content": f'''Answer the following query based on the given context: {prompt}'''},
|
205 |
+
],
|
206 |
+
stream=True,
|
207 |
+
):
|
208 |
+
if chunk.choices[0].delta.content:
|
209 |
+
response += chunk.choices[0].delta.content
|
210 |
+
|
211 |
+
return response.replace("###", '').replace('\nUser:', '')
|
212 |
|
213 |
def save_pdf_and_update_database(media_url):
|
214 |
response = requests.get(media_url)
|