Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 37:fb9bcd3145cb | 38:cf9caa4abc3e |
|---|---|
| 1 import redis.asyncio as redis | |
| 2 import json | |
| 3 import os | |
| 4 | |
| 5 REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0") | |
| 6 redis_client = redis.from_url(REDIS_URL, decode_responses=True) | |
| 7 | |
| 8 STREAM_KEY = "chat:stream" | |
| 9 | |
| 10 | |
| 11 async def append_message(chat_id: str, role: str, content: str): | |
| 12 """Append a FULL message (user or final assistant)""" | |
| 13 payload = {"chatId": chat_id, "role": role, "content": content} | |
| 14 await redis_client.xadd(STREAM_KEY, {"data": json.dumps(payload)}) | |
| 15 | |
| 16 | |
| 17 async def get_all_messages_from_redis() -> list[dict]: | |
| 18 try: | |
| 19 entries = await redis_client.xrange(STREAM_KEY, "-", "+") | |
| 20 return [json.loads(entry["data"]) for entry in entries] | |
| 21 except: | |
| 22 return [] |