KingNish commited on
Commit
6df9775
·
verified ·
1 Parent(s): c6f86b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -378,12 +378,12 @@ def web_search_and_extract_threading(
378
  async def adv_web_search(
379
  q: str,
380
  model: str = "gpt-4o-mini", # Use webs.chat by default
381
- max_results: int = 3,
382
  timelimit: Optional[str] = None,
383
  safesearch: str = "moderate",
384
  region: str = "wt-wt",
385
  backend: str = "html",
386
- max_chars: int = 6000,
387
  system_prompt: str = "You are an advanced AI chatbot. Provide the best answer to the user based on Google search results.",
388
  proxy: Optional[str] = None
389
  ):
@@ -393,18 +393,12 @@ async def adv_web_search(
393
  try:
394
  with WEBS(proxy=proxy) as webs:
395
  # 1. Perform the web search
396
- search_results = webs.text(keywords=q, region=region,
397
  safesearch=safesearch,
398
  timelimit=timelimit, backend=backend,
399
- max_results=max_results)
400
 
401
- # 2. Extract text from top search result URLs asynchronously
402
- extracted_text = ""
403
- tasks = [fetch_and_extract(result['href'], max_chars, proxy) for result in search_results if 'href' in result]
404
- extracted_results = await asyncio.gather(*tasks)
405
- for result in extracted_results:
406
- if result['text']:
407
- extracted_text += f"## Content from: {result['link']}\n\n{result['text']}\n\n"
408
 
409
  # 3. Construct the prompt for the chat model
410
  ai_prompt = (
 
378
  async def adv_web_search(
379
  q: str,
380
  model: str = "gpt-4o-mini", # Use webs.chat by default
381
+ max_results: int = 5,
382
  timelimit: Optional[str] = None,
383
  safesearch: str = "moderate",
384
  region: str = "wt-wt",
385
  backend: str = "html",
386
+ max_chars: int = 15000,
387
  system_prompt: str = "You are an advanced AI chatbot. Provide the best answer to the user based on Google search results.",
388
  proxy: Optional[str] = None
389
  ):
 
393
  try:
394
  with WEBS(proxy=proxy) as webs:
395
  # 1. Perform the web search
396
+ extracted_text = str(web_search_and_extract_threading(q=q, region=region,
397
  safesearch=safesearch,
398
  timelimit=timelimit, backend=backend,
399
+ max_results=max_results))
400
 
401
+ extracted_text = extracted_text[:max_chars]
 
 
 
 
 
 
402
 
403
  # 3. Construct the prompt for the chat model
404
  ai_prompt = (