Metadata-Version: 2.1
Name: redis-chatgpt
Version: 0.1.1
Summary: A user-friendly package designed to save chat history conversation and truncate conversation if user exceeds max token when using OpenAI chat completion.
Author: Elmira Ghorbani
Project-URL: Github, https://github.com/ElmiraGhorbani/redis-chatgpt
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: redis (>=4.6.0)

# Redis Chatgpt
Allows to save chat history of converation.


# Getting started
```
pip install redis-chatgpt
```

To build a simple data store:
```
from redis_chatgpt.manager import RedisManager

redis_db = RedisManager(host="localhost", port=6379)

# set data
redis_key = "chat_key"
chat_memory = [
    {
      "role": "system",
      "content": "Assistant is a large language model trained by OpenAI."
    },
    {
      "role": "assistant",
      "content": "Hello! How can I assist you today?"
    },
    {
      "role": "user",
      "content": "hi"
    },
]
redis_db.set_data(redis_key, chat_memory)

```

```
# get data

chat_history = redis_db.get_data(redis_key)

```

```
# truncate history(conversation)

# You can choose whether to update the Redis database or not by specifying the 'overwrite' parameter (boolean)."
redis_db.truncate_conversation(redis_key, overwrite=True)

```

### Use with FastAPI Swagger
`cd examples/chatbot`
1. Get your `OpenAI` API key [here](https://platform.openai.com/overview).
2. Copy env.example .env (set fastapi webserver workers and openai api key)
    `cp env.example .env`
3. docker-compose up -d
4. http://0.0.0.0:8012/docs
