Converting a table to single cell text block (Markdown, ReStructuredText or AsciiDoc)

I am making a Chat GPT component. I would like to have the option of including the input data table in with the users. GPT chat questions about it. Any ideas on how I can convert a table into a single string cell in a format that GPT would recognize as a table on the other end?

1 Like

For the second part of the question, ChatGPT should be able understand a block of cell if you provide it with the relevant info @iCFO

My goal is to be able to send over a block of code to GPT with the option of including the table in with the question. See the example below of a combined message that would be incorporated within a wider JSON request.

"You are playing the role of a data analyst. Below is a data table with missing values or incorrect spellings for US states in the “State” column. The values in the state column may also be abbreviated. Can you attempt to fill in the correct state with context from the other existing columns?

(the table info would then follow here)"

My current approach has been to attempt to include a concatenated JSON table within an wider JSON request to Chat GPT… This fails because characters need to be escaped in order to insert the JSON as a string within another JSON. (Which I am not really sure is the right approach to start with…)

If all else fails then I can create a setup that sends the table separately and then lets the user ask a followup question, but since that triggers a wasted response, it seems cleaner from a user perspective to ask a question with the option of including the table or not.

Chat GPT says that I can create nested JSON tables with wider JSON using nested dictionaries. It provided me some code in Python, but I am still struggling to get Python code to incorporate with input / output KNIME fields.

The nested JSON approach caused errors on the Chat GPT side even with the correct syntax.

Chat GPT helped me nail down a better approach to including a ChatGPT readable dataset with a question via API. (I Updated the thread title to better describe the challenge) I think that the more commonly used formats around here will be ReStructuredText or AsciiDoc since they are commonly used with Python’s Pandas library. Any tips or tools for converting tables to a single cell text block with either syntax?

@PTDataScientist - You mentioned working on an AsciiDoc converter in a thread about easily sharing KNIME results with outside people. Any ideas on an easy approach to convert entire tables and pass them downstream as a cell text block?

@iCFO - So far I’ve simply looped over a table and generated the corresponding AsciiDoc using a JavaSnippet. That’s what I like about AsciiDoc - that you can easily build your whole document bit by bit. If the input table is not too large that should work for you too I guess - should also be possible to convert that into a component without too much hassle…

See the uploaded workflow for a quick example:

A single “convert input table to AsciiDoc table” is on my list of ideas but I first need to find the time to finish an initial public relase of the AsciiDoc nodes at all… :confounded:


THANKS @PTDataScientist!

This AsciiDoc syntax was the key to prepping the API table portion of my GPT integration. I made a dynamic version of your AsciiDoc converter and put it on my hub in case you were interested. I had to add multiple escape characters after this component using regex replace before each formulas or json conversion to get the request to post correctly. Not sure how much data it can handle yet, but I will give it some harder challenges tomorrow.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.