Notes on the code merger - 2025-02-17
Arjun:
The two code bases principally touch in main.py. From there they go their separate ways.
The code for your summaries uses:
main.py-> bot.slash_command -> (summary.py) summary(), fromtosummary() or unreadsummary()
The code for webhook summaries uses:
main.py-> wiressummary_for_webhook()into a Flask controlled bywebhook.py-> (history.py)summarize_contents_of_channel_between_dates()usesget_channel_messages()followed by progressive calls toget_summary_from_ai(). To minimize costs, call return values are cached in the LRUCache.webhook.pywebhook()receives the POST and will forward the response (and embedded request) usingsend_message_to_webhook()` according to the values in the incoming payload
Refactoring Your code could use summarize_contents_of_channel_between_dates in the sections for collection from history:
async for message in channel.history(limit=None):
if first:
first = False
continue
history.append(message)
if len(history) == messages:
break
Line #88-96 (summary) Line #168-183 (fromtosummary) Line #205-222 (unreadsummary)
If so, the hardcoded html would need reworking (e.g. line #26 of history.py)
My code has global values for:
- OPEN API KEY
- Currently an environment varible
- I'm thinking this could be passed in the incoming payload (and omitted outbound)
- context_lookback_days
- the context window provides background info to aid with interpretation in addition to the period being summarized
- Set to 5, but already can be provided in the payload
- Some HTML in response strings (for things like headers)