From 8efd6b5c135d99f55c719f1e054e649f769d9c31 Mon Sep 17 00:00:00 2001 From: Logan Markewich Date: Mon, 30 Sep 2024 14:21:28 -0600 Subject: [PATCH] README --- .../README.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-upstash/README.md b/llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-upstash/README.md index 554f64cc78877..bc18a10f28c8a 100644 --- a/llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-upstash/README.md +++ b/llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-upstash/README.md @@ -1 +1,53 @@ # LlamaIndex Chat_Store Integration: Upstash Chat Store + +## Installation + +`pip install llama-index-storage-chat-store-upstash` + +## Usage + +```python +from llama_index.storage.chat_store.upstash import UpstashChatStore +from llama_index.core.memory import ChatMemoryBuffer + +chat_store = UpstashChatStore( + redis_url="YOUR_UPSTASH_REDIS_URL", + redis_token="YOUR_UPSTASH_REDIS_TOKEN", + ttl=300, # Optional: Time to live in seconds +) + +chat_memory = ChatMemoryBuffer.from_defaults( + token_limit=3000, + chat_store=chat_store, + chat_store_key="user1", +) +``` + +UpstashChatStore supports both synchronous and asynchronous operations. Here's an example of using async methods: + +```python +import asyncio +from llama_index.core.llms import ChatMessage + + +async def main(): + # Add messages + messages = [ + ChatMessage(content="Hello", role="user"), + ChatMessage(content="Hi there!", role="assistant"), + ] + await chat_store.async_set_messages("conversation1", messages) + + # Retrieve messages + retrieved_messages = await chat_store.async_get_messages("conversation1") + print(retrieved_messages) + + # Delete last message + deleted_message = await chat_store.async_delete_last_message( + "conversation1" + ) + print(f"Deleted message: {deleted_message}") + + +asyncio.run(main()) +```