igbot-base 0.0.9__py3-none-any.whl → 0.0.11__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
@@ -7,4 +7,11 @@ class Agent(ABC):
7
7
 
8
8
  @abstractmethod
9
9
  def invoke(self, query) -> AgentResponse:
10
- pass
10
+ pass
11
+
12
+ @abstractmethod
13
+ def describe(self):
14
+ pass
15
+
16
+ def __str__(self):
17
+ return self.describe()
@@ -0,0 +1,14 @@
1
+ from igbot_base.agent import Agent
2
+ from igbot_base.exception.base_exception import IgBotBaseException
3
+
4
+
5
+ class BaseAgentException(IgBotBaseException):
6
+
7
+ def __init__(self, message, agent: Agent, cause: Exception = None):
8
+ super().__init__(message, cause)
9
+ self.agent = agent
10
+
11
+ def __str__(self):
12
+ result = super().__str__()
13
+ result += f" at agent {self.agent}"
14
+
@@ -0,0 +1,12 @@
1
+ class IgBotBaseException(Exception):
2
+
3
+ def __init__(self, message, cause: Exception = None):
4
+ super().__init__(message)
5
+ self.cause = cause
6
+
7
+ def __str__(self):
8
+ result = self.args[0]
9
+ if self.cause:
10
+ result += f" Caused by: {self.cause}"
11
+
12
+ return result
@@ -0,0 +1,13 @@
1
+ from igbot_base.exception.base_exception import IgBotBaseException
2
+ from igbot_base.llm import Llm
3
+
4
+
5
+ class BaseLlmException(IgBotBaseException):
6
+
7
+ def __init__(self, message, llm: Llm, cause: Exception = None):
8
+ super().__init__(message, cause)
9
+ self.llm = llm
10
+
11
+ def __str__(self):
12
+ result = super().__str__()
13
+ result += f" at llm {self.llm}"
@@ -0,0 +1,14 @@
1
+ from igbot_base.exception.base_exception import IgBotBaseException
2
+ from igbot_base.llmmemory import LlmMemory
3
+
4
+
5
+ class BaseMemoryException(IgBotBaseException):
6
+
7
+ def __init__(self, message, memory: LlmMemory, cause: Exception = None):
8
+ super().__init__(message, cause)
9
+ self.memory = memory
10
+
11
+ def __str__(self):
12
+ result = super().__str__()
13
+ result += f" at memory {self.memory}"
14
+
@@ -0,0 +1,14 @@
1
+ from igbot_base.exception.base_exception import IgBotBaseException
2
+ from igbot_base.prompt_template import Prompt
3
+
4
+
5
+ class BasePromptException(IgBotBaseException):
6
+
7
+ def __init__(self, message, prompt: Prompt, cause: Exception = None):
8
+ super().__init__(message, cause)
9
+ self.prompt = prompt
10
+
11
+ def __str__(self):
12
+ result = super().__str__()
13
+ result += f" at prompt {self.prompt}"
14
+
@@ -0,0 +1,14 @@
1
+ from igbot_base.exception.base_exception import IgBotBaseException
2
+ from igbot_base.retriever import Retriever
3
+
4
+
5
+ class BaseRetrieverException(IgBotBaseException):
6
+
7
+ def __init__(self, message, retriever: Retriever, cause: Exception = None):
8
+ super().__init__(message, cause)
9
+ self.retriever = retriever
10
+
11
+ def __str__(self):
12
+ result = super().__str__()
13
+ result += f" at retriever {self.retriever}"
14
+
@@ -0,0 +1,14 @@
1
+ from igbot_base.exception.base_exception import IgBotBaseException
2
+ from igbot_base.tool import Tool
3
+
4
+
5
+ class BaseToolException(IgBotBaseException):
6
+
7
+ def __init__(self, message, tool: Tool, cause: Exception = None):
8
+ super().__init__(message, cause)
9
+ self.tool = tool
10
+
11
+ def __str__(self):
12
+ result = super().__str__()
13
+ result += f" at tool {self.tool}"
14
+
igbot_base/llm.py CHANGED
@@ -5,6 +5,9 @@ from typing import Optional
5
5
  from igbot_base.exception_handler import ExceptionHandler, NoopExceptionHandler
6
6
  from igbot_base.llmmemory import LlmMemory
7
7
  from igbot_base.models import Model
8
+ from igbot_base.logging_adapter import get_logger
9
+
10
+ logger = get_logger("application")
8
11
 
9
12
 
10
13
  class Llm(ABC):
@@ -22,6 +25,9 @@ class Llm(ABC):
22
25
  self._format = response_format
23
26
  self._exception_handler = llm_exception_handler
24
27
 
