Spaces:
Sleeping
Sleeping
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files159 unmodified lines160161162163164165166167168169170171172173174175176177178179180181182183184159 unmodified linesRetrieves and formats a list of high-quality educational resources on astronomy and space science.Uses Tavily search to find trusted sources such as NASA, ESA, and other reputable platforms.Args:state (AgentState): The current agent state, containing user input.Returns:dict: A dictionary containing a list of educational resources with titles, descriptions, and clickable links.Raises:Exception: If an error occurs while retrieving the resources or formatting the response."""try:# Use Tavily search to retrieve educational resources based on the queryresources = search.invoke({"query": "Provide a curated list of high-quality educational resources on astronomy and space science, from trusted sources like NASA, ESA, and reputable educational platforms."})if not resources:return {"output": "No educational resources found. Please try again."}formatted_resources = "\n\n".join([f"π {r.get('title', 'Untitled Resource')}\nπ {r.get('url', 'No URL provided')}" for r in resources])return {"output": f"π Educational Resources Agent:\n\n{formatted_resources}"}except Exception as e:return {"output": f"Educational Resources Agent Error: {str(e)}"}159 unmodified lines160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192159 unmodified linesRetrieves and formats a list of high-quality educational resources on astronomy and space science.Uses Tavily search to find trusted sources such as NASA, ESA, and other reputable platforms.Returns:dict: A dictionary containing an informative summary and a list of educational resources with titles, descriptions, and clickable links.Raises:Exception: If an error occurs while retrieving the resources or formatting the response."""try:# Use Tavily search to retrieve educational resources based on the queryresources = search.invoke({"query": "Provide a curated list of high-quality educational resources on astronomy and space science, from trusted sources like NASA, ESA, and reputable educational platforms."})if not resources:return {"output": "No educational resources found. Please try again."}# Format each resource as a clickable link along with a descriptionformatted_resources = "\n\n".join([f"π **{r.get('title', 'Untitled Resource')}**\nπ [Visit Resource]({r.get('url', 'No URL provided')})" for r in resources])# Add an informative introduction generated by LLM or manually written textinformative_text = ("Based on your query, here is a curated list of high-quality educational resources on astronomy and space science. ""These resources have been carefully selected from trusted institutions such as NASA, ESA, and reputable academic platforms. ""They provide a wealth of knowledge on various space topics, including recent discoveries, research articles, and interactive educational materials.")full_response = f"π **Educational Resources Agent:**\n\n{informative_text}\n\n{formatted_resources}"return {"output": full_response}except Exception as e:return {"output": f"Educational Resources Agent Error: {str(e)}"}
app.py+16-8