Update app.py
Browse files
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 = "
|
343 |
-
max_results: int =
|
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 |
-
|
360 |
-
|
361 |
-
|
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 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
f"
|
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})
|