Update app.py
Browse files
app.py
CHANGED
@@ -62,9 +62,9 @@ def query(payload, api_url):
|
|
62 |
logger.error(f"Failed to decode JSON response: {response.text}")
|
63 |
return None
|
64 |
|
65 |
-
# Function to perform
|
66 |
def search_web(query):
|
67 |
-
search_url = f"https://serphouse.com/
|
68 |
response = requests.get(search_url)
|
69 |
if response.status_code == 200:
|
70 |
return response.json()
|
@@ -94,8 +94,8 @@ if prompt := st.chat_input("Type your message..."):
|
|
94 |
search_results = search_web(prompt)
|
95 |
|
96 |
# Process search results if available
|
97 |
-
if search_results and "
|
98 |
-
search_content = "\n".join([f"**{item['title']}**: {item['snippet']}" for item in search_results["
|
99 |
search_content = f"Here are some search results related to your question:\n\n{search_content}\n\n"
|
100 |
|
101 |
# Combine the system message, search results, and user input into a single prompt
|
|
|
62 |
logger.error(f"Failed to decode JSON response: {response.text}")
|
63 |
return None
|
64 |
|
65 |
+
# Function to perform a web search using SerpHouse API
|
66 |
def search_web(query):
|
67 |
+
search_url = f"https://api.serphouse.com/serp/live?api_token=V38CNn4HXpLtynJQyOeoUensTEYoFy8PBUxKpDqAW1pawT1vfJ2BWtPQ98h6&q={query}&responseType=json&domain=google&lang=en&serp_type=web"
|
68 |
response = requests.get(search_url)
|
69 |
if response.status_code == 200:
|
70 |
return response.json()
|
|
|
94 |
search_results = search_web(prompt)
|
95 |
|
96 |
# Process search results if available
|
97 |
+
if search_results and "results" in search_results:
|
98 |
+
search_content = "\n".join([f"**{item['title']}**: {item['snippet']}" for item in search_results["results"]["organic"]])
|
99 |
search_content = f"Here are some search results related to your question:\n\n{search_content}\n\n"
|
100 |
|
101 |
# Combine the system message, search results, and user input into a single prompt
|