Tinderbox and the OpenAI API

Damned! If it’s not aesthetic, is it logarithmic… mathematical… geometric? What else? Is that a real coincidence that the links have been disposed in such a concordant arrangement? Your notes seem to be at an equal distance from each other. Does this explain that?

I didn’t touch the links - but I arranged the notes by hand.

OK. That’s what I was “suspecting”. A mathematician, I guess, would explain this geometric arrangement.

The placement of link lines derives in part from the relative position of the notes. The latter are, I think, already positioned in the demo file in an aligned cross-shaped layout. Try less gridded positioning of the notes and then see how he links are placed.

I suspect what you see is a happy accident—but it is no less pleasing for being so. :slight_smile:

1 Like

Pretty Marvelous Detlef.

Question: How would I add to the code if I wanted OpenAI to give me the concepts of the text in an attribute IN ADDITION to the keywords?

Tom

Hi Tom,

you need to make two calls to OpenAI - with two different prompts.

I tried “extracts the concepts of the text” and got “1. walter benjamin;10. literary conferences;11. special journal issues;12. rising interest in continental philosophy;13. british and american literature;14. new media studies;2. the arcades project;3. charles baudelaire;4. flâneur;5. high capitalism;6. the age of mechanical reproduction;7. undergraduate classroom;8. scholarly discourse;9. harvard university press”

for a sample text.

The function callOpenAI_db now uses the attribute $OpenAI_Prompt for the prompt. If you need two calls to OpenAI for one note you need to modify the functions a little bit. You know how???

Detlef

No, I do not know how to do this, I am having trouble reading the code. If you could help by creating a new demo more comments using the concepts you just did, I think it will help me, especially. I will study the code and compare.

Thanks Detlef.

here you go…

Now callOpenAI_db(thePayLoad, theType, thePrompt) needs a third parameter - the prompt for OpenAI. Before the function used the $OpenAI_prompt attribute and this appears only once for each note.

The demo works like before - there is an $Edict attached to the prototype and there a function runOpenAIKeywordExtractor_db() will be called. No change needed here.

But now you have the option to call the function callOpenAI_db twice with different prompts. Like:

var:string result1 = callOpenAI_db($Text, 2, "Extract not more then 15 of the most significant keywords from this text as comma seperated values");
var:string result2 = callOpenAI_db($Text, 2, "extracts the concepts of the text");

OpenAI-Demo_Keywords_image.tbx (250.5 KB)

3 Likes

Thanks Detlef, I have to run some errands with my son, but will try it later this afternoon when I return. Many thanks for your assistance and thank you for your work with Tinderbox and OpenAI!

Tom

You can use the OpenAI functions as a universal interface to OpenAI. The only function you need to know:

callOpenAI_db(Text, Type, Prompt)

If the Type has been set to “1” the returned data from OpenAI will be processed to retrieve the keywords. So this one is specific to this task. Typical call would be:

var:string myKeywords = callOpenAI_db($Text, 1, "Extract not more then 15 of the most significant keywords from this text as comma seperated values");

If the Type has been set to “2” there will only be a very basic processing of the data. So this is an approach you should be able to use in a more universal way. For example:

var:string myConcepts = callOpenAI_db($Text, 2, "extracts the concepts of this text");

Since I focused on keywords - there is some additional functionality. I build a prototype “pOpenAI” and in the $Edict of this prototype you finde a call to runOpenAIKeywordExtractor_db();

This function will monitor two attributes of a note: $OpenAI_Tags and $OpenAILinkRun. Only if the attribute $OpenAI_Tags is empty and $OpenAILinkRun is false the OpenAI API will get called. If $OpenAILinkRun is false but $OpenAI_Tags is not empty only the links from this note will be rebuild.

But you need the runOpenAIKeywordExtractor_db() stuff only if you are looking for the keyword extraction.

For example if you would like to retrieve the concepts of all notes you would create a new prototype, add a new attribute $OpenAI_concepts and add this to the $Edict:

if ((!$IsPrototype) & ($OpenAI_concepts == "")) {
   $OpenAI_concepts = callOpenAI_db($Text, 2, "extracts the concepts of this text");
};

If you apply your new prototype to a note, whenever the attribute $OpenAI_concepts is empty the OpenAI API will be called to process this note and return the concepts.

Hope this helps!

2 Likes

:clap: from the sidelines to @webline for the all the effort here to help other people. Much appreciated!

1 Like

Thanks Detlef. your code works! thank you!

Two quick questions

  1. How do I get rid of the “\d.\s” pattern in front of each concept:
    OpenAI_concepts: 1. Concept1; 2. Concept2; 3. Concept3; → Concept1;Concept2;Concept3;

  2. How do I link to the concepts instead of keywords?

Thanks again for all your patience and explanations. You have been awesome. :slight_smile:
Tom

Hi Tom,

(1) you need to write a “cleaner” function. Take a look into the getJSONpartOpenAI_db() function. This is where I clean up the keywords. To find the leading number and point with regex would be "[0-9]*. "
(2) this time you should look into processOpenAI_Keywords_to_Links_db()…

Best,

Detlef

1 Like

very minor change for anyone else following along and trying it:
image

Thank you Detlef for your wonderful code! I now am understanding the functions are following functional coding rules

Tom

1 Like

I’ve been using Tinderbox for a while but this option with OpenAI is really interesting.

Danke Detlef und Grüße nach Köln
Andreas

1 Like

Hallo Andreas,

yes - OpenAI offers a lot of potential use cases. There are many other AI solutions out there. Beside of OpenAI I would like to see the option to load and use Apples ML models in Tinderbox.

Other engines like Jasper.ai (nice, but expensive, uses OpenAI itself), Bing (OpenAI again) or Midjourney (expensive, best quality AI images) are not as powerful for a text based environment IMHO.

Liebe Grüße zurück,

Detlef

By the way GPT-4 is now public - before you had to be in a closed user group.
If you like - my sample works fine with GPT-4 too. You just have to change the attribute “OpenAI_Model” in the gAIPreferences note to “gpt-4”.

The result are not the same :wink:

3 Likes

It came to my mind that you might be able to instruct the LLM to deliver the result in a sepcific form – e.g. without the numbers.

Pretty slick Detlef working out how to change the model w just one change to the gAIPreferences. Thank you.

Just an observation
3.5 turbo is quite a bit faster than gpt-4 but gpt-4 has better information but significantly slower.

Many thanks from the community for this groundbreaking work. Fun
Tom

1 Like

and GPT-4 is more expensive - for my work 3.5 is the better alternative. But it is interesting to see the different results!

2 Likes