Creating a thread for a series of messages

I’ve written some basic python code that loads a large text file, loops through the paragraphs, and sends a message to the API gpt-3.5-turbo-1106. Is there a way I can keep each paragraph on topic with the same chat message thread? It treats each paragraph as a new chat, which causes it to repeat information more than needed. Thanks for any help.

There really should just be one user message at a time that the AI is tasked with answering. Each AI response also tends to include some “chatty” stuff from the AI narrator.

How is it exactly that you are “sends a message”? You’d think that multiple user inputs might be combined and seen as one, but instead, those are more perceived as chat that happened in the past. That’s necessary because aggressive conversation management can give what the user’s been asking about for conversational context, but eliminate the wordy AI answers for token savings.

When using chat completions, this conversation memory isn’t built in – you must send a history with user message and AI response, for as many times in the past as may be relevant.

Since the AI evaluates prior user messages like them simply being informative past chat, you can use those prior messages for adding knowledge or for putting the AI into a new “mode”. It will be better like “here’s some new information for you: xxxx”, “here’s the document I’m working on…”.

Although your “keep each paragraph on topic” isn’t quite clear to let me know if that background I just provided is helpful.

Maybe you want the paragraph to be processed or translated as-is without excessive chatter. To do so, you can tell the AI in your system message that it is an automatic data processor receiving file input, the output is being placed in a file or added to a document, and there is no actual user reading its responses.