Named Entity Recognition with Generative-AI

Straight to the point guys. This is an article on how to do Named Entity Recognition (NER) with Tiledesk and OpenAI. Sometimes you need to address a complex task during a conversation like asking to your end-user all the data (NER) needed to go on with the flow. For example, to get an appointment you need the week-day, a time slot selected from those available and the target office.

Suppose you would like to start a chat with a question like this:

And you want your chatbot to engage the user into a conversation like the following one with the minimum possible effort:

The hard part is how to tell ChatGPT something like:

“Please arrange a conversation with the user until you get all the required data, then tell me when the user provided all the data so I can move to the next step”.

With Tiledesk it’s very easy! It’s all about your prompt engineering skills that will move to a new level of power 🙂

The prompt

The main point is that you need something special to “iterate” on ChatGPT until the task is done using the same prompt. This is where a flow comes in to help you create the “rule”. A rule that is, we can say, recursive. And is something as simple as a prompt like the following one:

The OpenAI prompt is reported here for copy/paste purposes:

Analyze the conversation with the user and help him enter the necessary data to complete the operation. The data needed is:
slot day, slot time, office.
Available slots:
Monday slots: 10, 12, 14
Tuesday slots: 11, 13
Wednesday slots: 8, 9, 16
Offices: Support, Sales, Complaints
When the user has provided all the data, reply using the Reply Message below:
Thank you!

Reply to me with a JSON in this format:
{
    “slot_day”: "Slot day",
    “slot_time”: "slot time",
    “office”: "office"
    "response": YOUR RESPONSE FOR THE USER,
    "data_ok": true (boolean) when all required data is provided otherwise false (boolean)
}

Chat history and JSON reply

We asked OpenAI to always use the chat history, so OpenAI can know what data has already been provided during the conversation and managing it accordingly. But note, we always ask to reply with JSON data because we want back in the flow all the acquired data in a format suitable to be – for example – sent to a remote service. So don’t forget to always check the options accordingly:

We ask to fill the reply fields with appropriate data: slot_day, slot_time and office are the fields we are asking the user to fill up. The other two fields are instead functional to the conversation flow. The response field is delegated to always get the ChatGPT “human reply” for the user, while we use the last one, data_ok, to understand if the conversation with the user completed with all the necessary data and we can move on to the next steps.

Control the flow

The key in getting NERs (Named Entities Recognition) is that the converastion always loops checking for data_ok = true. We can say that while data_ok is false the conversation “loops” through the flow highlighted in the following picture:

Once OpenAI successfully completes the conversation with the user getting all data, data_ok will evaluate to true and the conversation moves to the final step where you can show the fulfilled data using the JSON “dot” notation from the gpt_reply attribute (that is a JSON object beheind the scenes):

{{gpt_reply.slot_day}} etc.

And as a last note: everything works on the gpt-4o-mini model! To maximize your tokens savings!

Tiledesk community

Now you would like to have this chatbot with just one click on your project right? You’re right. It’s published on our AI Agents community and is available for free! Follow the link and click on the Import button to get it directly into your project!

https://tiledesk.com/community/search/getchatbotinfo/chatbotId/673f478ad05bcb0012438f9b-GPT-Complex-task–find-a-slot-

Feel free to discover all of my chatbots and automation flows in my personal community page!

https://tiledesk.com/community/search/getdesigner/63a05d755f117f0013541383-Andreas%20Sponziello

Do you want to be part of our Automation flow Designers Community? Join Tiledesk today and publish your first chatbot!

Andrea
Andrea
Tiledesk founder. Coding chatbots as hobby. Working with my team to create the best Conversational Apps Development Platform - aka Tiledesk

Leave a Reply

Discover more from Tiledesk

Subscribe now to keep reading and get access to the full archive.

Continue reading