Skip to content

Commit 622277f

Browse files
committed
Assistant - fix token counting issue for conversations containing images
1 parent dc5b12f commit 622277f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

assistant/assistant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Assistant(
5454
"""
5555

5656
__author__ = "[vertyco](https://github.com/vertyco/vrt-cogs)"
57-
__version__ = "6.12.19"
57+
__version__ = "6.12.20"
5858

5959
def format_help_for_context(self, ctx):
6060
helpcmd = super().format_help_for_context(ctx)

assistant/common/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,14 @@ async def pop(role: str) -> int:
405405
if "name" in removed:
406406
reduction += 1
407407
if content := removed.get("content"):
408-
reduction += await self.count_tokens(content, model)
408+
if isinstance(content, list):
409+
for i in content:
410+
if i["type"] == "text":
411+
reduction += await self.count_tokens(i["text"], model)
412+
else:
413+
reduction += 2
414+
else:
415+
reduction += await self.count_tokens(str(content), model)
409416
elif tool_calls := removed.get("tool_calls"):
410417
reduction += await self.count_tokens(str(tool_calls), model)
411418
elif function_call := removed.get("function_call"):

0 commit comments

Comments
 (0)