swarmauri-base 0.6.0.dev4__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.
Files changed (74) hide show
  1. swarmauri_base/agents/AgentBase.py +16 -0
  2. swarmauri_base/agents/AgentConversationMixin.py +8 -0
  3. swarmauri_base/agents/AgentRetrieveMixin.py +10 -0
  4. swarmauri_base/agents/AgentSystemContextMixin.py +15 -0
  5. swarmauri_base/agents/AgentToolMixin.py +9 -0
  6. swarmauri_base/agents/AgentVectorStoreMixin.py +8 -0
  7. swarmauri_base/agents/__init__.py +0 -0
  8. swarmauri_base/chains/ChainBase.py +34 -0
  9. swarmauri_base/chains/ChainContextBase.py +46 -0
  10. swarmauri_base/chains/ChainStepBase.py +18 -0
  11. swarmauri_base/chains/PromptContextChainBase.py +154 -0
  12. swarmauri_base/chains/__init__.py +1 -0
  13. swarmauri_base/chunkers/ChunkerBase.py +19 -0
  14. swarmauri_base/chunkers/__init__.py +0 -0
  15. swarmauri_base/control_panels/ControlPanelBase.py +99 -0
  16. swarmauri_base/control_panels/__init__.py +0 -0
  17. swarmauri_base/conversations/ConversationBase.py +50 -0
  18. swarmauri_base/conversations/ConversationSystemContextMixin.py +8 -0
  19. swarmauri_base/conversations/__init__.py +0 -0
  20. swarmauri_base/data_connectors/DataConnectorBase.py +79 -0
  21. swarmauri_base/data_connectors/__init__.py +0 -0
  22. swarmauri_base/distances/DistanceBase.py +35 -0
  23. swarmauri_base/distances/VisionDistanceBase.py +7 -0
  24. swarmauri_base/distances/__init__.py +0 -0
  25. swarmauri_base/document_stores/DocumentStoreBase.py +88 -0
  26. swarmauri_base/document_stores/DocumentStoreRetrieveBase.py +22 -0
  27. swarmauri_base/document_stores/__init__.py +0 -0
  28. swarmauri_base/documents/DocumentBase.py +14 -0
  29. swarmauri_base/documents/__init__.py +0 -0
  30. swarmauri_base/embeddings/EmbeddingBase.py +11 -0
  31. swarmauri_base/embeddings/VisionEmbeddingBase.py +7 -0
  32. swarmauri_base/embeddings/__init__.py +1 -0
  33. swarmauri_base/factories/FactoryBase.py +31 -0
  34. swarmauri_base/factories/_init__.py +0 -0
  35. swarmauri_base/image_gens/ImageGenBase.py +51 -0
  36. swarmauri_base/image_gens/__init__.py +0 -0
  37. swarmauri_base/llms/LLMBase.py +41 -0
  38. swarmauri_base/llms/__init__.py +0 -0
  39. swarmauri_base/measurements/MeasurementAggregateMixin.py +25 -0
  40. swarmauri_base/measurements/MeasurementBase.py +23 -0
  41. swarmauri_base/measurements/MeasurementCalculateMixin.py +32 -0
  42. swarmauri_base/measurements/MeasurementThresholdMixin.py +8 -0
  43. swarmauri_base/measurements/__init__.py +0 -0
  44. swarmauri_base/messages/MessageBase.py +12 -0
  45. swarmauri_base/messages/__init__.py +0 -0
  46. swarmauri_base/parsers/ParserBase.py +28 -0
  47. swarmauri_base/parsers/__init__.py +0 -0
  48. swarmauri_base/pipelines/PipelineBase.py +105 -0
  49. swarmauri_base/pipelines/__init__.py +0 -0
  50. swarmauri_base/prompts/PromptBase.py +37 -0
  51. swarmauri_base/prompts/PromptGeneratorBase.py +40 -0
  52. swarmauri_base/prompts/PromptMatrixBase.py +37 -0
  53. swarmauri_base/prompts/PromptTemplateBase.py +39 -0
  54. swarmauri_base/prompts/__init__.py +0 -0
  55. swarmauri_base/schema_converters/SchemaConverterBase.py +15 -0
  56. swarmauri_base/schema_converters/__init__.py +0 -0
  57. swarmauri_base/service_registries/ServiceRegistryBase.py +60 -0
  58. swarmauri_base/service_registries/__init__.py +0 -0
  59. swarmauri_base/state/StateBase.py +47 -0
  60. swarmauri_base/state/__init__.py +0 -0
  61. swarmauri_base/swarm/SwarmBase.py +101 -0
  62. swarmauri_base/swarm/__init__.py +0 -0
  63. swarmauri_base/task_mgmt_strategies/TaskMgtStrategyBase.py +63 -0
  64. swarmauri_base/task_mgmt_strategies/__init__.py +0 -0
  65. swarmauri_base/toolkits/ToolkitBase.py +96 -0
  66. swarmauri_base/toolkits/__init__.py +0 -0
  67. swarmauri_base/tools/ParameterBase.py +13 -0
  68. swarmauri_base/tools/ToolBase.py +64 -0
  69. swarmauri_base/tools/__init__.py +0 -0
  70. swarmauri_base/transports/TransportBase.py +50 -0
  71. swarmauri_base/transports/__init__.py +0 -0
  72. swarmauri_base-0.6.0.dev4.dist-info/METADATA +58 -0
  73. swarmauri_base-0.6.0.dev4.dist-info/RECORD +74 -0
  74. swarmauri_base-0.6.0.dev4.dist-info/WHEEL +4 -0
