igbot-base 0.0.21__tar.gz → 0.0.23__tar.gz
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-0.0.21 → igbot_base-0.0.23}/PKG-INFO +1 -1
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/llmmemory.py +1 -1
- igbot_base-0.0.23/igbot_base/tokenizer.py +32 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base.egg-info/PKG-INFO +1 -1
- {igbot_base-0.0.21 → igbot_base-0.0.23}/pyproject.toml +1 -1
- igbot_base-0.0.21/igbot_base/tokenizer.py +0 -16
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/__init__.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/agent.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/agent_response.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/base_exception.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/exception_handler.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/llm.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/logging_adapter.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/models.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/persistable_memory.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/prompt_template.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/response_formats.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/retriever.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/tool.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base/vectorstore.py +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base.egg-info/SOURCES.txt +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base.egg-info/dependency_links.txt +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base.egg-info/requires.txt +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/igbot_base.egg-info/top_level.txt +0 -0
- {igbot_base-0.0.21 → igbot_base-0.0.23}/setup.cfg +0 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import Union, Dict, List
|
3
|
+
import json
|
4
|
+
import tiktoken
|
5
|
+
|
6
|
+
|
7
|
+
class BaseTokenizer(ABC):
|
8
|
+
@abstractmethod
|
9
|
+
def count_tokens(self, data: Union[str, Dict, None]) -> int:
|
10
|
+
pass
|
11
|
+
|
12
|
+
|
13
|
+
class OpenAiTokenizer(BaseTokenizer):
|
14
|
+
|
15
|
+
def __init__(self, model_name):
|
16
|
+
self.__tokenizer = tiktoken.encoding_for_model(model_name)
|
17
|
+
|
18
|
+
def count_tokens(self, data: Union[str: Dict, List, None]) -> int:
|
19
|
+
if data is None:
|
20
|
+
return 0
|
21
|
+
elif isinstance(data, str):
|
22
|
+
return len(self.__tokenizer.encode(data))
|
23
|
+
elif isinstance(data, dict):
|
24
|
+
dict_as_str = json.dumps(data, separators=(",", ":"))
|
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
|
31
|
+
else:
|
32
|
+
raise TypeError("Expected either a string, a dictionary, a list, or None.")
|
@@ -1,16 +0,0 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
import tiktoken
|
3
|
-
|
4
|
-
|
5
|
-
class BaseTokenizer(ABC):
|
6
|
-
@abstractmethod
|
7
|
-
def count_tokens(self, text: str):
|
8
|
-
pass
|
9
|
-
|
10
|
-
|
11
|
-
class OpenAiTokenizer(BaseTokenizer):
|
12
|
-
def __init__(self, model_name):
|
13
|
-
self.__tokenizer = tiktoken.encoding_for_model(model_name)
|
14
|
-
|
15
|
-
def count_tokens(self, text: str):
|
16
|
-
return len(self.__tokenizer.encode(text))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|