28
+ def __str__(self):
29
+ return f"Llm({self._name} {self._model.get_name()})"
30
+
25
31
  @abstractmethod
26
32
  def _call(self, user_query: str, history: LlmMemory, params: dict) -> str:
27
33
  pass
@@ -32,8 +38,12 @@ class Llm(ABC):
32
38
  def call(self, user_query: str, history: LlmMemory, params: dict) -> str:
33
39
  history.set_snapshot()
34
40
  try:
35
- return self._call(user_query, history, params)
41
+ response = self._call(user_query, history, params)
42
+ logger.debug("LLM %s %s responded: %s", self._name, self._model.get_name(), response)
43
+ return response
36
44
  except Exception as e:
45
+ logger.error("Error occurred in LLM %s, Model %s at calling the API: %s",
46
+ self._name, self._model.get_name(), e)
37
47
  self._revert_memory(history)
38
48
  self._exception_handler.handle(e)
39
49
 
@@ -45,3 +55,4 @@ class Llm(ABC):
45
55
  args["response_format"] = self._format
46
56
 
47
57
  return args
58
+
igbot_base/llmmemory.py CHANGED
@@ -50,3 +50,10 @@ class LlmMemory(ABC):
50
50
  @abstractmethod
51
51
  def set_snapshot(self):
52
52
  pass
53
+
54
+ @abstractmethod
55
+ def describe(self):
56
+ pass
57
+
58
+ def __str__(self):
59
+ return self.describe()
@@ -0,0 +1,15 @@
1
+ import logging
2
+
3
+ try:
4
+ import structlog
5
+
6
+ USE_STRUCTLOG = True
7
+ except ImportError:
8
+ USE_STRUCTLOG = False
9
+
10
+
11
+ def get_logger(name: str):
12
+ if USE_STRUCTLOG:
13
+ return structlog.get_logger(name)
14
+ else:
15
+ return logging.getLogger(name)
@@ -2,6 +2,9 @@ import re
2
2
  from typing import Optional
3
3
 
4
4
  from igbot_base.exception_handler import ExceptionHandler, PrintingExceptionHandler
5
+ from igbot_base.logging_adapter import get_logger
6
+
7
+ logger = get_logger("application")
5
8
 
6
9
 
7
10
  class Prompt:
@@ -15,6 +18,9 @@ class Prompt:
15
18
  self.__variables = variables
16
19
  self.__exception_handler = exception_handler
17
20
 
21
+ def __str__(self):
22
+ return f"Prompt({self.__get_content_short()} ({",".join(self.__variables)}))"
23
+
18
24
  @staticmethod
19
25
  def replace_placeholders(text: str, values: dict) -> str:
20
26
  def replacer(match):
@@ -30,9 +36,16 @@ class Prompt:
30
36
  try:
31
37
  return self.replace_placeholders(self.__content, params)
32
38
  except KeyError as e:
39
+ logger.exception("Exception occurred when parsing prompt %s... %s", self.__get_content_short(), e)
33
40
  self.__exception_handler.handle(e)
34
41
 
35
42
  raise Exception(f"Error while substituting values for prompt")
36
43
 
37
44
  def get_content(self) -> str:
38
45
  return self.__content
46
+
47
+ def __get_content_short(self):
48
+ if len(self.__content) > 15:
49
+ return self.__content[:15]
50
+ else:
51
+ return self.__content
igbot_base/retriever.py CHANGED
@@ -22,3 +22,10 @@ class Retriever(ABC):
22
22
  @abstractmethod
23
23
  def get_relevant_data(self, query: str) -> RetrieverResponse:
24
24
  pass
25
+
26
+ @abstractmethod
27
+ def describe(self):
28
+ pass
29
+
30
+ def __str__(self):
31
+ return self.describe()
igbot_base/tool.py CHANGED
@@ -18,3 +18,10 @@ class Tool(ABC):
18
18
  @abstractmethod
19
19
  def get_definition(self):
20
20
  pass
21
+
22
+ @abstractmethod
23
+ def describe(self):
24
+ pass
25
+
26
+ def __str__(self):
27
+ return self.describe()
igbot_base/vectorstore.py CHANGED
@@ -1,6 +1,9 @@
1
1
  from abc import ABC, abstractmethod
2
2
 
3
3
  from igbot_base.retriever import Retriever
4
+ from igbot_base.logging_adapter import get_logger
5
+
6
+ logger = get_logger("application")
4
7
 
5
8
 
6
9
  class Metadata:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: igbot_base
