igbot-base 0.0.35__py3-none-any.whl → 0.0.39__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/additional_data.py +17 -0
- igbot_base/agent.py +2 -1
- igbot_base/llm.py +20 -1
- igbot_base/tool.py +8 -1
- {igbot_base-0.0.35.dist-info → igbot_base-0.0.39.dist-info}/METADATA +1 -1
- {igbot_base-0.0.35.dist-info → igbot_base-0.0.39.dist-info}/RECORD +8 -7
- {igbot_base-0.0.35.dist-info → igbot_base-0.0.39.dist-info}/WHEEL +0 -0
- {igbot_base-0.0.35.dist-info → igbot_base-0.0.39.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
from pydantic.v1 import BaseModel
|
2
|
+
from typing import Any, Dict, Optional
|
3
|
+
|
4
|
+
class AdditionalData(BaseModel):
|
5
|
+
data: Dict[str, Any]
|
6
|
+
|
7
|
+
def get(self, key: str) -> Optional[Any]:
|
8
|
+
"""
|
9
|
+
Get the value associated with the key, or return None if the key doesn't exist.
|
10
|
+
|
11
|
+
:param key: The key to look for in the dictionary.
|
12
|
+
:return: The value associated with the key, or None.
|
13
|
+
"""
|
14
|
+
return self.data.get(key)
|
15
|
+
|
16
|
+
|
17
|
+
EMPTY = AdditionalData(data={})
|
igbot_base/agent.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
2
|
|
3
|
+
from igbot_base.additional_data import AdditionalData, EMPTY
|
3
4
|
from igbot_base.agent_response import AgentResponse
|
4
5
|
|
5
6
|
from igbot_base.exception_handler import ExceptionHandler, ReturnFailedResponseGracefully
|
@@ -30,7 +31,7 @@ class Agent(ABC):
|
|
30
31
|
return self.__ex_handler.handle(e)
|
31
32
|
|
32
33
|
@abstractmethod
|
33
|
-
def _invoke(self, query, memory: LlmMemory) -> AgentResponse:
|
34
|
+
def _invoke(self, query, memory: LlmMemory, params: AdditionalData = EMPTY) -> AgentResponse:
|
34
35
|
pass
|
35
36
|
|
36
37
|
@abstractmethod
|
igbot_base/llm.py
CHANGED
@@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
|
2
2
|
from builtins import dict
|
3
3
|
from typing import Optional
|
4
4
|
|
5
|
+
from igbot_base.additional_data import AdditionalData, EMPTY
|
5
6
|
from igbot_base.exception_handler import ExceptionHandler, NoopExceptionHandler
|
6
7
|
from igbot_base.llmmemory import LlmMemory
|
7
8
|
from igbot_base.models import Model
|
@@ -31,7 +32,11 @@ class Llm(ABC):
|
|
31
32
|
return f"Llm({self._name} {self._model.value.get_name()})"
|
32
33
|
|
33
34
|
@abstractmethod
|
34
|
-
def _call(self, user_query: str, history: LlmMemory, params: dict) -> str:
|
35
|
+
def _call(self, user_query: str, history: LlmMemory, params: dict, additonal_data: AdditionalData = EMPTY) -> str:
|
36
|
+
pass
|
37
|
+
|
38
|
+
@abstractmethod
|
39
|
+
def _add_llm_message(self, user_query: str, history: LlmMemory, params: dict) -> str:
|
35
40
|
pass
|
36
41
|
|
37
42
|
def _revert_memory(self, history: LlmMemory):
|
@@ -51,6 +56,20 @@ class Llm(ABC):
|
|
51
56
|
self._exception_handler.handle(e)
|
52
57
|
raise BaseLlmException(f"Exception occurred while calling llm api", self, e)
|
53
58
|
|
59
|
+
def add_llm_message(self, llm_message: str, history: LlmMemory, params: dict) -> str:
|
60
|
+
logger.debug("Call to %s with llm message: %s", self.__str__(), llm_message)
|
61
|
+
history.set_snapshot()
|
62
|
+
try:
|
63
|
+
response = self._add_llm_message(llm_message, history, params)
|
64
|
+
logger.debug("LLM %s %s responded: %s", self._name, self._model.value.get_name(), response)
|
65
|
+
return response
|
66
|
+
except Exception as e:
|
67
|
+
logger.error("Error occurred in LLM %s, Model %s at calling the API: %s",
|
68
|
+
self._name, self._model.value.get_name(), e)
|
69
|
+
self._revert_memory(history)
|
70
|
+
self._exception_handler.handle(e)
|
71
|
+
raise BaseLlmException(f"Exception occurred while calling llm api", self, e)
|
72
|
+
|
54
73
|
def get_additional_llm_args(self):
|
55
74
|
args = {}
|
56
75
|
if self._temperature is not None:
|
igbot_base/tool.py
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
|
+
from typing import Any, Optional, Callable
|
2
3
|
|
4
|
+
from pydantic import BaseModel
|
5
|
+
|
6
|
+
|
7
|
+
class ToolResponse(BaseModel):
|
8
|
+
message: Optional[str] = None
|
9
|
+
data: Optional[Any] = None
|
3
10
|
|
4
11
|
class Tool(ABC):
|
5
12
|
|
@@ -12,7 +19,7 @@ class Tool(ABC):
|
|
12
19
|
return self._name
|
13
20
|
|
14
21
|
@abstractmethod
|
15
|
-
def get_function(self):
|
22
|
+
def get_function(self) -> Callable[..., ToolResponse]:
|
16
23
|
pass
|
17
24
|
|
18
25
|
@abstractmethod
|
@@ -1,9 +1,10 @@
|
|
1
1
|
igbot_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
igbot_base/
|
2
|
+
igbot_base/additional_data.py,sha256=CbuT4m4l4Kw_7yUVAyPpMMct0ED3yF91JVo79vqnXik,479
|
3
|
+
igbot_base/agent.py,sha256=pdDPQIg60V9bpT_VQQjEQXZNoaxRlk_82HB-ffg24ro,1576
|
3
4
|
igbot_base/agent_response.py,sha256=ujLaFkIw9he-X1YFIICTJvq_4pmzTvTF4txEfeZtKSA,1041
|
4
5
|
igbot_base/base_exception.py,sha256=uRZXwYdsER2y_Rlah1TaSXwR6Kb9t2lNyngar0p5YFk,2146
|
5
6
|
igbot_base/exception_handler.py,sha256=Er5LbNt2ga2-e0GSzkJw66E-NS1dN_2msTRyyac1qX8,536
|
6
|
-
igbot_base/llm.py,sha256=
|
7
|
+
igbot_base/llm.py,sha256=0i0VVtvLafH_tqpvtNMvmULj4vkoKCrntXFkiimMifI,3172
|
7
8
|
igbot_base/llmmemory.py,sha256=eMjkjFMKgyAqpM7-q3xzQAP6gDeNfkpPkb9MK1hN8iY,1157
|
8
9
|
igbot_base/logging_adapter.py,sha256=kMuAaQPCba2luk0-WPxAbPNJaBL1yZsaff35ltKWgww,256
|
9
10
|
igbot_base/models.py,sha256=kbscj0jTNkJu9cglEQILjdOWJuwD3pZ0Q1rxz2q7tg8,1370
|
@@ -13,9 +14,9 @@ igbot_base/prompt_template.py,sha256=q7bnU2Rp2Cvm4ixEmKHCyuolTPan6CHfYVAomT5kp10
|
|
13
14
|
igbot_base/response_formats.py,sha256=Sp679VfkcyxsR19ddFEHTOM7Ox0u2WBhdji_Y9pVc2M,94
|
14
15
|
igbot_base/retriever.py,sha256=YHBHxiuPttsIAtjwwIz0fa9q2uFtsg0WoMRCorCt1PM,635
|
15
16
|
igbot_base/tokenizer.py,sha256=WSR0GFc1eoMmyL58RAxtpb2iWCrqu9vQ2Ui-hqs4plw,1032
|
16
|
-
igbot_base/tool.py,sha256=
|
17
|
+
igbot_base/tool.py,sha256=r0YV9KDVLyXyt2TnC4RLxK0r0llFPgDNwXw5TfhH_JA,634
|
17
18
|
igbot_base/vectorstore.py,sha256=f-S9DmOuehC0rtVAPGz22Guo7ddb1jVw7BygzFJM624,928
|
18
|
-
igbot_base-0.0.
|
19
|
-
igbot_base-0.0.
|
20
|
-
igbot_base-0.0.
|
21
|
-
igbot_base-0.0.
|
19
|
+
igbot_base-0.0.39.dist-info/METADATA,sha256=0tx5AFH4T3wXbLg6hvVBiRtvZmeiA1sNt4MVeV7t43Y,235
|
20
|
+
igbot_base-0.0.39.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
21
|
+
igbot_base-0.0.39.dist-info/top_level.txt,sha256=RGpEN0pLsnfNLoLfpw1D_nLSyZwi3ggSaDq07o4ZEAI,11
|
22
|
+
igbot_base-0.0.39.dist-info/RECORD,,
|
File without changes
|
File without changes
|