Skip to main content

The cat's meow in AI conversation management.

Project description

kittychat

The purrfect chat utils library! With Kittychat, you'll be feline fine as a kittycat, since it ensures your threads stay within the LLMs token limits by whisking away old messages.

install

pip install kittychat

usage

import logging

from kittychat.msg_dropping import MessageDropper
from kittychat.errors import NotEnoughTokens

thread = [
    {
        "content": "What is the weather like in Boston?",
        "role": "user",
    },
]
functions = [
    {
        "name": "get_current_weather",
        "description": "Get the current weather in a given location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The city and state, e.g. San Francisco, CA",
                },
            },
            "required": ["location"],
        },
    }
]
model = "openai/gpt-3.5-turbo-0613"

msgd = MessageDropper(model)
length, max_tokens, is_too_big = msgd.check_thread_length(thread, functions)
if is_too_big:
    logging.warn(f"Thread too big: {length} tokens; max is {max_tokens} for model '{model}'.")
try:
    cropped_thread = msgd.run(thread, functions)
except NotEnoughTokens as e:
    raise YourPromptTooBigException(e.token_count, e.max_tokens, model)
return cropped_thread

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

kittychat-0.1.4.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

kittychat-0.1.4-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file kittychat-0.1.4.tar.gz.

File metadata

  • Download URL: kittychat-0.1.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for kittychat-0.1.4.tar.gz
Algorithm Hash digest
SHA256 dac2948f521c1cc9ea0eaf1edffb8c6ad1bcf0004b9f76101ad62d465cb1d819
MD5 9dc6fba19787765f371bfc146203b48b
BLAKE2b-256 f4083f6e9b5200daa0e6f3522fddf7c96f5ac8c0d006e1e3ad82d7c4f86753f8

See more details on using hashes here.

File details

Details for the file kittychat-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: kittychat-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for kittychat-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4f56f3b3c9c2fdd28fe044bc0dc60b8220c842664613e936c2f06cf953b4cd8c
MD5 8e2559276b951572f3d0b794e26ea9d9
BLAKE2b-256 e8404ddbb6e012d30272b67b2da213603987de91b1dad399371a7e800145d3e2

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