{"id":13577207,"url":"https://github.com/continuum-llms/chatgpt-memory","last_synced_at":"2025-04-05T11:31:36.616Z","repository":{"id":147782292,"uuid":"612912524","full_name":"continuum-llms/chatgpt-memory","owner":"continuum-llms","description":"Allows to scale the ChatGPT API to multiple simultaneous sessions with infinite contextual and adaptive memory powered by GPT and Redis datastore.","archived":true,"fork":false,"pushed_at":"2023-10-22T09:08:16.000Z","size":94,"stargazers_count":519,"open_issues_count":0,"forks_count":65,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-11-05T14:43:49.367Z","etag":null,"topics":["chatgpt","chatgpt-api","memory","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/continuum-llms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-12T11:07:23.000Z","updated_at":"2024-11-01T04:03:09.000Z","dependencies_parsed_at":"2024-01-16T20:28:56.132Z","dependency_job_id":"22690c23-ef57-4e0e-849b-e2a6536442a3","html_url":"https://github.com/continuum-llms/chatgpt-memory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/continuum-llms%2Fchatgpt-memory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/continuum-llms%2Fchatgpt-memory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/continuum-llms%2Fchatgpt-memory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/continuum-llms%2Fchatgpt-memory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/continuum-llms","download_url":"https://codeload.github.com/continuum-llms/chatgpt-memory/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247330879,"owners_count":20921706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","chatgpt-api","memory","redis"],"created_at":"2024-08-01T15:01:19.257Z","updated_at":"2025-04-05T11:31:36.310Z","avatar_url":"https://github.com/continuum-llms.png","language":"Python","funding_links":[],"categories":["Python","13. Related Awesome Lists"],"sub_categories":["Model Benchmarks (March 2026)"],"readme":"*Development on this repository has discontinued. Please check out OpenAI's retrieval plugin instead: https://github.com/openai/chatgpt-retrieval-plugin*\n\n# ChatGPT Memory\n\nAllows to scale the ChatGPT API to multiple simultaneous sessions with infinite contextual and adaptive memory powered by GPT and Redis datastore. This can be visualized as follows\n\n\u003cp  align=\"center\"\u003e\n\u003cbr\u003e\n\u003cimg src=\"https://user-images.githubusercontent.com/6007894/227480704-e7e66341-98fd-43df-809a-f43d60d7c76b.png\"\u003e\n\u003cbr\u003e\n\u003c/p\u003e\n\n## Getting Started\n\n1. Create your free `Redis` datastore [here](https://redis.com/try-free/).\n2. Get your `OpenAI` API key [here](https://platform.openai.com/overview).\n3. Install dependencies using `poetry`.\n\n```bash\npoetry install\n```\n\n### Use with UI\n\u003cimg width=\"1217\" alt=\"Screenshot 2023-04-17 at 10 26 59 PM\" src=\"https://user-images.githubusercontent.com/6007894/232608443-054e47e6-6057-4583-9d92-205843a260c8.png\"\u003e\n\n\n\nStart the FastAPI webserver.\n```bash\npoetry run uvicorn rest_api:app --host 0.0.0.0 --port 8000\n```\n\nRun the UI.\n```bash\npoetry run streamlit run ui.py\n```\n\n### Use with Terminal\n\nThe library is highly modular. In the following, we describe the usage of each component (visualized above).\n\nFirst, start out by setting the required environment variables before running your script. This is optional but recommended.\nYou can use a `.env` file for this. See the `.env.example` file for an example.\n\n```python\nfrom chatgpt_memory.environment import OPENAI_API_KEY, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT\n```\n\nCreate an instance of the `RedisDataStore` class with the `RedisDataStoreConfig` configuration.\n\n```python\nfrom chatgpt_memory.datastore import RedisDataStoreConfig, RedisDataStore\n\n\nredis_datastore_config = RedisDataStoreConfig(\n    host=REDIS_HOST,\n    port=REDIS_PORT,\n    password=REDIS_PASSWORD,\n)\nredis_datastore = RedisDataStore(config=redis_datastore_config)\n```\n\nCreate an instance of the `EmbeddingClient` class with the `EmbeddingConfig` configuration.\n\n```python\nfrom chatgpt_memory.llm_client import EmbeddingConfig, EmbeddingClient\n\nembedding_config = EmbeddingConfig(api_key=OPENAI_API_KEY)\nembed_client = EmbeddingClient(config=embedding_config)\n```\n\nCreate an instance of the `MemoryManager` class with the Redis datastore and Embedding client instances, and the `topk` value.\n\n```python\nfrom chatgpt_memory.memory.manager import MemoryManager\n\nmemory_manager = MemoryManager(datastore=redis_datastore, embed_client=embed_client, topk=1)\n```\n\nCreate an instance of the `ChatGPTClient` class with the `ChatGPTConfig` configuration and the `MemoryManager` instance.\n\n```python\nfrom chatgpt_memory.llm_client import ChatGPTClient, ChatGPTConfig\n\nchat_gpt_client = ChatGPTClient(\n    config=ChatGPTConfig(api_key=OPENAI_API_KEY, verbose=True), memory_manager=memory_manager\n)\n```\n\nStart the conversation by providing user messages to the converse method of the `ChatGPTClient` instance.\n\n```python\nconversation_id = None\nwhile True:\n    user_message = input(\"\\n Please enter your message: \")\n    response = chat_gpt_client.converse(message=user_message, conversation_id=conversation_id)\n    conversation_id = response.conversation_id\n    print(response.chat_gpt_answer)\n```\n\nThis will allow you to talk to the AI assistant and extend its memory by using an external Redis datastore.\n\n### Putting it together\n\nHere's all of the above put together. You can also find it under [`examples/simple_usage.py`](examples/simple_usage.py)\n\n```python\n## set the following ENVIRONMENT Variables before running this script\n# Import necessary modules\nfrom chatgpt_memory.environment import OPENAI_API_KEY, REDIS_HOST, REDIS_PASSWORD, REDIS_PORT\nfrom chatgpt_memory.datastore import RedisDataStoreConfig, RedisDataStore\nfrom chatgpt_memory.llm_client import ChatGPTClient, ChatGPTConfig, EmbeddingConfig, EmbeddingClient\nfrom chatgpt_memory.memory import MemoryManager\n\n# Instantiate an EmbeddingConfig object with the OpenAI API key\nembedding_config = EmbeddingConfig(api_key=OPENAI_API_KEY)\n\n# Instantiate an EmbeddingClient object with the EmbeddingConfig object\nembed_client = EmbeddingClient(config=embedding_config)\n\n# Instantiate a RedisDataStoreConfig object with the Redis connection details\nredis_datastore_config = RedisDataStoreConfig(\n    host=REDIS_HOST,\n    port=REDIS_PORT,\n    password=REDIS_PASSWORD,\n)\n\n# Instantiate a RedisDataStore object with the RedisDataStoreConfig object\nredis_datastore = RedisDataStore(config=redis_datastore_config)\n\n# Instantiate a MemoryManager object with the RedisDataStore object and EmbeddingClient object\nmemory_manager = MemoryManager(datastore=redis_datastore, embed_client=embed_client, topk=1)\n\n# Instantiate a ChatGPTConfig object with the OpenAI API key and verbose set to True\nchat_gpt_config = ChatGPTConfig(api_key=OPENAI_API_KEY, verbose=True)\n\n# Instantiate a ChatGPTClient object with the ChatGPTConfig object and MemoryManager object\nchat_gpt_client = ChatGPTClient(\n    config=chat_gpt_config,\n    memory_manager=memory_manager\n)\n\n# Initialize conversation_id to None\nconversation_id = None\n\n# Start the chatbot loop\nwhile True:\n    # Prompt the user for input\n    user_message = input(\"\\n Please enter your message: \")\n\n\n    # Use the ChatGPTClient object to generate a response\n    response = chat_gpt_client.converse(message=user_message, conversation_id=conversation_id)\n\n    # Update the conversation_id with the conversation_id from the response\n    conversation_id = response.conversation_id\n\n\n    # Print the response generated by the chatbot\n    print(response.chat_gpt_answer)\n```\n\n# Acknowledgments\n\nUI has been added thanks to the awesome work by [avrabyt/MemoryBot](https://github.com/avrabyt/MemoryBot).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontinuum-llms%2Fchatgpt-memory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcontinuum-llms%2Fchatgpt-memory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcontinuum-llms%2Fchatgpt-memory/lists"}