Skip to main content

A Python package for managing LLM context windows

Project description

EffiMemo

一个用于管理大语言模型(LLM)上下文窗口的Python包。

功能特性

  • 智能上下文管理:自动管理对话历史,确保不超过token限制
  • 多种裁切策略:支持first、last和selective策略
  • 灵活配置:可自定义最大token数、模型类型等参数
  • 系统消息保护:可选择性保留重要的系统消息

安装

pip install effimemo

快速开始

from effimemo import create_context_manager

# 创建上下文管理器
manager = create_context_manager(
    max_tokens=8192,
    model_name="gpt-4",
    strategy="last",
    preserve_system=True
)

# 使用管理器处理对话
messages = [
    {"role": "system", "content": "你是一个有用的助手"},
    {"role": "user", "content": "你好"},
    {"role": "assistant", "content": "你好!有什么可以帮助你的吗?"}
]

# 管理上下文
managed_messages = manager.manage_context(messages)

API文档

create_context_manager

创建上下文管理器实例。

参数:

  • max_tokens (int): 最大token数量,默认8192
  • model_name (str): 模型名称,默认"gpt-4"
  • strategy (str): 裁切策略,可选"first"、"last"或"selective",默认"last"
  • preserve_system (bool): 是否保留系统消息,默认True

返回:

  • ContextManager: 上下文管理器实例

许可证

MIT License

作者

Manus AI

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

effimemo-0.1.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

effimemo-0.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file effimemo-0.1.0.tar.gz.

File metadata

  • Download URL: effimemo-0.1.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for effimemo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 74b4caa82d1fa41f9c672a75c3a0938a34f6d3fdc09df433ed8208bdd28d82ed
MD5 de64ec151a1a36252a8f7c54da5b51c8
BLAKE2b-256 24126e26ceba41b340b56fc5c71aefe0fd791f6df438fb6bbbd6131b80416e7f

See more details on using hashes here.

File details

Details for the file effimemo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: effimemo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for effimemo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c70db4d102b78ebbeab5ca9b37abfe115d1b47508800be4b626f0908f7bbf2e5
MD5 7abdaa8704d717e80dd710ece096a786
BLAKE2b-256 3a38ed1e58f82fd02cb23bd93beaf68a7d3414e713a8f354a04a4ab0a036b77c

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