Abhaykoul commited on
Commit
9235666
·
verified ·
1 Parent(s): f008a24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -339,8 +339,8 @@ def web_search_and_extract_threading(
339
  @app.get("/api/adv_web_search")
340
  async def adv_web_search(
341
  q: str,
342
- model: str = "gpt-4o-mini",
343
- max_results: int = 5,
344
  timelimit: Optional[str] = None,
345
  safesearch: str = "moderate",
346
  region: str = "wt-wt",
@@ -355,14 +355,10 @@ async def adv_web_search(
355
  try:
356
  with WEBS(proxy=proxy) as webs:
357
  # 1. Perform the web search
358
- search_results = webs.text(
359
- keywords=q,
360
- region=region,
361
- safesearch=safesearch,
362
- timelimit=timelimit,
363
- backend=backend,
364
- max_results=max_results
365
- )
366
 
367
  # 2. Extract text from top search result URLs asynchronously
368
  extracted_text = ""
@@ -373,17 +369,13 @@ async def adv_web_search(
373
  extracted_text += f"## Content from: {result['link']}\n\n{result['text']}\n\n"
374
 
375
  # 3. Construct the prompt for FastAI
376
- ai_prompt = (
377
- f"User Query: {q}\n\n"
378
- f"Please provide a detailed and accurate answer to the user's query. Include relevant information extracted from the search results below. Ensure to cite sources by providing links to the original content where applicable. Format your response as follows:\n\n"
379
- f"1. **Answer:** Provide a clear and comprehensive answer to the user's query.\n"
380
- f"2. **Details:** Include any additional relevant details or explanations.\n"
381
- f"3. **Sources:** List the sources of the information with clickable links for further reading.\n\n"
382
- f"Search Results:\n{extracted_text}"
383
- )
384
-
385
- # 4. Get the AI's response directly using webs().chat
386
- response = webs.chat(keywords=ai_prompt, model=model)
387
 
388
  # 5. Return the results
389
  return JSONResponse(content={"response": response})
 
339
  @app.get("/api/adv_web_search")
340
  async def adv_web_search(
341
  q: str,
342
+ model: str = "llama3-8b",
343
+ max_results: int = 3,
344
  timelimit: Optional[str] = None,
345
  safesearch: str = "moderate",
346
  region: str = "wt-wt",
 
355
  try:
356
  with WEBS(proxy=proxy) as webs:
357
  # 1. Perform the web search
358
+ search_results = webs.text(keywords=q, region=region,
359
+ safesearch=safesearch,
360
+ timelimit=timelimit, backend=backend,
361
+ max_results=max_results)
 
 
 
 
362
 
363
  # 2. Extract text from top search result URLs asynchronously
364
  extracted_text = ""
 
369
  extracted_text += f"## Content from: {result['link']}\n\n{result['text']}\n\n"
370
 
371
  # 3. Construct the prompt for FastAI
372
+ ai_prompt = f"Query by user: {q}. Answer the query asked by the user in detail. Search Result: {extracted_text}"
373
+
374
+ # 4. Get the FastAI's response using FastAI service
375
+ try:
376
+ response = await asyncio.to_thread(fastai, ai_prompt, model=model, system=system_prompt)
377
+ except Exception as e:
378
+ raise HTTPException(status_code=500, detail=f"Error during FastAI request: {e}")
 
 
 
 
379
 
380
  # 5. Return the results
381
  return JSONResponse(content={"response": response})