26.5 C
Wednesday, May 29, 2024

Laravel and the Open-Ai API Query Type Function


This post shows how to tag articles with the LLM using the OpenAi Query Function. An actual-world example from their Open-Source project, LLMAssistant, is given by the author. More chores will eventually be automated, such as categorizing tasks according to the Bullet Journal technique. However, as OpenAi noted, there are dangers connected to SQL creation. The author also briefly discusses two functions they’ve created, “Get Existing Tags Function” and “Tag Article Function.”

I’ll demonstrate how to query the database using the OpenAi Query Function after this post. This example will make use of tags, and the LLM will be tasked with selecting 1-3 tags that appear to fit the article from among the current tags. Then it will add 1-2 more that could be pertinent.

This is a simple but accurate example that I’ve started using in my open-source LLMAssistant project.

Future versions of this system will hopefully handle more “code,” like inserting examples of certain tags. I’d like the LLM to assist me with planning my week and month using the Bullet Journal system.

Although it may seem counterproductive to the idea of bullet journaling, I’m eager to try this experiment. Overall, rather than just coding it myself, it’s a trial run on when and how to utilize the LLM.

As stated in the OpenAi Cook Book link, “SQL generation can be high-risk in a production environment since models are not perfectly reliable at generating correct SQL.” This is an important thing to think about. LLMAssistant is a solo project at the moment, but given the LLM’s knowledge with Eloquent, I’m thinking about asking it to utilize ORM-based queries rather than raw ones.

Function for Get Existing Tags

Although I can easily code this function manually, I’m eager to use the LLM more and do less hand coding. It’s possible that in the future, the query may be customized to the content and will use a vector-based dataset to find or even generate appropriate tags.

For better or worse, as mentioned in the articles before, I create “helper” methods in Laravel, connect them to the actual Call, pass in a consistent Data Object, and have them return the model Message. I can link these functions together as a result. To track down the code, look in the ‘app/helpers.php’ file.

Article Tag Function

The LLM is given instructions by this function on how to format the data the system needs. The remainder, such as tag creation or discovery, is subsequently handled by the system. This once again demonstrates the LLM’s capacity to format data for parameters.

Final Effects
I send emails to the assistant every day as part of my routine. There are links in these emails. The “get_content_from_url” method is used by the assistant, as was indicated in earlier articles. Using the following prompt right now:

It gives the LLM a tip to use the functions that are associated for the item that I send.

The result is the article with tags you see below:

The “Reply” section offers explanations for the selection of the tags:

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles