Any Suggestions on How To Incorporate LLM Models into Editor Tables
Any Suggestions on How To Incorporate LLM Models into Editor Tables
Niko@1966
Posts: 16Questions: 7Answers: 3
I have a table that I can view through editor. I have text fields in the table that I want to have an AI model scan for key words and then characterize them into buckets. I can make it work by free typing into an HTML form. However I am having trouble integrating it with DataTables structure. Any insights would be greatly appreciated.
This question has an accepted answers - jump to answer
Answers
How do you do that? Doing it with Editor will be very similar, once you have access to the
textarea
element. You can get that element using thefield().input()
method - e.g. perhaps something like:Allan
The important bit there is that the LLM model will "scan for key words". How does it do that scan? Do you point it towards a
td
element, or is there a class on thetd
or an element within thetd
that says scan this? And when you say free typing into a HTML form - is that just a direct interface into the LLM, similar to the ChatGPT typing area?Colin
i am trying to do it through the server script. I am trying to connect the model to the table via the server script and then have it display the categorized word results on the front end html. Is this the right approach or should I try something different?
That sounds okay. You just need to have an Ajax request to your server-side script, passing the server the value from the input (
field().val()
) and have it process the data and then display the results.How do you do it currently? You said you had it working with an existing input.
Allan
The existing was just a simple stand alone html form with an input box to type text into. I used that to test out the connection to the model and it worked. It would read the words, characterize them and then sort them based on type of word. Now I need to make that work for my database tables.
I am able to connect to the GPT model and I can characterize the words in multiple text boxes and I can display the results in the front end table. This part works great. Where I am stuck at right now is getting the categorized results to insert into a separate table before it is displayed on the front end. When I get the data to insert I only want the PHP code to return data for id values that do not exist in the insert table. My code is below.
```
<?php
// Include the DataTables PHP library and necessary classes
include("../lib/DataTables.php");
// Alias Editor classes for easier use
use DataTables\Editor;
use DataTables\Editor\Field;
// Function to send data to OpenAI API and categorize it
function categorizeText($text, $fieldType) {
if (is_null($text) || $text === '') {
return 'Fields Empty';
}
}
// Build the Editor instance and process the data coming from _POST
$editor = Editor::inst($db, 'equipment_wo_view_c')
->fields(
Field::inst('equipment_wo_view_c.cid'),
Field::inst('equipment_wo_view_c.id'),
Field::inst('equipment_wo_view_c.work_description'),
Field::inst('equipment_wo_view_c.priority_comments'),
Field::inst('equipment_wo_view_c.closed_marker_comment'),
Field::inst('equipment_wo_view_c.status_found_comment'),
Field::inst('equipment_wo_view_c.status_finished_comment'),
Field::inst('equipment_wo_view_c.work_comment')
)
->where(function ($q) {
$q->where('equipment_wo_view_c.cid', $_SESSION['update_cid']);
})
->process($_POST);
// Get the data
$data = $editor->data();
// Categorize each work description and work comment and add it to the data
foreach ($data['data'] as &$row) {
$row['equipment_wo_view_c']['description_category'] = categorizeText($row['equipment_wo_view_c']['work_description'], 'description');
$row['equipment_wo_view_c']['priority_category'] = categorizeText($row['equipment_wo_view_c']['priority_comments'], 'priority');
$row['equipment_wo_view_c']['closed_category'] = categorizeText($row['equipment_wo_view_c']['closed_marker_comment'], 'closed');
$row['equipment_wo_view_c']['found_category'] = categorizeText($row['equipment_wo_view_c']['status_found_comment'], 'found');
$row['equipment_wo_view_c']['finished_category'] = categorizeText($row['equipment_wo_view_c']['status_finished_comment'], 'finished');
$row['equipment_wo_view_c']['comment_category'] = categorizeText($row['equipment_wo_view_c']['work_comment'], 'comment');
}
// Return the JSON data
<?php > ``` ?>echo json_encode($data);
Sorry, false alarm. I just got it to work. The issue was a mismatch between variable type I needed to insert and the variable type in the table.