igbot-base 0.0.11__py3-none-any.whl → 0.0.13__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/agent.py CHANGED
@@ -2,11 +2,27 @@ from abc import ABC, abstractmethod
2
2
 
3
3
  from igbot_base.agent_response import AgentResponse
4
4
 
5
+ from igbot_base.exception_handler import ExceptionHandler, ReturnFailedResponseGracefully
6
+ from igbot_base.logging_adapter import get_logger
7
+
8
+ logger = get_logger("application")
9
+
5
10
 
6
11
  class Agent(ABC):
7
12
 
8
- @abstractmethod
13
+ def __init__(self, name, exception_handler: ExceptionHandler = ReturnFailedResponseGracefully):
14
+ self.__name = name
15
+ self.__ex_handler = exception_handler
16
+
9
17
  def invoke(self, query) -> AgentResponse:
18
+ try:
19
+ return self._invoke(query)
20
+ except Exception as e:
21
+ logger.exception("Exception occurred at %s for query %s: %s", self.describe(), query, e)
22
+ return self.__ex_handler.handle(e)
23
+
24
+ @abstractmethod
25
+ def _invoke(self, query) -> AgentResponse:
10
26
  pass
11
27
 
12
28
  @abstractmethod
@@ -14,4 +30,4 @@ class Agent(ABC):
14
30
  pass
15
31
 
16
32
  def __str__(self):
17
- return self.describe()
33
+ return self.describe()
@@ -1,5 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
+ from igbot_base.agent_response import AgentResponse
4
+
3
5
 
4
6
  class ExceptionHandler(ABC):
5
7
 
@@ -18,3 +20,9 @@ class PrintingExceptionHandler(ExceptionHandler):
18
20
 
19
21
  def handle(self, e: Exception):
20
22
  print(e)
23
+
24
+
25
+ class ReturnFailedResponseGracefully(ExceptionHandler):
26
+
27
+ def handle(self, e: Exception):
28
+ return AgentResponse.error(str(e), e)
igbot_base/llm.py CHANGED
@@ -26,7 +26,7 @@ class Llm(ABC):
26
26
  self._exception_handler = llm_exception_handler
27
27
 
28
28
  def __str__(self):
29
- return f"Llm({self._name} {self._model.get_name()})"
29
+ return f"Llm({self._name} {self._model.value.get_name()})"
30
30
 
31
31
  @abstractmethod
32
32
  def _call(self, user_query: str, history: LlmMemory, params: dict) -> str:
@@ -36,14 +36,15 @@ class Llm(ABC):
36
36
  history.revert_to_snapshot()
37
37
 
38
38
  def call(self, user_query: str, history: LlmMemory, params: dict) -> str:
39
+ logger.debug("Call to %s with question: %s", self.__str__(), user_query)
39
40
  history.set_snapshot()
40
41
  try:
41
42
  response = self._call(user_query, history, params)
42
- logger.debug("LLM %s %s responded: %s", self._name, self._model.get_name(), response)
43
+ logger.debug("LLM %s %s responded: %s", self._name, self._model.value.get_name(), response)
43
44
  return response
44
45
  except Exception as e:
45
46
  logger.error("Error occurred in LLM %s, Model %s at calling the API: %s",
46
- self._name, self._model.get_name(), e)
47
+ self._name, self._model.value.get_name(), e)
47
48
  self._revert_memory(history)
48
49
  self._exception_handler.handle(e)
49
50
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: igbot_base
3
- Version: 0.0.11
3
+ Version: 0.0.13
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
@@ -1,8 +1,8 @@
1
1
  igbot_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- igbot_base/agent.py,sha256=xU1jDgoyfXfSJlXcdLl1Va7BX-Z5QLXz4ZpjOuz2z9M,301
2
+ igbot_base/agent.py,sha256=FwQ5nvk5rLm5F-QaxsghhqDZcus_at7AehXIWDIk8dw,932
3
3
  igbot_base/agent_response.py,sha256=eAps47djL_aWYn8P_BMpVGkPwO6m8nhltWWyh8qSG6E,1042
4
- igbot_base/exception_handler.py,sha256=BMzQpgP4jnnRuTcEItx0oMljTZmKgMRCHzpybHn88Ig,341
5
- igbot_base/llm.py,sha256=xwd-AyMXYtzIlGV9Hcshof_h84R_n5vcT57tjcCDI10,1913
4
+ igbot_base/exception_handler.py,sha256=9DFAW0K0U7Y2vKGiUW-j1C0_zp48UCyO8jL3oRj9yJQ,535
5
+ igbot_base/llm.py,sha256=_HVTrQcbIzUaGWfRWeD-Pgy1M7JkOybzogXiQSK-mH8,2012
6
6
  igbot_base/llmmemory.py,sha256=I6eSBPW1DK8UNiHhayon-DLbSbWSinO_EwM5S8C3tHA,1090
7
7
  igbot_base/logging_adapter.py,sha256=kMuAaQPCba2luk0-WPxAbPNJaBL1yZsaff35ltKWgww,256
8
8
  igbot_base/models.py,sha256=15bitUZy4Z4JhZbLd_SMx5pD7m8YuZiIq-wYGumf0ws,622
@@ -19,7 +19,7 @@ igbot_base/exception/memory_exception.py,sha256=ZGKw3dN2tMf9XHacYaVTXgvYpWi14z7u
19
19
  igbot_base/exception/prompt_exception.py,sha256=_u-O9E2Z1DK_OT4StyOmIDLfr_Mmk4k0GLe67kIoQNc,413
20
20
  igbot_base/exception/retriever_exception.py,sha256=A46sBV6_1N3jgBl-nFRw4KgEcz3oPb8d5Eb83YWDEPo,431
21
21
  igbot_base/exception/tool_exception.py,sha256=1EX7R90MplT4Vqv1-zzPslFrNvDwcrh7wgEWun2Ba6k,386
22
- igbot_base-0.0.11.dist-info/METADATA,sha256=qRbglwrx7br3mjX0RH6I_KjsJ-lyR6dxOL4I7ECvtTo,211
23
- igbot_base-0.0.11.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
24
- igbot_base-0.0.11.dist-info/top_level.txt,sha256=RGpEN0pLsnfNLoLfpw1D_nLSyZwi3ggSaDq07o4ZEAI,11
25
- igbot_base-0.0.11.dist-info/RECORD,,
22
+ igbot_base-0.0.13.dist-info/METADATA,sha256=uc9oNyCmuuP-qhhpEuqm8tYLLR6_aO1Y1oP7drjcnsA,211
23
+ igbot_base-0.0.13.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
24
+ igbot_base-0.0.13.dist-info/top_level.txt,sha256=RGpEN0pLsnfNLoLfpw1D_nLSyZwi3ggSaDq07o4ZEAI,11
25
+ igbot_base-0.0.13.dist-info/RECORD,,