Here is how the code works:
There is the example code (Main module) and the OpenAI library (OpenAI module).
The flow starts with a user clicking on a button in the UI.
List Assistants / Select Assistant button for example.
This calls the Sub btnListAssistants_Click.
The Sub btnListAssistants_Click calls the Sub ShowTable("Assistant List"). This sub sets up the table to show the list of Assistants.
Next, the Sub btnListAssistants_Click calls the Sub ListAssistants in the OpenAI module.
The Sub ListAssistants calls the OpenAI API with a Job.Name created in the Sub.
The response from OpenAI is in JSON format and has an object name among other details.
The Sub JobDone in the OpenAI module receives the response from OpenAI.
The Job.Name is Selected by Select...Case.
The first Select...Case checks for speech and image response. They have special handling because they will next return a non-JSON object.
The second Select...Case falls into a Case that has many job names.
This Case is needed so that the object in the JSON response will be changed to the Job.Name.
The reason for this is because the OpenAI API returns the same object name for many calls to the API. In this example the returned Object is "list".
This is not helpful because we need a unique object in the Main module. So, the Object is changed to the Job.Name so it will be a unique object.
The Sub Job.Done in the OpenAI module calls the Sub OpenAI_Response in the Main module and passes the same JSON that came down from the OpenAI API with the modified object.
The Sub OpenAI_Response in the main code Selects on the object using Select...Case. In this case "ListAssistants" is the modified object.
The code in the Sub OpenAI, Case "ListAssistants" callse the Sub ParseAssistantList.
The Sub ParseAssistantList parses the returned JSON and creates rows in the table that was set up earlier.
The table shows the list of Assistants and the job is done.
This is the typical loop that the code follows.
There is also a google search option that I added to the Main module. The reason for the google search part of the code is because there is a cutoff date on the knowledge in OpenAI. Anything that occurred after the knowledge cutoff date can be added to the AI by searching for what you want and uploading the page that is found to OpenAI. That is what the google search part is all about. It has something like 32 different parameters that you can specify for a google search. Many more than I was origainally away of. Using the google search requires two keys. Click the Settings button in this software to find out more about getting keys.
I also added a right click help menu based on the ContextMenu in B4J. I used OpenAI to generate the text of each help entry (about 230 of them). So they are basic and can be improved, but it took literally about 2 minutes to do what would have taken me 2 hours or more. Such is the benefit of AI.
There are numbers in green on the main page. These are the order of steps to create a Run in OpenAI. See here for details:
https://platform.openai.com/docs/assistants/overview
I could write more but that gives you all the general understanding of how it works. If you have any questions, please let me know.