A user-friendly package designed to save chat history conversation and truncate conversation if user exceeds max token when using OpenAI chat completion.
Project description
Redis Chatgpt
This package is a useful tool specifically developed for effectively handling chat message history. This Python package's primary goal is to provide a reliable, efficient, and simple method to store chat logs in a Redis database.
redis_chatgpt makes use of Redis, a fast, efficient, and highly scalable in-memory data structure store. By organizing and preserving the chat message history in Redis, users can retrieve message history promptly and easily with the best performance.
This package is the perfect solution if you need to store and recover chat histories effortlessly from the Redis Database. With redis_chatgpt, you can streamline your chat log management tasks while becoming more productive and efficient with your resources.
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).
data = redis_db.truncate_conversation(redis_key, overwrite=True)
Use with FastAPI Swagger
cd examples/chatbot
- Get your
OpenAI
API key here. - Copy env.example .env (set fastapi webserver workers and openai api key)
cp env.example .env
docker-compose up -d
- check out :
http://0.0.0.0:8012/docs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redis_chatgpt-0.1.2.tar.gz
.
File metadata
- Download URL: redis_chatgpt-0.1.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1d4bcac788fc0bf2acbce9b4dd1f2def6cefd8bd6b7b403f6e876221b004c1 |
|
MD5 | baf17477462d8713f727f11fcc6b04d0 |
|
BLAKE2b-256 | 82a1ec3d93147b751d437f05ca38f0cf4e7999d16e1476a086d5e2e4f431965a |
File details
Details for the file redis_chatgpt-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: redis_chatgpt-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b83a81c9fbeaf514f04b55c8706f4a0c57c0693906ec2ee6d7b3146010fb793 |
|
MD5 | b5782c9c3c79edfd98083bd505a20d0a |
|
BLAKE2b-256 | 83fdd1198b768872dfe03eeb26dea3d60c8c6a70ae37357a8a3fd781b01ca915 |