NB Requires "OPEN_AI_KEY" secret set
This project demonstrates how to perform recursive generation with OpenAI's models while managing message stacks to remain within token limits.
-
Initialization: We start with an initial set of messages. This could be a prompt or any other starting point for our recursive generation.
-
OpenAI Call: We send the set of messages to OpenAI's API. The assistant returns a continuation or response based on the provided messages.
-
Append and Pop Messages:
- We append the assistant's response to our set of messages.
- To manage token limits, we remove the oldest assistant message (at index 2) from our message stack.
-
Recursive Loop: We iterate steps 2 and 3 for a set number of times or until a certain condition is met. This results in a series of recursive generations where each new response is influenced by the previous ones.
-
Saving Data:
- After each iteration, we extract the CSV content from the assistant's response using the
extract_csv_contentfunction. This content is then appended toextracted_data.csv. - The updated message stack is saved to
messages.jsonto maintain state between iterations.
- After each iteration, we extract the CSV content from the assistant's response using the
-
Restarting and Continuing: If you wish to restart the recursive generation or continue from where you left off, load the latest set of messages from
messages.jsonand continue from step 2.
extracted_data.csv: Contains the CSV data extracted from the assistant's responses across iterations.messages.json: Stores the message stack after each iteration. Use this to continue recursive generation after a break or to review the messages used in previous iterations.