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 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.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: igbot_base
3
- Version: 0.0.22
3
+ Version: 0.0.23
4
4
  Summary: Base classes for igbot
5
5
  Author-email: Igor Kopeć <igor.kopec95@gmail.com>
6
6
  License: LGPL-3.0-or-later
@@ -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=uvDNr3UOeNL7Hg9HTfcFd-Fzf04SRSyEoOgYoo077Qs,825
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.22.dist-info/METADATA,sha256=78jnUQdCKgRLQe165z5TBeMDX1BlLdzVOl96ldamszE,235
18
- igbot_base-0.0.22.dist-info/WHEEL,sha256=GHB6lJx2juba1wDgXDNlMTyM13ckjBMKf-OnwgKOCtA,91
19
- igbot_base-0.0.22.dist-info/top_level.txt,sha256=RGpEN0pLsnfNLoLfpw1D_nLSyZwi3ggSaDq07o4ZEAI,11
20
- igbot_base-0.0.22.dist-info/RECORD,,
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,,