Spaces:
Paused
Paused
Update app.py
Browse files338 unmodified lines3393403413423433443453468 unmodified lines3553563573583593603613623633643653663673684 unmodified lines373374375376377378379380381382383384385386387388389338 unmodified lines@app.get("/api/adv_web_search")async def adv_web_search(q: str,model: str = "gpt-4o-mini",max_results: int = 5,timelimit: Optional[str] = None,safesearch: str = "moderate",region: str = "wt-wt",8 unmodified linestry:with WEBS(proxy=proxy) as webs:# 1. Perform the web searchsearch_results = webs.text(keywords=q,region=region,safesearch=safesearch,timelimit=timelimit,backend=backend,max_results=max_results)# 2. Extract text from top search result URLs asynchronouslyextracted_text = ""4 unmodified linesextracted_text += f"## Content from: {result['link']}\n\n{result['text']}\n\n"# 3. Construct the prompt for FastAIai_prompt = (f"User Query: {q}\n\n"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"f"1. **Answer:** Provide a clear and comprehensive answer to the user's query.\n"f"2. **Details:** Include any additional relevant details or explanations.\n"f"3. **Sources:** List the sources of the information with clickable links for further reading.\n\n"f"Search Results:\n{extracted_text}")# 4. Get the AI's response directly using webs().chatresponse = webs.chat(keywords=ai_prompt, model=model)# 5. Return the resultsreturn JSONResponse(content={"response": response})338 unmodified lines3393403413423433443453468 unmodified lines3553563573583593603613623633644 unmodified lines369370371372373374375376377378379380381338 unmodified lines@app.get("/api/adv_web_search")async def adv_web_search(q: str,model: str = "llama3-8b",max_results: int = 3,timelimit: Optional[str] = None,safesearch: str = "moderate",region: str = "wt-wt",8 unmodified linestry:with WEBS(proxy=proxy) as webs:# 1. Perform the web searchsearch_results = webs.text(keywords=q, region=region,safesearch=safesearch,timelimit=timelimit, backend=backend,max_results=max_results)# 2. Extract text from top search result URLs asynchronouslyextracted_text = ""4 unmodified linesextracted_text += f"## Content from: {result['link']}\n\n{result['text']}\n\n"# 3. Construct the prompt for FastAIai_prompt = f"Query by user: {q}. Answer the query asked by the user in detail. Search Result: {extracted_text}"# 4. Get the FastAI's response using FastAI servicetry:response = await asyncio.to_thread(fastai, ai_prompt, model=model, system=system_prompt)except Exception as e:raise HTTPException(status_code=500, detail=f"Error during FastAI request: {e}")# 5. Return the resultsreturn JSONResponse(content={"response": response})
app.py+13-21