|
|
@ -696,7 +696,6 @@ def trim_messages(
|
|
|
|
HumanMessage("This is a 4 token text. The full message is 10 tokens.", id="third"),
|
|
|
|
HumanMessage("This is a 4 token text. The full message is 10 tokens.", id="third"),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Last 40 tokens, including system message, allowing partial messages, start on HumanMessage:
|
|
|
|
Last 40 tokens, including system message, allowing partial messages, start on HumanMessage:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
@ -717,31 +716,6 @@ def trim_messages(
|
|
|
|
HumanMessage("This is a 4 token text. The full message is 10 tokens.", id="third"),
|
|
|
|
HumanMessage("This is a 4 token text. The full message is 10 tokens.", id="third"),
|
|
|
|
AIMessage("This is a 4 token text. The full message is 10 tokens.", id="fourth"),
|
|
|
|
AIMessage("This is a 4 token text. The full message is 10 tokens.", id="fourth"),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
Using a TextSplitter for splitting parting messages:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Using a model for token counting:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Chaining:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" # noqa: E501
|
|
|
|
""" # noqa: E501
|
|
|
|
from langchain_core.language_models import BaseLanguageModel
|
|
|
|
from langchain_core.language_models import BaseLanguageModel
|
|
|
|
|
|
|
|
|
|
|
|