Update app.py
Browse files
app.py
CHANGED
@@ -355,10 +355,14 @@ 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 |
-
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
362 |
|
363 |
# 2. Extract text from top search result URLs asynchronously
|
364 |
extracted_text = ""
|
@@ -376,14 +380,10 @@ async def adv_web_search(
|
|
376 |
f"2. **Details:** Include any additional relevant details or explanations.\n"
|
377 |
f"3. **Sources:** List the sources of the information with clickable links for further reading.\n\n"
|
378 |
f"Search Results:\n{extracted_text}"
|
379 |
-
)
|
380 |
|
381 |
-
|
382 |
-
|
383 |
-
try:
|
384 |
-
response = webs.chat(keywords=ai_prompt, model=model)
|
385 |
-
except Exception as e:
|
386 |
-
raise HTTPException(status_code=500, detail=f"Error during FastAI request: {e}")
|
387 |
|
388 |
# 5. Return the results
|
389 |
return JSONResponse(content={"response": response})
|
@@ -391,6 +391,7 @@ async def adv_web_search(
|
|
391 |
except Exception as e:
|
392 |
raise HTTPException(status_code=500, detail=f"Error during advanced search: {e}")
|
393 |
|
|
|
394 |
@app.get("/api/website_summarizer")
|
395 |
async def website_summarizer(url: str, proxy: Optional[str] = None):
|
396 |
"""Summarizes the content of a given URL using a chat model."""
|
|
|
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 = ""
|
|
|
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})
|
|
|
391 |
except Exception as e:
|
392 |
raise HTTPException(status_code=500, detail=f"Error during advanced search: {e}")
|
393 |
|
394 |
+
|
395 |
@app.get("/api/website_summarizer")
|
396 |
async def website_summarizer(url: str, proxy: Optional[str] = None):
|
397 |
"""Summarizes the content of a given URL using a chat model."""
|