Context Length Filter (tokens & turns)

function

Truncate chat context length with 'token limit' and 'max turns', showing status while limit exceeded.

keke
@keke
·
2 years ago
1.2K
2
5.7K
Updated 2 years ago
Created Sep 19, 2024
context_length_filter.py
Python · 103 lines
"""
title: Context Length Filter
description: Truncate chat context length with 'token limit' and 'max turns', showing status while limit exceeded. System message and multimodal messages excluded.
author: Kejun Luo
version: 0.5
"""

import tiktoken
from pydantic import BaseModel, Field
from typing import Optional, Callable, Any, Awaitable


Truncate chat context length with 'token limit' and 'max turns', showing status while limit exceeded.


0