I created a demo file that implements a function using CURL to call the OpenAI API.
The first thing you have to do is create a free account at https://platform.openai.com.
Then you need to create an API key: OpenAI API
Copy the key into the OpenAI_Key attribute of the gPreferences note.
Then you are ready to test the OpenAI interface. Select one (or more) of the „myJsonX_raw“ notes and apply the „getKeywordWithAI“ stamp to the note. Wait a few seconds and you should see the keywords in the OpenAI_tags attribute of the selected note.
To retrieve keywords from a text is only one possible use case. The stamp „getKeywordWithAI“ has been created for this specific task: get the keywords of a text.
There is a 2nd Stamp called „getAnswerWithAI“ with a more universal approach. The results are always added to the note „debug“ (change that to your needs).
I created a prototype called „pOpenAI“ and all the demo notes („myJsonX_raw“) use this prototype. There are several attributes to control the OpenAI engine. The most important one is „OpenAI_task“. Here you specify what OpenAI should do for you. The better you define your task, the better the result will be. Possible options for this task are unlimited. For example „get the short bio of“ or „select all cities found in the following text“ or „correct the spelling of the following text“… The text of the note is the target of the task and will be delivered together to the OpenAI engine. So if you enter „get the short bio of“ into the „OpenAI_task“ attribute of a note, the text of this note should contain the name of the person you are looking for. It should be easy to adjust those inputs to your individual Tinderbox structure. The attribute „OpenAI_Max_Tokens“ is also important. A text will be broken into tokens by OpenAI. A token is more or less equal to a syllable. If you limit „OpenAI_Max_Tokens“ to 100 only 100 tokens will be processed. For a longer text you have to increase this value.
You find all the code needed in the note „cOpenAI“. I use CURL and the runCommand action code to communicate with the OpenAI API. The function „callOpenAI_db“ creates the CURL command for you. There should be no need to alter this function. You have to call the function with two parameters: the text to work with (the $Text of a note) and a type parameter. Use 1 if you like to extract keywords and 2 for anything else. See both stamps to get an example how to call the function.
The function „buildOpenAIPayload_db“ is the place where I add the parameters to be passed with the CURL command. And that’s the place where you should adjust the code to your specific needs. Everything else is just Tinderbox stuff like creating links or removing text from the returned data.
Have fun,
Detlef
OpenAI-Demo.tbx (294.1 KB)