|
import streamlit as st |
|
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, ToolCallingAgent, ManagedAgent, VisitWebpageTool |
|
|
|
|
|
web_agent = ToolCallingAgent( |
|
tools=[DuckDuckGoSearchTool(max_results=10), VisitWebpageTool()], |
|
model=HfApiModel(), |
|
) |
|
|
|
managed_web_agent = ManagedAgent( |
|
agent=web_agent, |
|
name="search", |
|
description="Runs tech web searches. Give it your query as an argument. Also, this agent should link to the sources you are using. If any specific sites are provided, this agent will only those sources.", |
|
) |
|
|
|
manager_agent = CodeAgent( |
|
tools=[], |
|
model=HfApiModel(model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"), |
|
managed_agents=[managed_web_agent], |
|
additional_authorized_imports=['pyparsing', 'matplotlib', 'datetime', 'statistics', 'bs4', 'request', 'unicodedata', 'queue', 'time', 'collections', 're', 'math', 'stat', 'random', |
|
'itertools'], |
|
) |
|
|
|
|
|
def log_agent_action(prompt, result, agent_name): |
|
st.write(f"### Agent Activity ({agent_name}):") |
|
st.write("**Prompt Sent to Agent:**") |
|
st.code(prompt, language="text") |
|
st.write("**Agent Output:**") |
|
st.code(result, language="text") |
|
|
|
|
|
st.title("AI Tech Assistant Agent researching your query and summarizing it") |
|
|
|
|
|
st.write("Generate reports enriched with real-time insights using the AI Tech Report Writing Agent powered by SmolAgents and DuckDuckGo.") |
|
|
|
|
|
|
|
prompt = st.text_area("Enter the your search query:", placeholder="E.g., What is the optimal specs for my computer? I am running normal desktop programs. I want my computer to be fast and efficient. Storage is not so important. Please, don't let it be too expensive. Also, let me know where I can buy the computer in Sweden.") |
|
|
|
|
|
if st.button("Generate Summary"): |
|
if prompt: |
|
with st.spinner("Generating content..."): |
|
try: |
|
|
|
result = manager_agent.run(prompt) |
|
|
|
st.subheader("Generated Summary:") |
|
st.write(result) |
|
|
|
|
|
log_agent_action(prompt, result, "Tech Research Agent with DuckDuckGo") |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
else: |
|
st.warning("Please enter a blog topic or prompt to proceed.") |
|
|
|
|
|
st.markdown("---") |
|
st.caption("Powered by SmolAgents, DuckDuckGo, and Streamlit") |
|
|