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.2.tar.gz (12.7 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.2-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: llm_mem_ai-0.1.2.tar.gz
  • Upload date:
  • Size: 12.7 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.2.tar.gz
Algorithm Hash digest
SHA256 ff00a2c05cc46db9f3c5fb3cac02ee90053189155a17815c8e8a698d885cdc45
MD5 ca8302ae7679c6f14a984ae18878bdd4
BLAKE2b-256 c936bf2c5eac0b6c3a88cdc06ce56602ad73337f940d63f48e24ca426559b0b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llm_mem_ai-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a7be58d0a326d29024a7fdd4ae5cf486917abcb165d2e4f08bf8c60f3ad66d7b
MD5 7c185e8ef2e1e9507d529d4d32460092
BLAKE2b-256 b80009534313f7e4ff51d657bbb528620a25153d16465f764d4fb983baa2d606

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