Get to the Point

Author Picture

Çağrı Gökpunar

Analyst / Developer / Artist

www.cagrigokpunar.com

Nov 2024

This page has been viewed 496 times.

Share Buy me a coffee

News sites often bury the main details under piles of redundant info, making it tough to find what you actually want to know. That’s why I built “Get to the Point” (or Sadede Gel in Turkish)—an LLM-powered tool that cuts through the clutter to quickly retrieve and summarize essential information from news sources. This project uses the LangChain framework to make integration with large language models (LLMs) easy, and it taps into SerpApi’s Google News endpoint for targeted Turkish-language news searches. The tool’s workflow is simple: get a query, pull up relevant articles, summarize the content, and present a clear, concise answer.

Go back to the blogs

I don't know if it is for the SEO (search engine optimization) or not; news sites throw an annoying amount of redundant text before explaining what I am looking for. Check out the following case: I directly copied the text from a news page and translated to English for the sake of this blog post.

What am I looking for

When is the midterm break?

What I got

MIDTERM HOLIDAY DATES OF 2024 📍 When will the first midterm break be held in schools? Here are the midterm break dates for November and April...

# Midterm Break 2024
# Midterm Break 2025

The Ministry of National Education announced the midterm break dates. The 2024-2025 midterm break calendar is always on the agenda of students. Millions of students want to know when the midterm break starts and ends. Here are the midterm break dates that will be applied in November and April...

MIDTERM HOLIDAY DATES OF 2024 📍 When will the first midterm break be held in schools? Here are the midterm break dates for November and April...

The midterm break dates that are of particular interest to primary school, middle school and high school students have been announced. When does the midterm break, which has been on the agenda since we are halfway through October, start and end? The plans for the midterm break dates of November 2024 and April 2025 are in our news...

WHEN DOES THE MIDTERM BREAK START, WHEN DOES IT END
WHEN DOES THE MIDTERM BREAK START, WHEN DOES IT END?

The November break will be held on November 11-15, 2024.

I think you can see how annoying this is. That would be useful if I had a tool retrieving this information for me.

Besides the practical reason, it is fun making LLM applications. The LangChain framework makes it super easy to work with LLMs.

Process

The beginning strategy I had in mind was like this, and I followed these steps:

  1. Get query from user
  2. Send request to search API
  3. Get links from the API
  4. Send get requests to the link to get the information
  5. Summarize using LLM
  6. Output

Tools

I knew about tavily, but their search API is not great for Turkish results. After some research, I have discovered SerpApi, which has a specific Google News endpoint with language and region parameters. For our LLM agent to use, I have created search and request tools first.

google_news_search

@tool
def google_news_search_tr(query):
    """
    From the given query, returns the news results from Google News in Turkish.
    """

    params = {
        "api_key": os.getenv("SERPAPI_API_KEY"),
        "engine": "google_news",
        "hl": "tr",
        "gl": "tr",
        "q": query,
    }

    search = GoogleSearch(params)
    results = search.get_dict()

    news_results = results["news_results"]

    return news_results

send_get_request

@tool
def send_get_request(url):
    """
    Sends a GET request to the given URL and returns the response.
    """
    response = requests.get(url)

    return response.text

After some testing, I have noticed that the agent can get the results without reaching the page content.

One hallucination I have encountered was the agent projecting the past events like they are going to happen in the future if there is no recent news about them.

When is the Ramadan Feast? (An important holiday in Turkey)

Ramadan Feast will be on April 10, 2023.

The current date is November 9, 2024. The answer should contain a date from the future. So I created a tool for this case.

next_religious_holiday

@tool
def next_religious_holiday(name):
    """
    Get the next religious holiday date. Input should be either 'sacrifice' or 'ramadan'.
    """ 
    holidays = [
        {"name": "ramadan", "date": "2024-04-10"},
        {"name": "sacrifice", "date": "2024-06-16"},
        {"name": "ramadan", "date": "2025-03-30"},
        {"name": "sacrifice", "date": "2025-06-06"},
        {"name": "ramadan", "date": "2026-03-20"},
        {"name": "sacrifice", "date": "2026-05-27"},
        {"name": "ramadan", "date": "2027-03-09"},
        {"name": "sacrifice", "date": "2027-05-16"},
    ]

    current_date = datetime.now()
    for holiday in holidays:
        holiday_date = datetime.strptime(holiday["date"], "%Y-%m-%d")
        if holiday["name"] == name.lower() and holiday_date > current_date:
            return f"The next {name.capitalize()} Feast is on {holiday_date.strftime('%B %d, %Y')}."

    return f"No upcoming {name.capitalize()} Feast found."

Prompting

I have used ReAct Prompt and tuned it a little.

template = """
Answer the following questions as best you can by searching first and getting data from these search results.
The question will be in Turkish. Do not make translations. Directly use the question text for the search.
You can use the search results to answer the question.

Currently, the date is {current_date}.

In the search results, you are able to see the name of the news source. At the end of your answer, include it in parentheses.

You have access to the following tools:

{tools}

IMPORTANT: For the Action and Action Input format:
- Action should ONLY contain the tool name (like "next_religious_holiday" or "google_news_search_tr")
- Action Input should contain the parameter value (like "sacrifice" or "ramadan")
- DO NOT include parameters or quotes in the Action field

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!

Question: {input}
Thought: {agent_scratchpad}
"""

If you are curious about what ReAct is, check this famous paper: ReAct: Synergizing Reasoning and Acting in Language Models.

Result

After a hard half-days work, I present you Get to the Point (or Sadede Gel in Turkish), a summarizer tool for reaching conclusions rapidly on current topics.

What Can Be Done Next?


Go back to the blogs