Mercurial
diff love/poppy/utils/redis.py @ 38:cf9caa4abc3e
[Love] FE and BE. Can chat and render images. Also created MCP for powerpoint generations.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 01 Dec 2025 20:35:56 -0800 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/love/poppy/utils/redis.py Mon Dec 01 20:35:56 2025 -0800 @@ -0,0 +1,22 @@ +import redis.asyncio as redis +import json +import os + +REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0") +redis_client = redis.from_url(REDIS_URL, decode_responses=True) + +STREAM_KEY = "chat:stream" + + +async def append_message(chat_id: str, role: str, content: str): + """Append a FULL message (user or final assistant)""" + payload = {"chatId": chat_id, "role": role, "content": content} + await redis_client.xadd(STREAM_KEY, {"data": json.dumps(payload)}) + + +async def get_all_messages_from_redis() -> list[dict]: + try: + entries = await redis_client.xrange(STREAM_KEY, "-", "+") + return [json.loads(entry["data"]) for entry in entries] + except: + return []