Report

Simple Data Toolkit - Python - Loading Data and Text Through ChatGPT

November 09, 2024 at 5:42 PM UTC
This post has no media.
Profile picture
Franklin Powers

Simple Data Toolkit provides an API for passing data and text to ChatGPT and extracting related data or text. (At the time of this writing, the release of this is pending for complete support, but it is coming soon)

Below is an example which uses an embedded data of users and orders, plus text loaded in from a file.


from sdtk import com_sdtk_api_ChatGPTAPI, com_sdtk_table_ArrayOfMapsReader

#Set

def callbackData(reader):
print(reader.toArrayOfNativeMaps(None))

def callbackText(data):
print(data)

users = [
{"user_id": 1, "first_name": "Sally", "last_name": "Franklin"},
{"user_id": 2, "first_name": "Lucas", "last_name": "Franklin"},
{"user_id": 3, "first_name": "Joe", "last_name": "Romeo"},
{"user_id": 4, "first_name": "Julie", "last_name": "Romeo"},
{"user_id": 5, "first_name": "Lucia", "last_name": "Templeton"},
]

orders = [
{"order_id": 1, "user_id": 3, "item_desc": "Book 1", "item_quantity": 2, "date": "2024-01-01"},
{"order_id": 2, "user_id": 3, "item_desc": "Book 2", "item_quantity": 1, "date": "2024-02-01"},
{"order_id": 3, "user_id": 3, "item_desc": "Book 3", "item_quantity": 3, "date": "2024-03-01"},
{"order_id": 4, "user_id": 3, "item_desc": "Book 4", "item_quantity": 0, "date": "2024-04-01"},
{"order_id": 5, "user_id": 3, "item_desc": "Book 5", "item_quantity": 4, "date": "2024-05-01"}
]

com_sdtk_api_ChatGPTAPI.queryAsReaderWithDataAPI().execute("What can we determine about the buying habits of all of our users?", None, {"Users": com_sdtk_table_ArrayOfMapsReader.readWholeArray(users), "Orders": com_sdtk_table_ArrayOfMapsReader.readWholeArray(orders)}, callbackData)
com_sdtk_api_ChatGPTAPI.queryWithDataAPI().execute("What can we determine about the buying habits of all of our users? As a narrative.", None, {"Users": com_sdtk_table_ArrayOfMapsReader.readWholeArray(users), "Orders": com_sdtk_table_ArrayOfMapsReader.readWholeArray(orders)}, callbackText)

content = ""
with open('sample.html', 'r') as content_file:
content = content_file.read()

com_sdtk_api_ChatGPTAPI.queryWithDataAPI().execute("We also have this document in HTML format on recent trends.n" + content + "nnWhat can we determine about the buying habits of all of our users? As a narrative.", None, {"Users": com_sdtk_table_ArrayOfMapsReader.readWholeArray(users), "Orders": com_sdtk_table_ArrayOfMapsReader.readWholeArray(orders)}, callbackText)


Below is an example which queries data from ChatGPT in a table format using a DataTableReader from SDTK.

from sdtk import com_sdtk_api_ChatGPTAPI

def callback(data, reader):
print(reader.toArrayOfNativeMaps(None))

com_sdtk_api_ChatGPTAPI.queryAsReaderAPI().retrieveData({ "query": "List all cities in the USA with known population." }, callback)

Any thoughts on Franklin's post?

To comment or reply, you need an Ortingo account.

Sign in or sign up

Here's what Ortingoers think of Franklin's post.

There are no comments on this post.