Spaces:
Runtime error
Runtime error
Ashhar
commited on
Commit
·
6e0cef4
1
Parent(s):
0b4a166
added related questions feature
Browse files- app.py +13 -12
- constants.py +10 -3
- soup_dump.html +0 -0
- tools/webScraper.py +2 -2
app.py
CHANGED
|
@@ -88,15 +88,16 @@ def __isInvalidResponse(response: str):
|
|
| 88 |
U.pprint("LLM API threw exception")
|
| 89 |
return True
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
|
| 102 |
def __matchingKeywordsCount(keywords: List[str], text: str):
|
|
@@ -379,7 +380,7 @@ for chat in st.session_state.chatHistory:
|
|
| 379 |
# U.pprint(f"{st.session_state.startMsg=}")
|
| 380 |
|
| 381 |
if prompt := (
|
| 382 |
-
st.chat_input("Ask anything")
|
| 383 |
or st.session_state["buttonValue"]
|
| 384 |
):
|
| 385 |
__resetButtonState()
|
|
@@ -466,11 +467,11 @@ if prompt := (
|
|
| 466 |
try:
|
| 467 |
json.loads(jsonStr)
|
| 468 |
jsonObj = json.loads(jsonStr)
|
| 469 |
-
|
| 470 |
action = jsonObj.get("action")
|
| 471 |
|
| 472 |
-
if
|
| 473 |
-
for option in
|
| 474 |
st.button(
|
| 475 |
option["label"],
|
| 476 |
key=option["id"],
|
|
|
|
| 88 |
U.pprint("LLM API threw exception")
|
| 89 |
return True
|
| 90 |
|
| 91 |
+
if ('{\n "questions"' in response) and (C.JSON_SEPARATOR not in response):
|
| 92 |
+
U.pprint("JSON response without json separator")
|
| 93 |
+
return True
|
| 94 |
+
if ('{\n "action"' in response) and (C.JSON_SEPARATOR not in response):
|
| 95 |
+
U.pprint("JSON response without json separator")
|
| 96 |
+
return True
|
| 97 |
|
| 98 |
+
if response.startswith(C.JSON_SEPARATOR):
|
| 99 |
+
U.pprint("only options with no text")
|
| 100 |
+
return True
|
| 101 |
|
| 102 |
|
| 103 |
def __matchingKeywordsCount(keywords: List[str], text: str):
|
|
|
|
| 380 |
# U.pprint(f"{st.session_state.startMsg=}")
|
| 381 |
|
| 382 |
if prompt := (
|
| 383 |
+
st.chat_input("Ask anything ...")
|
| 384 |
or st.session_state["buttonValue"]
|
| 385 |
):
|
| 386 |
__resetButtonState()
|
|
|
|
| 467 |
try:
|
| 468 |
json.loads(jsonStr)
|
| 469 |
jsonObj = json.loads(jsonStr)
|
| 470 |
+
questions = jsonObj.get("questions")
|
| 471 |
action = jsonObj.get("action")
|
| 472 |
|
| 473 |
+
if questions:
|
| 474 |
+
for option in questions:
|
| 475 |
st.button(
|
| 476 |
option["label"],
|
| 477 |
key=option["id"],
|
constants.py
CHANGED
|
@@ -30,7 +30,7 @@ Keep options to less than 5.
|
|
| 30 |
|
| 31 |
"""
|
| 32 |
|
| 33 |
-
SYSTEM_MSG = """
|
| 34 |
=> Instructions:
|
| 35 |
You're a helpful assistant who tries to answer as accurately as possible. Always add supporting details wherever possible AFTER the primary answer.
|
| 36 |
If a query is not in past tense, search google.
|
|
@@ -40,8 +40,9 @@ If a query is not in past tense, search google.
|
|
| 40 |
## Rule 1:
|
| 41 |
- If you don't know an answer or are not sure if it's correct and latest, then you search google and collect search results.
|
| 42 |
- You then read through all the google search results, and generate the answer.
|
| 43 |
-
-
|
| 44 |
-
{Generated Answer}
|
|
|
|
| 45 |
\n-------
|
| 46 |
References:
|
| 47 |
(all below citations as different bullet points, max 5 citations)
|
|
@@ -55,6 +56,12 @@ If a query is not in past tense, search google.
|
|
| 55 |
|
| 56 |
=> Response Format:
|
| 57 |
- Don't tell how you arrived at the answer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
"""
|
| 59 |
|
| 60 |
# """
|
|
|
|
| 30 |
|
| 31 |
"""
|
| 32 |
|
| 33 |
+
SYSTEM_MSG = f"""
|
| 34 |
=> Instructions:
|
| 35 |
You're a helpful assistant who tries to answer as accurately as possible. Always add supporting details wherever possible AFTER the primary answer.
|
| 36 |
If a query is not in past tense, search google.
|
|
|
|
| 40 |
## Rule 1:
|
| 41 |
- If you don't know an answer or are not sure if it's correct and latest, then you search google and collect search results.
|
| 42 |
- You then read through all the google search results, and generate the answer.
|
| 43 |
+
- You return the final answer (before Questions JSON) in this format (each point should be in a new line):
|
| 44 |
+
{{Generated Answer}}
|
| 45 |
+
<Brief details/context about the answer>
|
| 46 |
\n-------
|
| 47 |
References:
|
| 48 |
(all below citations as different bullet points, max 5 citations)
|
|
|
|
| 56 |
|
| 57 |
=> Response Format:
|
| 58 |
- Don't tell how you arrived at the answer.
|
| 59 |
+
- Append this exact keyword "{JSON_SEPARATOR}" to your FINAL response (after appending details and references, if any), and only AFTER this, append a JSON of possible Questions that the user might be interesed in (max 4) in the format described below.
|
| 60 |
+
```
|
| 61 |
+
{{
|
| 62 |
+
"questions": [{{ "id": "1", "label": "Question 1"}}, {{ "id": "2", "label": "Question 2"}}]
|
| 63 |
+
}}
|
| 64 |
+
```
|
| 65 |
"""
|
| 66 |
|
| 67 |
# """
|
soup_dump.html
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tools/webScraper.py
CHANGED
|
@@ -24,13 +24,13 @@ def scrapeGoogleSearch(query):
|
|
| 24 |
citationDate = citationDateDiv.text if citationDateDiv else ""
|
| 25 |
answerText = answerDiv.text.replace(citationDate, '').strip()
|
| 26 |
citationText = f"Citation Date: {citationDate}" if citationDate else ""
|
| 27 |
-
finalResponse.append(f"Verified Answer:\n
|
| 28 |
|
| 29 |
results = mainDiv.select('div.egMi0.kCrYT')
|
| 30 |
resultsDesc = mainDiv.select('div.BNeawe.s3v9rd.AP7Wnd .BNeawe.s3v9rd.AP7Wnd:last-child')
|
| 31 |
|
| 32 |
if results:
|
| 33 |
-
finalResponse.append("Search Results:\n
|
| 34 |
|
| 35 |
for (i, result) in enumerate(results[:10]):
|
| 36 |
title = result.find('h3').text
|
|
|
|
| 24 |
citationDate = citationDateDiv.text if citationDateDiv else ""
|
| 25 |
answerText = answerDiv.text.replace(citationDate, '').strip()
|
| 26 |
citationText = f"Citation Date: {citationDate}" if citationDate else ""
|
| 27 |
+
finalResponse.append(f"Verified Answer:\n{answerText}\n{citationText}\n\n\n")
|
| 28 |
|
| 29 |
results = mainDiv.select('div.egMi0.kCrYT')
|
| 30 |
resultsDesc = mainDiv.select('div.BNeawe.s3v9rd.AP7Wnd .BNeawe.s3v9rd.AP7Wnd:last-child')
|
| 31 |
|
| 32 |
if results:
|
| 33 |
+
finalResponse.append("Search Results:\n")
|
| 34 |
|
| 35 |
for (i, result) in enumerate(results[:10]):
|
| 36 |
title = result.find('h3').text
|