igbot-base 0.0.22__py3-none-any.whl → 0.0.23__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- igbot_base/tokenizer.py +8 -3
- {igbot_base-0.0.22.dist-info → igbot_base-0.0.23.dist-info}/METADATA +1 -1
- {igbot_base-0.0.22.dist-info → igbot_base-0.0.23.dist-info}/RECORD +5 -5
- {igbot_base-0.0.22.dist-info → igbot_base-0.0.23.dist-info}/WHEEL +0 -0
- {igbot_base-0.0.22.dist-info → igbot_base-0.0.23.dist-info}/top_level.txt +0 -0
igbot_base/tokenizer.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
|
-
from typing import Union, Dict
|
2
|
+
from typing import Union, Dict, List
|
3
3
|
import json
|
4
4
|
import tiktoken
|
5
5
|
|
@@ -15,7 +15,7 @@ class OpenAiTokenizer(BaseTokenizer):
|
|
15
15
|
def __init__(self, model_name):
|
16
16
|
self.__tokenizer = tiktoken.encoding_for_model(model_name)
|
17
17
|
|
18
|
-
def count_tokens(self, data: Union[str: Dict, None]) -> int:
|
18
|
+
def count_tokens(self, data: Union[str: Dict, List, None]) -> int:
|
19
19
|
if data is None:
|
20
20
|
return 0
|
21
21
|
elif isinstance(data, str):
|
@@ -23,5 +23,10 @@ class OpenAiTokenizer(BaseTokenizer):
|
|
23
23
|
elif isinstance(data, dict):
|
24
24
|
dict_as_str = json.dumps(data, separators=(",", ":"))
|
25
25
|
return len(self.__tokenizer.encode(dict_as_str))
|
26
|
+
elif isinstance(data, list):
|
27
|
+
token_number = 0
|
28
|
+
for datum in data:
|
29
|
+
token_number += self.count_tokens(datum)
|
30
|
+
return token_number
|
26
31
|
else:
|
27
|
-
raise TypeError("Expected either a string, a dictionary, or None.")
|
32
|
+
raise TypeError("Expected either a string, a dictionary, a list, or None.")
|
@@ -11,10 +11,10 @@ igbot_base/persistable_memory.py,sha256=867Z4l_awD23QSTFDK3uN9TEttKfDpxx9g19c7UL
|
|
11
11
|
igbot_base/prompt_template.py,sha256=q7bnU2Rp2Cvm4ixEmKHCyuolTPan6CHfYVAomT5kp10,1573
|
12
12
|
igbot_base/response_formats.py,sha256=Sp679VfkcyxsR19ddFEHTOM7Ox0u2WBhdji_Y9pVc2M,94
|
13
13
|
igbot_base/retriever.py,sha256=YHBHxiuPttsIAtjwwIz0fa9q2uFtsg0WoMRCorCt1PM,635
|
14
|
-
igbot_base/tokenizer.py,sha256=
|
14
|
+
igbot_base/tokenizer.py,sha256=WSR0GFc1eoMmyL58RAxtpb2iWCrqu9vQ2Ui-hqs4plw,1032
|
15
15
|
igbot_base/tool.py,sha256=ghjuU3cK_VElHGStUl3IYf9dlRDOGM_aQucUQNUH3mU,431
|
16
16
|
igbot_base/vectorstore.py,sha256=f-S9DmOuehC0rtVAPGz22Guo7ddb1jVw7BygzFJM624,928
|
17
|
-
igbot_base-0.0.
|
18
|
-
igbot_base-0.0.
|
19
|
-
igbot_base-0.0.
|
20
|
-
igbot_base-0.0.
|
17
|
+
igbot_base-0.0.23.dist-info/METADATA,sha256=I3skWzfixIyRxLZ2RgPuJaghLt0gKjNAnaLz9oM_YYo,235
|
18
|
+
igbot_base-0.0.23.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
|
19
|
+
igbot_base-0.0.23.dist-info/top_level.txt,sha256=RGpEN0pLsnfNLoLfpw1D_nLSyZwi3ggSaDq07o4ZEAI,11
|
20
|
+
igbot_base-0.0.23.dist-info/RECORD,,
|
File without changes
|
File without changes
|