How to use LLMs with up-to-date data: implementation guide

author

Yaroslav Rushchak

Engineering Manager
in this article:

What’s a Rich Text element?

The rich text element allows you to create and format headings, paragraphs, blockquotes, images, and video all in one place instead of having to add and format them individually. Just double-click and easily create content.

Static and dynamic content editing

A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel.

  1. my first list item
  2. asfsdf
  3. fweg
  4. we
  • Voila!
  • asfawgwrgaw
іфвфіафа

How to customize formatting for each rich text

Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector

system.

вапва

teast

It's good to use large language models to solve our daily needs. It's even better to use products like ChatGPT, which can access real-time data from the web to answer your questions. 

But it would be great if you could use LLM via API with access to real-time data from the web. In this article, I will describe my steps to achieve this. Let’s go! 

Idea

My primary task was to find the upcoming dates for events like concerts and festivals. 

However, this solution can be used to retrieve any kind of information.

Implementation

For this task, I've mostly used Python and Jupyter notebooks. However, programming language is not the main factor here. Our primary instruments are LLMs. 

I used GPT-3.5turbo and GPT-4 from OpenAI (they are available via their API). Also, I used SerpAPI + BeautifulSoup to get real-time data from the web.

Get the data

At first, I created a search query that returns the most appropriate search result. For me, the most effective was this simple search query format: “event name, event location, dates 2024.”

Then, I tried to get the data from the top 5 web pages from those search results:

  • SerpAPI to get search results
  • BeautifulSoup to get the content from each individual website

Once the data is ready, we can analyze it.

Analyze with AI

As I mentioned before, I was trying to get the upcoming dates for the specific event.

I used a GPT-3,5 (the cheapest) model and a custom prompt to determine whether website data contains upcoming dates for the event I'm looking for. The result of this call was the event date that LLM extracted from input data. 

Here comes the most interesting part: since it is used via API, there is no human validation of whether the dates are correct. And we all know that LLMs are sometimes prone to hallucinations, which was not acceptable in my case.

So the next step is…

Validation of the results

I used the GPT-4 model (the most advanced at the moment) with a custom prompt on the same data used in the previous step to check if the dates found by GPT-3 are correct. 

You won't believe how many times this validation failed due to dates found in the past or not related to this event. That’s why I highly recommend not to miss this step.

But still, those results were not good enough.

Two-step verification

This step is essential to ensure the dates are correct and the results can be trusted. I repeated this verification for all found dates.

We consider correct only the dates that match from two or more sources (in our case, event websites). Once a match occurs, the event date counts as found, and the task is finished.

Two-step verification is essential since it decreases the error rate. For example, in this project, the error rate was reduced from more than 20% to less than 2% — which is less than the error rate provided by people. 

Results

The main result is a fully automated algorithm for finding upcoming dates for events without human supervision. It has worked great in a production environment for almost half a year, and we continue to use it. 

I hope you'll find this guide helpful while using AI for your needs. Stay tuned for more! 

See more: How we build an AI-powered search chatbot for a cruise travel company

By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.