In today's fast-paced world, keeping up with the latest news in a particular field can be challenging. What if we could harness the power of generative AI and agents to create a personalized news aggregator that runs entirely on local machines? In this article, we'll explore how to useOllamaof the Llama 3.2 model,SwarmPerform proxy scheduling, andDuckDuckGoConduct a web search to build such a system.
The Power of Local AI
With the rise of large-scale language models, we are now able to run complex AI systems on our personal computers. This opens up endless possibilities for creating tools that are customized for our specific needs. Our news aggregator is a perfect example of this potential.
Components of our system
- Ollama with Llama 3.2 : This is the heart of our system, powering our AI agents.
- Swarm : An agent orchestration framework that allows us to create and manage multiple AI agents.
- DuckDuckGo Search :: Provide up-to-date web search results without tracking user data.
Working Principle
Our news aggregator consists of two main AI agents:
- News Assistant : Use DuckDuckGo search to get the latest news articles on specific topics.
- Editorial Assistant : Review and refine the news collected for final presentation.
Let's break down the workflow:
1. Setting up the environment
ollama pull llama3.2
export OPENAI_MODEL_NAME=llama3.2
export OPENAI_BASE_URL=http://localhost:11434/v1
export OPENAI_API_KEY=any
pip install git+https://github.com/openai/swarm.git duckduckgo-search
We start by importing the necessary libraries and initializing our Swarm client:
from duckduckgo_search import DDGS
from swarm import Swarm, Agent
from datetime import datetime
current_date = datetime.now().strftime("%Y-%m")
client = Swarm()
2. Creation of a news search function
We define a function to search for news using DuckDuckGo:
pythondef get_news_articles(topic).
ddg_api = DDGS()
results = ddg_api.text(f"{topic} {current_date}", max_results=5)
if results.
news_results = "\n\n".join([f "Title: {result['title']}\nURL: {result['href']}\nDescription: {result['body']}" for result in results])
return news_results
else.
return f "Could not find news results for {topic}."
3. Defining our AI agents
We create two agents using Ollama's Llama 3.2 model:
news_agent = Agent(
model="llama3.2",
name="News Assistant", instructions="You provide the latest news articles for a given topic using DuckDuckGo search.
instructions="You provide the latest news articles for a given topic using DuckDuckGo search.", functions=[get_news_articles], news_agent = Agent(
functions=[get_news_articles], )
)
editor_agent = Agent(
model="llama3.2", name="Editor Assistant", functions=[get_news_articles], )
model="llama3.2", name="Editor Assistant", instructions="You review and finalize
instructions="You review and finalize the news article for publishing.",)
)
4. Harmonization of workflows
We define a function to run our news aggregation workflow:
def run_news_workflow(topic).
# Fetch news
news_response = client.run(
agent=news_agent,
messages=[{"role": "user", "content": f "Get me the news about {topic} on {current_date}"}], )
)
raw_news = news_response.messages[-1]["content"]
# Pass news to editor for final review
edited_news_response = client.run(
agent=editor_agent,
messages=[{"role": "system", "content": raw_news}],]
)
print(f"{edited_news_response.messages[-1]['content']}")
5. Operational systems
Finally, we can run our news aggregator for any topic of interest:
run_news_workflow("AI in Drug Discovery")
Full code : app.py
from duckduckgo_search import DDGS
from swarm import Swarm, Agent
from datetime import datetime
current_date = datetime.now().strftime("%Y-%m")
# Initialize Swarm client
client = Swarm()
# 1. Create an Internet search tool
def get_news_articles(topic).
print(f "Doing a DuckDuckGo news search for {topic}...")
# DuckDuckGo search
ddg_api = DDGS()
results = ddg_api.text(f"{topic} {current_date}", max_results=5)
if results.
news_results = "\n\n".join([f "title: {result['title']}\n url: {result['href']}\n description: {result['body']}" for result in results])
return news_results
else.
return f "Failed to find news results about {topic}."
# 2. Create the AI agent
def transfer_to_editor_assistant(raw_news):
print("Passing article to editor assistant...")
return editor_agent.run({"role": "system", "content": raw_news})
# News agent to get news
news_agent = Agent(
model="llama3.2", name="NewsAssistant", "news_agent" = Agent(
name="NewsAssistant",
instructions="You provide the latest news articles about the given topic using DuckDuckGo search." ,
functions=[get_news_articles], )
)
# Edit agent to edit news
editor_agent = Agent(
model="llama3.2",
name="editor_agent",
instructions="You review and finalize news articles for publication." ,
)
# 3. Create the workflow
def run_news_workflow(topic).
print("Running the news agent workflow...")
# The first step: get the news
news_response = client.run(
news_response = client.run( agent=news_agent,
messages=[{"role": "user", "content": f "Get news about {topic} at {current_date}"}], )
)
raw_news = news_response.messages[-1]["content"]
print(f "Fetched news: {raw_news}")
# Step 2: Pass the news to the editor for final review
edited_news_response = client.run(
agent=editor_agent,
messages=[{"role": "system", "content": raw_news}],]
)
print(f"{edited_news_response.messages[-1]['content']}")
# Example of running a news workflow for a given topic
run_news_workflow("AI in Drug Discovery")
sample output
Running news Agent workflow...
Running DuckDuckGo news search for AI in Drug Discovery...
Fetched news: Here's a formatted answer based on the news articles.
**Artificial Intelligence in Drug Discovery: A Revolutionary Transformation
The role of Artificial Intelligence (AI) in drug discovery marks a revolutionary shift in pharmaceuticals.AI utilizes complex algorithms to make autonomous decisions, augmenting human capabilities from data analysis rather than replacing them.
**Challenges and Limitations**
Despite promising advances, challenges and limitations remain in the field. The paper "The Role of AI in Drug Discovery" explores these issues, highlighting the need for high-quality data, the resolution of ethical issues, and an awareness of the limitations of AI-based approaches.
**AI in Drug Discovery**
AI has the potential to play a key role in drug discovery, design, and the study of drug-drug interactions.Applications of AI in drug discovery include:
* Multi-target pharmacology: AI can predict the effectiveness of compounds against multiple diseases.
* Chemical synthesis: AI can optimize chemical synthesis processes for faster and more efficient production.
* Drug repositioning: AI can identify new uses for existing drugs.
* Predicting drug properties: AI can predict the potency, toxicity and physicochemical properties of compounds.
** The Future of AI in Drug Discovery
As AI continues to evolve, it is expected to have a significant impact on the pharmaceutical industry.Successful application of AI will depend on the availability of high-quality data, resolution of ethical issues, and awareness of the limitations of AI-based approaches.
Benefits of Local AI News Syndication
- private business : All processing takes place on your local machine, ensuring that your data stays in your own hands.
- customization : You can easily modify an agent's instructions or add a new agent to meet your specific needs.
- Latest Information : By searching with DuckDuckGo, you always get the latest news on the topic of your choice.
- AI-driven curation : The editorial assistant helps refine and organize the collected news to provide a more polished final output.
reach a verdict
This local AI-powered news aggregator demonstrates the potential of combining large-scale language models with web search capabilities. By utilizing Ollama's Llama 3.2 model, Swarm for agent orchestration, and DuckDuckGo for search, we have created a powerful tool that allows us to stay informed on any topic of interest while maintaining our privacy and running entirely on our local computers.
As AI continues to evolve, the possibilities for creating personalized, AI-powered tools will only continue to expand. This news aggregator is just the beginning - imagine what other innovative applications you could build with these technologies!