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
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
- 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
- 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
redis_chatgpt-0.1.1.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for redis_chatgpt-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6de08204b6e0f42e382758731e511d34a048dfd9c454860b4064fc6753288cc5 |
|
MD5 | 043bcf5fdd1615fe383d1b7d2f16f7ae |
|
BLAKE2b-256 | 6ddd9e92e8ab4edec23a878e552669d2406d91d6f83e7779820c9ebdb8c565a4 |