igbot-base 0.0.10__tar.gz → 0.0.12__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.10 → igbot_base-0.0.12}/PKG-INFO +1 -1
- igbot_base-0.0.12/igbot_base/agent.py +33 -0
- igbot_base-0.0.12/igbot_base/exception/agent_exception.py +14 -0
- igbot_base-0.0.12/igbot_base/exception/base_exception.py +12 -0
- igbot_base-0.0.12/igbot_base/exception/llm_exception.py +13 -0
- igbot_base-0.0.12/igbot_base/exception/memory_exception.py +14 -0
- igbot_base-0.0.12/igbot_base/exception/prompt_exception.py +14 -0
- igbot_base-0.0.12/igbot_base/exception/retriever_exception.py +14 -0
- igbot_base-0.0.12/igbot_base/exception/tool_exception.py +14 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/exception_handler.py +8 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/llm.py +5 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/llmmemory.py +7 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/prompt_template.py +3 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/retriever.py +7 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/tool.py +7 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base.egg-info/PKG-INFO +1 -1
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base.egg-info/SOURCES.txt +8 -1
- {igbot_base-0.0.10 → igbot_base-0.0.12}/pyproject.toml +1 -1
- igbot_base-0.0.10/igbot_base/agent.py +0 -10
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/__init__.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/agent_response.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/logging_adapter.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/models.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/persistable_memory.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/response_formats.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base/vectorstore.py +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base.egg-info/dependency_links.txt +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base.egg-info/requires.txt +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/igbot_base.egg-info/top_level.txt +0 -0
- {igbot_base-0.0.10 → igbot_base-0.0.12}/setup.cfg +0 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
|
3
|
+
from igbot_base.agent_response import AgentResponse
|
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
|
+
|
10
|
+
|
11
|
+
class Agent(ABC):
|
12
|
+
|
13
|
+
def __init__(self, name, exception_handler: ExceptionHandler = ReturnFailedResponseGracefully):
|
14
|
+
self.__name = name
|
15
|
+
self.__ex_handler = exception_handler
|
16
|
+
|
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:
|
26
|
+
pass
|
27
|
+
|
28
|
+
@abstractmethod
|
29
|
+
def describe(self):
|
30
|
+
pass
|
31
|
+
|
32
|
+
def __str__(self):
|
33
|
+
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
|
+
|
@@ -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)
|
@@ -25,6 +25,9 @@ class Llm(ABC):
|
|
25
25
|
self._format = response_format
|
26
26
|
self._exception_handler = llm_exception_handler
|
27
27
|
|
28
|
+
def __str__(self):
|
29
|
+
return f"Llm({self._name} {self._model.get_name()})"
|
30
|
+
|
28
31
|
@abstractmethod
|
29
32
|
def _call(self, user_query: str, history: LlmMemory, params: dict) -> str:
|
30
33
|
pass
|
@@ -33,6 +36,7 @@ class Llm(ABC):
|
|
33
36
|
history.revert_to_snapshot()
|
34
37
|
|
35
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)
|
36
40
|
history.set_snapshot()
|
37
41
|
try:
|
38
42
|
response = self._call(user_query, history, params)
|
@@ -52,3 +56,4 @@ class Llm(ABC):
|
|
52
56
|
args["response_format"] = self._format
|
53
57
|
|
54
58
|
return args
|
59
|
+
|
@@ -18,6 +18,9 @@ class Prompt:
|
|
18
18
|
self.__variables = variables
|
19
19
|
self.__exception_handler = exception_handler
|
20
20
|
|
21
|
+
def __str__(self):
|
22
|
+
return f"Prompt({self.__get_content_short()} ({",".join(self.__variables)}))"
|
23
|
+
|
21
24
|
@staticmethod
|
22
25
|
def replace_placeholders(text: str, values: dict) -> str:
|
23
26
|
def replacer(match):
|
@@ -17,4 +17,11 @@ igbot_base.egg-info/PKG-INFO
|
|
17
17
|
igbot_base.egg-info/SOURCES.txt
|
18
18
|
igbot_base.egg-info/dependency_links.txt
|
19
19
|
igbot_base.egg-info/requires.txt
|
20
|
-
igbot_base.egg-info/top_level.txt
|
20
|
+
igbot_base.egg-info/top_level.txt
|
21
|
+
igbot_base/exception/agent_exception.py
|
22
|
+
igbot_base/exception/base_exception.py
|
23
|
+
igbot_base/exception/llm_exception.py
|
24
|
+
igbot_base/exception/memory_exception.py
|
25
|
+
igbot_base/exception/prompt_exception.py
|
26
|
+
igbot_base/exception/retriever_exception.py
|
27
|
+
igbot_base/exception/tool_exception.py
|
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
|