KingNish commited on
Commit
df243be
1 Parent(s): 138c976

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -212,6 +212,44 @@ async def web_search_and_extract(
212
  except Exception as e:
213
  raise HTTPException(status_code=500, detail=f"Error during search and extraction: {e}")
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  @app.get("/api/website_summarizer")
216
  async def website_summarizer(url: str):
217
  """Summarizes the content of a given URL using a chat model."""
 
212
  except Exception as e:
213
  raise HTTPException(status_code=500, detail=f"Error during search and extraction: {e}")
214
 
215
+ @app.get("/api/adv_web_search")
216
+ async def adv_web_search(
217
+ model: str,
218
+ message: str,
219
+ ):
220
+ """Interact with a specified large language model with an optional system prompt."""
221
+ try:
222
+ with WEBS() as webs:
223
+ # Perform WEBS search
224
+ search_results = webs.text(keywords=message, backend="html", max_results=3)
225
+ # Extract text from each result's link
226
+ extracted_results = []
227
+ for result in search_results:
228
+ if 'href' in result:
229
+ link = result['href']
230
+ try:
231
+ response = requests.get(link, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0"})
232
+ response.raise_for_status()
233
+ visible_text = extract_text_from_webpage(response.text)
234
+ if len(visible_text) > 15000:
235
+ visible_text = visible_text[:15000] + "..."
236
+ extracted_results.append({"link": link, "text": visible_text})
237
+ except requests.exceptions.RequestException as e:
238
+ print(f"Error fetching or processing {link}: {e}")
239
+ extracted_results.append({"link": link, "text": None})
240
+ else:
241
+ extracted_results.append({"link": None, "text": None})
242
+ message += f"Answer tis question in detail {message}. Now, You are provided with Google Search Results, To increase your accuracy and providing real time data. {extracted_results} "
243
+
244
+ messages = [{"role": "user", "content": message}]
245
+ messages.insert(0, {"role": "system", "content": "You are Most Advanced and Powerful Ai chatbot, User ask you questions and you have to answer that, You are also provided with Google Search Results, To increase your accuracy and providing real time data. Your task is to answer in best way to user."})
246
+ llm = LLM(model=model)
247
+ response = llm.chat(messages=messages)
248
+ return JSONResponse(content={response})
249
+ except Exception as e:
250
+ raise HTTPException(status_code=500, detail=f"Error during LLM chat: {e}")
251
+
252
+
253
  @app.get("/api/website_summarizer")
254
  async def website_summarizer(url: str):
255
  """Summarizes the content of a given URL using a chat model."""