@@ -0,0 +1,39 @@
1
+ from typing import Dict, List, Union, Optional, Literal
2
+ from pydantic import Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.prompts.IPrompt import IPrompt
5
+ from swarmauri_core.prompts.ITemplate import ITemplate
6
+
7
+ class PromptTemplateBase(IPrompt, ITemplate, ComponentBase):
8
+ """
9
+ A class for generating prompts based on a template and variables.
10
+ Implements the IPrompt for generating prompts and ITemplate for template manipulation.
11
+ """
12
+
13
+ template: str = ""
14
+ variables: Union[List[Dict[str, str]], Dict[str,str]] = {}
15
+ resource: Optional[str] = Field(default=ResourceTypes.PROMPT.value, frozen=True)
16
+ type: Literal['PromptTemplateBase'] = 'PromptTemplateBase'
17
+
18
+ def set_template(self, template: str) -> None:
19
+ """
20
+ Sets or updates the current template string.
21
+ """
22
+ self.template = template
23
+
24
+ def set_variables(self, variables: Dict[str, str]) -> None:
25
+ """
26
+ Sets or updates the variables to be substituted into the template.
27
+ """
28
+ self.variables = variables
29
+
30
+ def generate_prompt(self, variables: Dict[str, str] = None) -> str:
31
+ variables = variables or self.variables
32
+ return self.template.format(**variables)
33
+
34
+ def __call__(self, variables: Optional[Dict[str, str]] = None) -> str:
35
+ """
36
+ Generates a prompt using the current template and provided keyword arguments for substitution.
37
+ """
38
+ variables = variables if variables else self.variables
39
+ return self.generate_prompt(variables)
File without changes
@@ -0,0 +1,15 @@
1
+ from abc import abstractmethod
2
+ from typing import Optional, Dict, Any, Literal
3
+ from pydantic import ConfigDict, Field
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri_core.schema_converters.ISchemaConvert import ISchemaConvert
6
+ from swarmauri_core.tools.ITool import ITool
7
+
8
+ class SchemaConverterBase(ISchemaConvert, ComponentBase):
9
+ model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)
10
+ resource: Optional[str] = Field(default=ResourceTypes.SCHEMA_CONVERTER.value, frozen=True)
11
+ type: Literal['SchemaConverterBase'] = 'SchemaConverterBase'
12
+
13
+ @abstractmethod
14
+ def convert(self, tool: ITool) -> Dict[str, Any]:
15
+ raise NotImplementedError("Subclasses must implement the convert method.")
File without changes
@@ -0,0 +1,60 @@
1
+ from typing import Dict, Any, List, Literal, Optional
2
+
3
+ from pydantic import ConfigDict, Field
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri_core.service_registries.IServiceRegistry import IServiceRegistry
6
+
7
+
8
+ class ServiceRegistryBase(IServiceRegistry, ComponentBase):
9
+ """
10
+ Concrete implementation of the IServiceRegistry abstract base class.
11
+ """
12
+
13
+ services: Dict[str, Any] = {}
14
+ type: Literal["ServiceRegistryBase"] = "ServiceRegistryBase"
15
+ resource: Optional[str] = Field(
16
+ default=ResourceTypes.SERVICE_REGISTRY.value, frozen=True
17
+ )
18
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
19
+
20
+ def register_service(self, name: str, details: Dict[str, Any]) -> None:
21
+ """
22
+ Register a new service with the given name and details.
23
+ """
24
+ self.services[name] = details
25
+
26
+ def get_service(self, name: str) -> Optional[Dict[str, Any]]:
27
+ """
28
+ Retrieve a service by its name.
29
+ """
30
+ return self.services.get(name)
31
+
32
+ def get_services_by_roles(self, roles: List[str]) -> List[str]:
33
+ """
34
+ Get services filtered by their roles.
35
+ """
36
+ return [
37
+ name
38
+ for name, details in self.services.items()
39
+ if details.get("role") in roles
40
+ ]
41
+
42
+ def unregister_service(self, name: str) -> None:
43
+ """
44
+ unregister the service with the given name.
45
+ """
46
+ if name in self.services:
47
+ del self.services[name]
48
+ print(f"Service {name} unregistered.")
49
+ else:
50
+ raise ValueError(f"Service {name} not found.")
51
+
52
+ def update_service(self, name: str, details: Dict[str, Any]) -> None:
53
+ """
54
+ Update the details of the service with the given name.
55
+ """
56
+ if name in self.services:
57
+ self.services[name].update(details)
58
+ print(f"Service {name} updated with new details: {details}")
59
+ else:
60
+ raise ValueError(f"Service {name} not found.")
File without changes
@@ -0,0 +1,47 @@
1
+ from typing import Dict, Any, Optional, Literal
2
+ from pydantic import Field, ConfigDict
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.state.IState import IState
5
+
6
+
7
+ class StateBase(IState, ComponentBase):
8
+ """
9
+ Abstract base class for state management, extending IState and ComponentBase.
10
+ """
11
+
12
+ state_data: Dict[str, Any] = Field(
13
+ default_factory=dict, description="The current state data."
14
+ )
15
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
16
+ resource: Optional[str] = Field(default=ResourceTypes.STATE.value, frozen=True)
17
+ type: Literal["StateBase"] = "StateBase"
18
+
19
+ def read(self) -> Dict[str, Any]:
20
+ """
21
+ Reads and returns the current state as a dictionary.
22
+ """
23
+ raise NotImplementedError("Subclasses must implement 'read'.")
24
+
25
+ def write(self, data: Dict[str, Any]) -> None:
26
+ """
27
+ Replaces the current state with the given data.
28
+ """
29
+ raise NotImplementedError("Subclasses must implement 'write'.")
30
+
31
+ def update(self, data: Dict[str, Any]) -> None:
32
+ """
33
+ Updates the state with the given data.
34
+ """
35
+ raise NotImplementedError("Subclasses must implement 'update'.")
36
+
37
+ def reset(self) -> None:
38
+ """
39
+ Resets the state to its initial state.
40
+ """
41
+ raise NotImplementedError("Subclasses must implement 'reset'.")
42
+
43
+ def deep_copy(self) -> "IState":
44
+ """
45
+ Creates a deep copy of the current state.
46
+ """
47
+ raise NotImplementedError("Subclasses must implement 'deep_copy'.")
File without changes
@@ -0,0 +1,101 @@
1
+ import asyncio
2
+ from typing import Any, Dict, List, Literal, Optional, Union
3
+ from pydantic import ConfigDict, Field
4
+ from enum import Enum
5
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
6
+ from swarmauri_core.swarms.ISwarm import ISwarm
7
+
8
+
9
+ class SwarmStatus(Enum):
10
+ IDLE = "IDLE"
11
+ WORKING = "WORKING"
12
+ COMPLETED = "COMPLETED"
13
+ FAILED = "FAILED"
14
+
15
+
16
+ class SwarmBase(ISwarm, ComponentBase):
17
+ """Base class for Swarm implementations"""
18
+
19
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
20
+ resource: Optional[str] = Field(default=ResourceTypes.SWARM.value, frozen=True)
21
+ type: Literal["SwarmBase"] = "SwarmBase"
22
+
23
+ num_agents: int = Field(default=5, gt=0, le=100)
24
+ agent_timeout: float = Field(default=1.0, gt=0)
25
+ max_retries: int = Field(default=3, ge=0)
26
+ max_queue_size: int = Field(default=10, gt=0)
27
+
28
+ _agents: List[Any] = []
29
+ _task_queue: Optional[asyncio.Queue] = None
30
+ _status: Dict[int, SwarmStatus] = {}
31
+
32
+ def __init__(self, **kwargs):
33
+ super().__init__(**kwargs)
34
+ self._task_queue = asyncio.Queue(maxsize=self.max_queue_size)
35
+ self._initialize_agents()
36
+
37
+ def _initialize_agents(self):
38
+ self._agents = [self._create_agent() for _ in range(self.num_agents)]
39
+ self._status = {i: SwarmStatus.IDLE for i in range(self.num_agents)}
40
+
41
+ def _create_agent(self) -> Any:
42
+ """create specific agent types"""
43
+ raise NotImplementedError("Agent creation method not implemented")
44
+
45
+ @property
46
+ def agents(self) -> List[Any]:
47
+ return self._agents
48
+
49
+ @property
50
+ def queue_size(self) -> int:
51
+ return self._task_queue.qsize()
52
+
53
+ def get_swarm_status(self) -> Dict[int, SwarmStatus]:
54
+ return self._status
55
+
56
+ async def _process_task(self, agent_id: int, task: Any, **kwargs) -> Any:
57
+ self._status[agent_id] = SwarmStatus.WORKING
58
+ try:
59
+ for _ in range(self.max_retries):
60
+ try:
61
+ result = await asyncio.wait_for(
62
+ self._execute_task(task, agent_id, **kwargs),
63
+ timeout=self.agent_timeout,
64
+ )
65
+ self._status[agent_id] = SwarmStatus.COMPLETED
66
+ return result
67
+ except asyncio.TimeoutError:
68
+ continue
69
+ self._status[agent_id] = SwarmStatus.FAILED
70
+ return None
71
+ except Exception as e:
72
+ self._status[agent_id] = SwarmStatus.FAILED
73
+ raise e
74
+
75
+ async def _execute_task(self, task: Any, agent_id: int) -> Any:
76
+ """Override this method to implement specific task execution logic"""
77
+ raise NotImplementedError("Task execution method not implemented")
78
+
79
+ async def exec(
80
+ self, input_data: Union[List[str], Any] = [], **kwargs: Optional[Dict]
81
+ ) -> List[Any]:
82
+ tasks = input_data if isinstance(input_data, list) else [input_data]
83
+ for task in tasks:
84
+ await self._task_queue.put(task)
85
+
86
+ results = []
87
+ while not self._task_queue.empty():
88
+ available_agents = [
89
+ i for i, status in self._status.items() if status == SwarmStatus.IDLE
90
+ ]
91
+ if not available_agents:
92
+ await asyncio.sleep(0.1)
93
+ continue
94
+
95
+ task = await self._task_queue.get()
96
+ agent_id = available_agents[0]
97
+ result = await self._process_task(agent_id, task, **kwargs)
98
+ if result is not None:
99
+ results.append(result)
100
+
101
+ return results
File without changes
@@ -0,0 +1,63 @@
1
+ from abc import abstractmethod
2
+
3
+ from pydantic import ConfigDict, Field
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri_core.task_mgt_strategies.ITaskMgtStrategy import ITaskMgtStrategy
6
+ from typing import Any, Callable, Dict, Literal, Optional
7
+
8
+
9
+ class TaskMgtStrategyBase(ITaskMgtStrategy, ComponentBase):
10
+ """Base class for TaskStrategy."""
11
+
12
+ type: Literal["TaskMgtStrategyBase"] = "TaskMgtStrategyBase"
13
+ resource: Optional[str] = Field(
14
+ default=ResourceTypes.TASK_MGT_STRATEGY.value, frozen=True
15
+ )
16
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
17
+
18
+ @abstractmethod
19
+ def assign_task(
20
+ self, task: Dict[str, Any], agent_factory: Callable, service_registry: Callable
21
+ ) -> str:
22
+ """
23
+ Abstract method to assign a task to a service.
24
+ """
25
+ raise NotImplementedError(
26
+ "assign_task method must be implemented in derived classes."
27
+ )
28
+
29
+ @abstractmethod
30
+ def add_task(self, task: Dict[str, Any]) -> None:
31
+ """
32
+ Abstract method to add a task to the task queue.
33
+ """
34
+ raise NotImplementedError(
35
+ "add_task method must be implemented in derived classes."
36
+ )
37
+
38
+ @abstractmethod
39
+ def remove_task(self, task_id: str) -> None:
40
+ """
41
+ Abstract method to remove a task from the task queue.
42
+ """
43
+ raise NotImplementedError(
44
+ "remove_task method must be implemented in derived classes."
45
+ )
46
+
47
+ @abstractmethod
48
+ def get_task(self, task_id: str) -> Dict[str, Any]:
49
+ """
50
+ Abstract method to get a task from the task queue.
51
+ """
52
+ raise NotImplementedError(
53
+ "get_task method must be implemented in derived classes."
54
+ )
55
+
56
+ @abstractmethod
57
+ def process_tasks(self, task: Dict[str, Any]) -> None:
58
+ """
59
+ Abstract method to process tasks.
60
+ """
61
+ raise NotImplementedError(
62
+ "process_task method must be implemented in derived classes."
63
+ )
File without changes
@@ -0,0 +1,96 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Dict, Optional, List, Literal
3
+ from pydantic import Field, ConfigDict
4
+ from swarmauri_core.typing import SubclassUnion
5
+ from swarmauri.tools.base.ToolBase import ToolBase
6
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
7
+ from swarmauri_core.toolkits.IToolkit import IToolkit
8
+
9
+
10
+
11
+ class ToolkitBase(IToolkit, ComponentBase):
12
+ """
13
+ A class representing a toolkit used by Swarm Agents.
14
+ Tools are maintained in a dictionary keyed by the tool's name.
15
+ """
16
+
17
+ tools: Dict[str, SubclassUnion[ToolBase]] = {}
18
+ resource: Optional[str] = Field(default=ResourceTypes.TOOLKIT.value, frozen=True)
19
+ model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)
20
+ type: Literal['ToolkitBase'] = 'ToolkitBase'
21
+
22
+ def get_tools(self,
23
+ include: Optional[List[str]] = None,
24
+ exclude: Optional[List[str]] = None,
25
+ by_alias: bool = False,
26
+ exclude_unset: bool = False,
27
+ exclude_defaults: bool = False,
28
+ exclude_none: bool = False
29
+ ) -> Dict[str, SubclassUnion[ToolBase]]:
30
+ """
31
+ List all tools in the toolkit with options to include or exclude specific fields.
32
+
33
+ Parameters:
34
+ include (List[str], optional): Fields to include in the returned dictionary.
35
+ exclude (List[str], optional): Fields to exclude from the returned dictionary.
36
+
37
+ Returns:
38
+ Dict[str, SubclassUnion[ToolBase]]: A dictionary of tools with specified fields included or excluded.
39
+ """
40
+ return [tool.model_dump(include=include, exclude=exclude, by_alias=by_alias,
41
+ exclude_unset=exclude_unset, exclude_defaults=exclude_defaults,
42
+ exclude_none=exclude_none) for name, tool in self.tools.items()]
43
+
44
+ def add_tools(self, tools: Dict[str, SubclassUnion[ToolBase]]) -> None:
45
+ """
46
+ Add multiple tools to the toolkit.
47
+
48
+ Parameters:
49
+ tools (Dict[str, Tool]): A dictionary of tool objects keyed by their names.
50
+ """
51
+ self.tools.update(tools)
52
+
53
+ def add_tool(self, tool: SubclassUnion[ToolBase]) -> None:
54
+ """
55
+ Add a single tool to the toolkit.
56
+
57
+ Parameters:
58
+ tool (Tool): The tool instance to be added to the toolkit.
59
+ """
60
+ self.tools[tool.name] = tool
61
+
62
+ def remove_tool(self, tool_name: str) -> None:
63
+ """
64
+ Remove a tool from the toolkit by name.
65
+
66
+ Parameters:
67
+ tool_name (str): The name of the tool to be removed from the toolkit.
68
+ """
69
+ if tool_name in self.tools:
70
+ del self.tools[tool_name]
71
+ else:
72
+ raise ValueError(f"Tool '{tool_name}' not found in the toolkit.")
73
+
74
+ def get_tool_by_name(self, tool_name: str) -> SubclassUnion[ToolBase]:
75
+ """
76
+ Get a tool from the toolkit by name.
77
+
78
+ Parameters:
79
+ tool_name (str): The name of the tool to retrieve.
80
+
81
+ Returns:
82
+ Tool: The tool instance with the specified name.
83
+ """
84
+ if tool_name in self.tools:
85
+ return self.tools[tool_name]
86
+ else:
87
+ raise ValueError(f"Tool '{tool_name}' not found in the toolkit.")
88
+
89
+ def __len__(self) -> int:
90
+ """
91
+ Returns the number of tools in the toolkit.
92
+
93
+ Returns:
94
+ int: The number of tools in the toolkit.
95
+ """
96
+ return len(self.tools)
File without changes
@@ -0,0 +1,13 @@
1
+ from typing import Optional, List, Any
2
+ from pydantic import Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.tools.IParameter import IParameter
5
+
6
+
7
+ class ParameterBase(IParameter, ComponentBase):
8
+ name: str
9
+ description: str
10
+ required: bool = False
11
+ enum: Optional[List[str]] = None
12
+ resource: Optional[str] = Field(default=ResourceTypes.PARAMETER.value)
13
+ type: str # THIS DOES NOT USE LITERAL
@@ -0,0 +1,64 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Optional, List, Any, Literal
3
+ from pydantic import Field
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri.tools.base.ParameterBase import ParameterBase as Parameter
6
+ from swarmauri_core.tools.ITool import ITool
7
+
8
+
9
+ class ToolBase(ITool, ComponentBase, ABC):
10
+ name: str
11
+ description: Optional[str] = None
12
+ parameters: List[Parameter] = Field(default_factory=list)
13
+ resource: Optional[str] = Field(default=ResourceTypes.TOOL.value)
14
+ type: Literal["ToolBase"] = "ToolBase"
15
+
16
+ def call(self, *args, **kwargs):
17
+ return self.__call__(*args, **kwargs)
18
+
19
+ @abstractmethod
20
+ def __call__(self, *args, **kwargs):
21
+ raise NotImplementedError("Subclasses must implement the __call__ method.")
22
+
23
+
24
+ # #def __getstate__(self):
25
+ # return {'type': self.type, 'function': self.function}
26
+
27
+
28
+ # def __iter__(self):
29
+ # yield ('type', self.type)
30
+ # yield ('function', self.function)
31
+
32
+ # @property
33
+ # def function(self):
34
+ # # Dynamically constructing the parameters schema
35
+ # properties = {}
36
+ # required = []
37
+
38
+ # for param in self.parameters:
39
+ # properties[param.name] = {
40
+ # "type": param.type,
41
+ # "description": param.description,
42
+ # }
43
+ # if param.enum:
44
+ # properties[param.name]['enum'] = param.enum
45
+
46
+ # if param.required:
47
+ # required.append(param.name)
48
+
49
+ # function = {
50
+ # "name": self.name,
51
+ # "description": self.description,
52
+ # "parameters": {
53
+ # "type": "object",
54
+ # "properties": properties,
55
+ # }
56
+ # }
57
+
58
+ # if required: # Only include 'required' if there are any required parameters
59
+ # function['parameters']['required'] = required
60
+ # return function
61
+
62
+ # def as_dict(self):
63
+ # #return asdict(self)
64
+ # return {'type': self.type, 'function': self.function}
File without changes
@@ -0,0 +1,50 @@
1
+ from typing import Dict, Any, List, Optional, Literal
2
+ from pydantic import ConfigDict, Field
3
+ from enum import Enum, auto
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri_core.transports.ITransport import ITransport
6
+
7
+
8
+ class TransportProtocol(Enum):
9
+ """
10
+ Enumeration of transportation protocols supported by the transport layer
11
+ """
12
+
13
+ UNICAST = auto()
14
+ MULTICAST = auto()
15
+ BROADCAST = auto()
16
+ PUBSUB = auto()
17
+
18
+
19
+ class TransportBase(ITransport, ComponentBase):
20
+ allowed_protocols: List[TransportProtocol] = []
21
+ resource: Optional[str] = Field(default=ResourceTypes.TRANSPORT.value, frozen=True)
22
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
23
+ type: Literal["TransportBase"] = "TransportBase"
24
+
25
+ def send(self, sender: str, recipient: str, message: Any) -> None:
26
+ """
27
+ Send a message to a specific recipient.
28
+
29
+ Raises:
30
+ NotImplementedError: Subclasses must implement this method.
31
+ """
32
+ raise NotImplementedError("send() not implemented in subclass yet.")
33
+
34
+ def broadcast(self, sender: str, message: Any) -> None:
35
+ """
36
+ Broadcast a message to all potential recipients.
37
+
38
+ Raises:
39
+ NotImplementedError: Subclasses must implement this method.
40
+ """
41
+ raise NotImplementedError("broadcast() not implemented in subclass yet.")
42
+
43
+ def multicast(self, sender: str, recipients: List[str], message: Any) -> None:
44
+ """
45
+ Send a message to multiple specific recipients.
46
+
47
+ Raises:
48
+ NotImplementedError: Subclasses must implement this method.
49
+ """
50
+ raise NotImplementedError("multicast() not implemented in subclass yet.")
File without changes
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.1
2
+ Name: swarmauri-base
3
+ Version: 0.6.0.dev4
4
+ Summary: This repository includes base classes and mixins for the Swarmauri framework.
5
+ Home-page: http://github.com/swarmauri/swarmauri-sdk
6
+ License: Apache-2.0
7
+ Author: Jacob Stewart
8
+ Author-email: jacob@swarmauri.com
9
+ Requires-Python: >=3.10,<3.13
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Dist: pydantic (>=2.0,<3.0)
16
+ Requires-Dist: swarmauri_core (>=0.6.0.dev4,<0.7.0)
17
+ Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Core Library
21
+
22
+ The Core Library provides the foundational interfaces and abstract base classes necessary for developing scalable and flexible machine learning agents, models, and tools. It is designed to offer a standardized approach to implementing various components of machine learning systems, such as models, parsers, conversations, and vector stores.
23
+
24
+ ## Features
25
+
26
+ - **Models Interface**: Define and interact with predictive models.
27
+ - **Agents Interface**: Build and manage intelligent agents for varied tasks.
28
+ - **Tools Interface**: Develop tools with standardized execution and configuration.
29
+ - **Parsers and Conversations**: Handle and parse text data, manage conversations states.
30
+ - **Vector Stores**: Interface for vector storage and similarity searches.
31
+ - **Document Stores**: Manage the storage and retrieval of documents.
32
+ - **Retrievers and Chunkers**: Efficiently retrieve relevant documents and chunk large text data.
33
+
34
+ ## Getting Started
35
+
36
+ To start developing with the Core Library, include it as a module in your Python project. Ensure you have Python 3.6 or later installed.
37
+
38
+ ```python
39
+ # Example of using an abstract model interface from the Core Library
40
+ from swarmauri.core.models.IModel import IModel
41
+
42
+ class MyModel(IModel):
43
+ # Implement the abstract methods here
44
+ pass
45
+ ```
46
+
47
+ ## Documentation
48
+
49
+ For more detailed documentation on each interface and available abstract classes, refer to the [Docs](/docs) directory within the library.
50
+
51
+ ## Contributing
52
+
53
+ Contributions are welcome! If you'd like to add a new feature, fix a bug, or improve documentation, please submit a pull request.
54
+
55
+ ## License
56
+
57
+ See `LICENSE` for more information.
58
+