{"id":22469,"library":"tokentrim","title":"TokenTrim","description":"A utility library for trimming 'messages' arrays to fit within a specified token limit, commonly used with GPT models. Current version is 0.1.13, released as a stable package with no recent changes.","status":"active","version":"0.1.13","language":"python","source_language":"en","source_url":"https://github.com/your-username/tokentrim","tags":["openai","gpt","token","messages","trimming"],"install":[{"cmd":"pip install tokentrim","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Tokenization for OpenAI models","package":"tiktoken","optional":false}],"imports":[{"note":"Main function for trimming message arrays.","symbol":"trim_messages","correct":"from tokentrim import trim_messages"}],"quickstart":{"code":"import tokentrim\n\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"Tell me about Python.\"}\n]\n\n# Trim messages to fit within 100 tokens\ntrimmed_messages = tokentrim.trim_messages(messages, model=\"gpt-3.5-turbo\", max_tokens=100)\nprint(trimmed_messages)","lang":"python","description":"Basic usage: trim a list of messages to a maximum token count for a given model."},"warnings":[{"fix":"Ensure that the last message is preserved or handle the case where no messages remain.","message":"If the last message is a user message and trimming removes it, the function may return an empty list or incomplete conversation.","severity":"gotcha","affected_versions":"all"},{"fix":"Use a known model string like 'gpt-3.5-turbo' or 'gpt-4'.","message":"The 'model' parameter must match a model supported by tiktoken; otherwise, it may fall back to a default encoding or raise an error.","severity":"gotcha","affected_versions":"all"},{"fix":"Always specify max_tokens explicitly to avoid breaking changes.","message":"Future versions may change default trimming behavior; check documentation for updates.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install tiktoken: pip install tiktoken","cause":"Missing dependency tiktoken.","error":"ModuleNotFoundError: No module named 'tiktoken'"},{"fix":"Use a valid model like 'gpt-3.5-turbo', 'gpt-4', or 'text-davinci-003'.","cause":"The model string provided is not recognized by tiktoken.","error":"KeyError: 'model'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}