3
- Version: 0.0.9
3
+ Version: 0.0.11
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
@@ -0,0 +1,25 @@
1
+ igbot_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ igbot_base/agent.py,sha256=xU1jDgoyfXfSJlXcdLl1Va7BX-Z5QLXz4ZpjOuz2z9M,301
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
6
+ igbot_base/llmmemory.py,sha256=I6eSBPW1DK8UNiHhayon-DLbSbWSinO_EwM5S8C3tHA,1090
7
+ igbot_base/logging_adapter.py,sha256=kMuAaQPCba2luk0-WPxAbPNJaBL1yZsaff35ltKWgww,256
8
+ igbot_base/models.py,sha256=15bitUZy4Z4JhZbLd_SMx5pD7m8YuZiIq-wYGumf0ws,622
9
+ igbot_base/persistable_memory.py,sha256=867Z4l_awD23QSTFDK3uN9TEttKfDpxx9g19c7ULG1Y,167
10
+ igbot_base/prompt_template.py,sha256=q7bnU2Rp2Cvm4ixEmKHCyuolTPan6CHfYVAomT5kp10,1573
11
+ igbot_base/response_formats.py,sha256=Sp679VfkcyxsR19ddFEHTOM7Ox0u2WBhdji_Y9pVc2M,94
12
+ igbot_base/retriever.py,sha256=YHBHxiuPttsIAtjwwIz0fa9q2uFtsg0WoMRCorCt1PM,635
13
+ igbot_base/tool.py,sha256=ghjuU3cK_VElHGStUl3IYf9dlRDOGM_aQucUQNUH3mU,431
14
+ igbot_base/vectorstore.py,sha256=f-S9DmOuehC0rtVAPGz22Guo7ddb1jVw7BygzFJM624,928
15
+ igbot_base/exception/agent_exception.py,sha256=qDnVYMpzaiwkhO4QI-zasySFewoA7T9ee2XIe-0E-DI,395
16
+ igbot_base/exception/base_exception.py,sha256=Hlu_hNRW4Krx41CdUtYYaxI4VknKUw1Bs1stpm2XFTY,307
17
+ igbot_base/exception/llm_exception.py,sha256=54oAekBvzjL6x_JckqbY34m54EAh3GKRAwJJQ8ZjkvQ,377
18
+ igbot_base/exception/memory_exception.py,sha256=ZGKw3dN2tMf9XHacYaVTXgvYpWi14z7unJBFjrEUVyM,413
19
+ igbot_base/exception/prompt_exception.py,sha256=_u-O9E2Z1DK_OT4StyOmIDLfr_Mmk4k0GLe67kIoQNc,413
20
+ igbot_base/exception/retriever_exception.py,sha256=A46sBV6_1N3jgBl-nFRw4KgEcz3oPb8d5Eb83YWDEPo,431
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,,
@@ -1,17 +0,0 @@
1
- igbot_base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- igbot_base/agent.py,sha256=186kf599wrK4z41RVddeh0dH_iJ-_fCTqxM7J00P8IE,188
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=XNd_HyR2jK_7XlDW-2rdSaSCmVjRLAl_fdVTC2sW0HU,1461
6
- igbot_base/llmmemory.py,sha256=KslOeTSZwvHVyFglbFhPcb6_GCCXZOqHz5YBTzJ2mew,977
7
- igbot_base/models.py,sha256=15bitUZy4Z4JhZbLd_SMx5pD7m8YuZiIq-wYGumf0ws,622
8
- igbot_base/persistable_memory.py,sha256=867Z4l_awD23QSTFDK3uN9TEttKfDpxx9g19c7ULG1Y,167
9
- igbot_base/prompt_template.py,sha256=YHJDbe-33Zs202DMh6gLY_lLDejcyqB9xmek6xnyE0Q,1106
10
- igbot_base/response_formats.py,sha256=Sp679VfkcyxsR19ddFEHTOM7Ox0u2WBhdji_Y9pVc2M,94
11
- igbot_base/retriever.py,sha256=TeHWi6Sy5EvmmXOnNXuWLJO1Imlj0i6CEihv3WVN0SI,523
12
- igbot_base/tool.py,sha256=8QwzQuokkVSITCjZuZJeEbCvJU-n2yh9D-QauQex4Ko,319
13
- igbot_base/vectorstore.py,sha256=Q1ZRlsJ45ckgFZuPPQVMWuYl3W_L-HiX9VJIJ0wnjU8,842
14
- igbot_base-0.0.9.dist-info/METADATA,sha256=Vp252wgk01DCuFYmC6KxzXzpu1_h0QRVDSXNVNsLZh8,210
15
- igbot_base-0.0.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
16
- igbot_base-0.0.9.dist-info/top_level.txt,sha256=RGpEN0pLsnfNLoLfpw1D_nLSyZwi3ggSaDq07o4ZEAI,11
17
- igbot_base-0.0.9.dist-info/RECORD,,