Summarization of notes where the reference of time is off

I’m summarizing a large body of journal entires where the goal is to summarize both older and newer entries. The prompt is divided in two parts, historical journal entries ( which are written as in pretense with dates included ) and the last entry. Frequently we end up with a mix of old and new information presented as current. Any help on how to deal with this?

Could you do something like this

from dotenv import load_dotenv

_ = load_dotenv()
from openai import OpenAI

client = OpenAI()

current_date = '2024-06-06'

prompt_template = """
Your job is to summarize a list of journal entries. Each journal entry is written in the present tense. Please take the current date and the date of the journal entry into account in your summary.

Current Date: {CURRENT_DATE}

Journal Entries:
{JOURNAL_ENTRIES}

Please provide your summary below:
"""

journal_entries = [
    { "date": "2022-01-01", "content": "I am going to the grocery store." },
    { "date": "2023-04-01", "content": "I am going to the zoo." },
    { "date": "2024-06-01", "content": "I am going to the beach." }
]

def build_prompt(journal_entries, current_date):
    journal_entries_text = "\n".join([f"{entry['date']}: {entry['content']}" for entry in journal_entries])
    return prompt_template.format(CURRENT_DATE=current_date, JOURNAL_ENTRIES=journal_entries_text)

prompt = build_prompt(journal_entries, current_date)

result = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": prompt}],
)

content = result.choices[0].message.content
print('result: ', content)
1 Like

Thank you very much for the suggestion. Ivwas thinking along these lines but your answer cleared it out for me.

1 Like