Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ class Agent1:
|
|
29 |
rephrase_prompt = PromptTemplate(
|
30 |
input_variables=["query"],
|
31 |
template="""
|
32 |
-
|
33 |
If the query contains multiple distinct questions, split them.
|
34 |
Provide ONLY the rephrased queries without any additional text or explanations, one per line.
|
35 |
|
@@ -279,6 +279,7 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
279 |
|
280 |
max_attempts = 3
|
281 |
context_reduction_factor = 0.7
|
|
|
282 |
|
283 |
for attempt in range(max_attempts):
|
284 |
try:
|
@@ -349,15 +350,19 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
349 |
else:
|
350 |
answer = full_response.strip()
|
351 |
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
|
|
|
|
|
|
|
|
361 |
|
362 |
if web_search:
|
363 |
sources = set(doc.metadata['source'] for doc in web_docs)
|
|
|
29 |
rephrase_prompt = PromptTemplate(
|
30 |
input_variables=["query"],
|
31 |
template="""
|
32 |
+
Rephrase the given query into one or more concise, search-engine-friendly formats.
|
33 |
If the query contains multiple distinct questions, split them.
|
34 |
Provide ONLY the rephrased queries without any additional text or explanations, one per line.
|
35 |
|
|
|
279 |
|
280 |
max_attempts = 3
|
281 |
context_reduction_factor = 0.7
|
282 |
+
agent2_max_attempts = 2
|
283 |
|
284 |
for attempt in range(max_attempts):
|
285 |
try:
|
|
|
350 |
else:
|
351 |
answer = full_response.strip()
|
352 |
|
353 |
+
for agent2_attempt in range(agent2_max_attempts):
|
354 |
+
if agent2.validate_response(question, answer):
|
355 |
+
break
|
356 |
+
|
357 |
+
if agent2_attempt < agent2_max_attempts - 1:
|
358 |
+
follow_up_query = agent2.generate_follow_up_query(question, answer)
|
359 |
+
follow_up_results = agent1.process(follow_up_query)
|
360 |
+
follow_up_docs = [Document(page_content=result["text"], metadata={"source": result["link"], "query": follow_up_query}) for results in follow_up_results.values() for result in results if result["text"]]
|
361 |
+
database.add_documents(follow_up_docs)
|
362 |
+
context_str += "\n" + "\n".join([f"Follow-up Query: {doc.metadata['query']}\nSource: {doc.metadata['source']}\nContent: {doc.page_content}" for doc in follow_up_docs])
|
363 |
+
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
364 |
+
full_response = generate_chunked_response(model, formatted_prompt)
|
365 |
+
answer = full_response.strip()
|
366 |
|
367 |
if web_search:
|
368 |
sources = set(doc.metadata['source'] for doc in web_docs)
|