Skip to main content

A LLM Memory Cache package

Project description

llm-mem

项目简介

  • 想制作一个简单可行的对话存储的记忆模块,可以分层,可以混合检索,当用户提问时可以命中局部记忆内容
  • 这里使用的模型为阿里云百炼,dashscope.aliyuncs.com,其他平台会慢慢兼容

安装方法

使用示例

# How to run
def test_llm_memory():
    memory = MemoryAI()
    
    question = "我想了解一下Springboot能做什么呢?"
    user_id = "jerry.s.d"
    session_id = ""

    # 获取长期记忆 question_context 为上下文的消息列表(可根据情况自行加工)
    question_context, session_id, summary_result, message_ids = memory.get_memory(
        question, user_id, session_id
    )

    # TODO 这里是正常调用语言模型的逻辑,或者智能体, 使用question_context 构建自己的上下文即可
    # 开始提问
    answer_res = "Do some function call LLM "

    # 追加新的信息进入长期记忆
    memory.set_memory(
        question, answer_res, user_id, session_id, message_ids, summary_result
    )
# .env相关配置
# =========== 模型相关配置 ===========
# dashscope 目前只兼容了dashscope
PLATFORM = "dashscope"
API_KEY ="sk-"
BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
LLM_MODEL="qwen-plus"
EMBEDDING_MODEL="text-embedding-v4"
EMBEDDING_MODEL_DIM=1024

# =========== 向量数据库相关配置 ===========
# qdrant 目前只兼容了qdrant
VECTOR = "qdrant"
QDRANT_URL = "http://localhost:6333"
QDRANT_API_KEY = "xxxxx"
QDRANT_COLLECTION = "mem_collection"
# =========== Mongo文档库相关配置 ===========
# 开启后自动存储聊天内容, TODO 对于False的情况,还没有进行测试
OPEN_CONTEXT_SAVE = "True"
# mongodb://chat:chat@localhost:27017/chat_database?authSource=admin
MONGO_URL = "mongodb://mongo:mongo@localhost:27017"
MONGO_DB = "mem_database"
MONGO_AUTH = "admin"
MONGO_COLLECTION = "mem_collection"

# 其他配置
DEBUG="False"

Collaborate with your team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_mem_ai-0.1.1.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_mem_ai-0.1.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file llm_mem_ai-0.1.1.tar.gz.

File metadata

  • Download URL: llm_mem_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for llm_mem_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 046532c2c4945d53e551acc5f17fefb7e7a1626803ec6fb3076608b1e7255c68
MD5 28a95d9a0171f4d7def21b8c007e9190
BLAKE2b-256 bb5e07ea0618d46bbdb1bcaa21e1055b193ff1dfbb7d7337fb4d3f86ff308452

See more details on using hashes here.

File details

Details for the file llm_mem_ai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: llm_mem_ai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for llm_mem_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 67f83b6c7e12e78a5188117c35f1d8f697d7d811707e33acd73c99a376b0d13a
MD5 d6947b1dd348c9a15c47068b42eff361
BLAKE2b-256 fcc251d3a05cfe63954d03740799b01df3c26c70509c4872085d98ae91d8c82b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page