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,88 @@
1
+ import json
2
+ from abc import ABC, abstractmethod
3
+ from typing import List, Optional
4
+ from swarmauri_core.documents.IDocument import IDocument
5
+ from swarmauri_core.document_stores.IDocumentStore import IDocumentStore
6
+
7
+ class DocumentStoreBase(IDocumentStore, ABC):
8
+ """
9
+ Abstract base class for document stores, implementing the IDocumentStore interface.
10
+
11
+ This class provides a standard API for adding, updating, getting, and deleting documents in a store.
12
+ The specifics of storing (e.g., in a database, in-memory, or file system) are to be implemented by concrete subclasses.
13
+ """
14
+
15
+ @abstractmethod
16
+ def add_document(self, document: IDocument) -> None:
17
+ """
18
+ Add a single document to the document store.
19
+
20
+ Parameters:
21
+ - document (IDocument): The document to be added to the store.
22
+ """
23
+ pass
24
+
25
+ @abstractmethod
26
+ def add_documents(self, documents: List[IDocument]) -> None:
27
+ """
28
+ Add multiple documents to the document store in a batch operation.
29
+
30
+ Parameters:
31
+ - documents (List[IDocument]): A list of documents to be added to the store.
32
+ """
33
+ pass
34
+
35
+ @abstractmethod
36
+ def get_document(self, doc_id: str) -> Optional[IDocument]:
37
+ """
38
+ Retrieve a single document by its identifier.
39
+
40
+ Parameters:
41
+ - doc_id (str): The unique identifier of the document to retrieve.
42
+
43
+ Returns:
44
+ - Optional[IDocument]: The requested document if found; otherwise, None.
45
+ """
46
+ pass
47
+
48
+ @abstractmethod
49
+ def get_all_documents(self) -> List[IDocument]:
50
+ """
51
+ Retrieve all documents stored in the document store.
52
+
53
+ Returns:
54
+ - List[IDocument]: A list of all documents in the store.
55
+ """
56
+ pass
57
+
58
+ @abstractmethod
59
+ def update_document(self, doc_id: str, updated_document: IDocument) -> None:
60
+ """
61
+ Update a document in the document store.
62
+
63
+ Parameters:
64
+ - doc_id (str): The unique identifier of the document to update.
65
+ - updated_document (IDocument): The updated document instance.
66
+ """
67
+ pass
68
+
69
+ @abstractmethod
70
+ def delete_document(self, doc_id: str) -> None:
71
+ """
72
+ Delete a document from the document store by its identifier.
73
+
74
+ Parameters:
75
+ - doc_id (str): The unique identifier of the document to delete.
76
+ """
77
+ pass
78
+
79
+ def document_count(self):
80
+ return len(self.documents)
81
+
82
+ def dump(self, file_path):
83
+ with open(file_path, 'w') as f:
84
+ json.dumps([each.__dict__ for each in self.documents], f, indent=4)
85
+
86
+ def load(self, file_path):
87
+ with open(file_path, 'r') as f:
88
+ self.documents = json.loads(f)
@@ -0,0 +1,22 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import List
3
+ from swarmauri_core.document_stores.IDocumentRetrieve import IDocumentRetrieve
4
+ from swarmauri_core.documents.IDocument import IDocument
5
+ from swarmauri.document_stores.base.DocumentStoreBase import DocumentStoreBase
6
+
7
+ class DocumentStoreRetrieveBase(DocumentStoreBase, IDocumentRetrieve, ABC):
8
+
9
+
10
+ @abstractmethod
11
+ def retrieve(self, query: str, top_k: int = 5) -> List[IDocument]:
12
+ """
13
+ Retrieve the top_k most relevant documents based on the given query.
14
+
15
+ Args:
16
+ query (str): The query string used for document retrieval.
17
+ top_k (int): The number of top relevant documents to retrieve.
18
+
19
+ Returns:
20
+ List[IDocument]: A list of the top_k most relevant documents.
21
+ """
22
+ pass
File without changes
@@ -0,0 +1,14 @@
1
+ from typing import Dict, Optional, Literal
2
+ from pydantic import Field, ConfigDict
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.documents.IDocument import IDocument
5
+ from swarmauri.vectors.concrete.Vector import Vector
6
+
7
+
8
+ class DocumentBase(IDocument, ComponentBase):
9
+ content: str
10
+ metadata: Dict = {}
11
+ embedding: Optional[Vector] = None
12
+ model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)
13
+ resource: Optional[str] = Field(default=ResourceTypes.DOCUMENT.value, frozen=True)
14
+ type: Literal['DocumentBase'] = 'DocumentBase'
File without changes
@@ -0,0 +1,11 @@
1
+ from typing import Optional, Literal
2
+ from pydantic import Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.embeddings.IVectorize import IVectorize
5
+ from swarmauri_core.embeddings.IFeature import IFeature
6
+ from swarmauri_core.embeddings.ISaveModel import ISaveModel
7
+
8
+ class EmbeddingBase(IVectorize, IFeature, ISaveModel, ComponentBase):
9
+ resource: Optional[str] = Field(default=ResourceTypes.EMBEDDING.value, frozen=True)
10
+ type: Literal['EmbeddingBase'] = 'EmbeddingBase'
11
+
@@ -0,0 +1,7 @@
1
+ from typing import Optional, Literal
2
+ from pydantic import Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+
5
+ class VisionEmbeddingBase(ComponentBase):
6
+ resource: Optional[str] = Field(default=ResourceTypes.EMBEDDING.value, frozen=True)
7
+ type: Literal['VisionEmbeddingBase'] = 'VisionEmbeddingBase'
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,31 @@
1
+ from typing import Any, Callable, Literal, Optional
2
+ from swarmauri_core.ComponentBase import ComponentBase
3
+ from swarmauri_core.ComponentBase import ResourceTypes
4
+ from swarmauri_core.factories.IFactory import IFactory
5
+ from pydantic import ConfigDict, Field
6
+
7
+
8
+ class FactoryBase(IFactory, ComponentBase):
9
+ """
10
+ Base factory class for registering and creating instances.
11
+ """
12
+
13
+ resource: Optional[str] = Field(default=ResourceTypes.FACTORY.value, frozen=True)
14
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
15
+ type: Literal["FactoryBase"] = "FactoryBase"
16
+
17
+ def register(self, type: str, resource_class: Callable) -> None:
18
+ """
19
+ Register a resource class under a specific resource and type.
20
+ """
21
+ raise NotImplementedError(
22
+ "register method must be implemented in derived classes."
23
+ )
24
+
25
+ def create(self, type: str, *args: Any, **kwargs: Any) -> Any:
26
+ """
27
+ Create an instance of the class associated with the given resource and type.
28
+ """
29
+ raise NotImplementedError(
30
+ "create method must be implemented in derived classes."
31
+ )
File without changes
@@ -0,0 +1,51 @@
1
+ from abc import abstractmethod
2
+ from typing import Optional, List, Literal
3
+ from pydantic import ConfigDict, model_validator, Field
4
+ from swarmauri_core.image_gens.IGenImage import IGenImage
5
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
6
+
7
+
8
+ class ImageGenBase(IGenImage, ComponentBase):
9
+ allowed_models: List[str] = []
10
+ resource: Optional[str] = Field(default=ResourceTypes.IMAGE_GEN.value, frozen=True)
11
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
12
+ type: Literal["ImageGenBase"] = "ImageGenBase"
13
+
14
+ @model_validator(mode="after")
15
+ @classmethod
16
+ def _validate_name_in_allowed_models(cls, values):
17
+ name = values.name
18
+ allowed_models = values.allowed_models
19
+ if name and name not in allowed_models:
20
+ raise ValueError(
21
+ f"Model name {name} is not allowed. Choose from {allowed_models}"
22
+ )
23
+ return values
24
+
25
+ @abstractmethod
26
+ def generate_image(self, *args, **kwargs) -> any:
27
+ """
28
+ Generate images based on the input data provided to the model.
29
+ """
30
+ raise NotImplementedError("generate_image() not implemented in subclass yet.")
31
+
32
+ @abstractmethod
33
+ async def agenerate_image(self, *args, **kwargs) -> any:
34
+ """
35
+ Generate images based on the input data provided to the model.
36
+ """
37
+ raise NotImplementedError("agenerate_image() not implemented in subclass yet.")
38
+
39
+ @abstractmethod
40
+ def batch_generate(self, *args, **kwargs) -> any:
41
+ """
42
+ Generate images based on the input data provided to the model.
43
+ """
44
+ raise NotImplementedError("batch_generate() not implemented in subclass yet.")
45
+
46
+ @abstractmethod
47
+ async def abatch_generate(self, *args, **kwargs) -> any:
48
+ """
49
+ Generate images based on the input data provided to the model.
50
+ """
51
+ raise NotImplementedError("abatch_generate() not implemented in subclass yet.")
File without changes
@@ -0,0 +1,41 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Any, Union, Optional, List, Literal
3
+ from pydantic import BaseModel, ConfigDict, ValidationError, model_validator, Field
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri_core.llms.IPredict import IPredict
6
+
7
+
8
+ class LLMBase(IPredict, ComponentBase):
9
+ allowed_models: List[str] = []
10
+ resource: Optional[str] = Field(default=ResourceTypes.LLM.value, frozen=True)
11
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
12
+ type: Literal["LLMBase"] = "LLMBase"
13
+
14
+ @model_validator(mode="after")
15
+ @classmethod
16
+ def _validate_name_in_allowed_models(cls, values):
17
+ name = values.name
18
+ allowed_models = values.allowed_models
19
+ if name and name not in allowed_models:
20
+ raise ValueError(
21
+ f"Model name {name} is not allowed. Choose from {allowed_models}"
22
+ )
23
+ return values
24
+
25
+ def predict(self, *args, **kwargs):
26
+ raise NotImplementedError("predict() not implemented in subclass yet.")
27
+
28
+ async def apredict(self, *args, **kwargs):
29
+ raise NotImplementedError("apredict() not implemented in subclass yet.")
30
+
31
+ def stream(self, *args, **kwargs):
32
+ raise NotImplementedError("stream() not implemented in subclass yet.")
33
+
34
+ async def astream(self, *args, **kwargs):
35
+ raise NotImplementedError("astream() not implemented in subclass yet.")
36
+
37
+ def batch(self, *args, **kwargs):
38
+ raise NotImplementedError("batch() not implemented in subclass yet.")
39
+
40
+ async def abatch(self, *args, **kwargs):
41
+ raise NotImplementedError("abatch() not implemented in subclass yet.")
File without changes
@@ -0,0 +1,25 @@
1
+ from typing import List, Any, Literal
2
+ from pydantic import BaseModel
3
+ from swarmauri_core.measurements.IMeasurementAggregate import IMeasurementAggregate
4
+
5
+ class MeasurementAggregateMixin(IMeasurementAggregate, BaseModel):
6
+ """
7
+ An abstract base class that implements the IMeasurement interface, providing common
8
+ functionalities and properties for measurements within SwarmAURI.
9
+ """
10
+ measurements: List[Any] = []
11
+
12
+
13
+ def add_measurement(self, measurement) -> None:
14
+ """
15
+ Adds measurement to the internal store of measurements.
16
+ """
17
+ self.measurements.append(measurement)
18
+
19
+ def reset(self) -> None:
20
+ """
21
+ Resets the measurement's state/value, allowing for fresh calculations.
22
+ """
23
+ self.measurements.clear()
24
+ self.value = None
25
+
@@ -0,0 +1,23 @@
1
+ from typing import Any, Optional, Literal
2
+ from pydantic import BaseModel, ConfigDict, Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.measurements.IMeasurement import IMeasurement
5
+
6
+ class MeasurementBase(IMeasurement, ComponentBase):
7
+ """
8
+ A base implementation of the IMeasurement interface that provides the foundation
9
+ for specific measurement implementations.
10
+ """
11
+ unit: str
12
+ value: Any = None
13
+ resource: Optional[str] = Field(default=ResourceTypes.MEASUREMENT.value, frozen=True)
14
+ type: Literal['MeasurementBase'] = 'MeasurementBase'
15
+
16
+ def __call__(self, **kwargs) -> Any:
17
+ """
18
+ Retrieves the current value of the measurement.
19
+
20
+ Returns:
21
+ The current value of the measurement.
22
+ """
23
+ return self.value
@@ -0,0 +1,32 @@
1
+ from abc import abstractmethod
2
+ from typing import Any, Literal
3
+ from pydantic import BaseModel
4
+ from swarmauri_core.measurements.IMeasurementCalculate import IMeasurementCalculate
5
+
6
+ class MeasurementCalculateMixin(IMeasurementCalculate, BaseModel):
7
+ """
8
+ A base implementation of the IMeasurement interface that provides the foundation
9
+ for specific measurement implementations.
10
+ """
11
+
12
+ def update(self, value) -> None:
13
+ """
14
+ Update the measurement value based on new information.
15
+ This should be used internally by the `calculate` method or other logic.
16
+ """
17
+ self.value = value
18
+
19
+ @abstractmethod
20
+ def calculate(self, **kwargs) -> Any:
21
+ """
22
+ Calculate the measurement based on the provided data.
23
+ This method must be implemented by subclasses to define specific calculation logic.
24
+ """
25
+ raise NotImplementedError('calculate is not implemented yet.')
26
+
27
+ def __call__(self, **kwargs) -> Any:
28
+ """
29
+ Calculates the measurement, updates the value, and returns the current value.
30
+ """
31
+ self.calculate(**kwargs)
32
+ return self.value
@@ -0,0 +1,8 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Literal
3
+ from pydantic import BaseModel
4
+ from swarmauri_core.measurements.IThreshold import IThreshold
5
+
6
+ class MeasurementThresholdMixin(IThreshold, BaseModel):
7
+ k: int
8
+
File without changes
@@ -0,0 +1,12 @@
1
+ from typing import Optional, Literal, List, Dict, Union
2
+ from pydantic import ConfigDict, Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.messages.IMessage import IMessage
5
+
6
+
7
+ class MessageBase(IMessage, ComponentBase):
8
+ content: Union[str, List[Dict]]
9
+ role: str
10
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
11
+ resource: Optional[str] = Field(default=ResourceTypes.MESSAGE.value, frozen=True)
12
+ type: Literal["MessageBase"] = "MessageBase"
File without changes
@@ -0,0 +1,28 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Optional, Union, List, Any, Literal
3
+ from pydantic import Field
4
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
5
+ from swarmauri_core.documents.IDocument import IDocument
6
+ from swarmauri_core.parsers.IParser import IParser
7
+
8
+
9
+ class ParserBase(IParser, ComponentBase):
10
+ """
11
+ Interface for chunking text into smaller pieces.
12
+
13
+ This interface defines abstract methods for chunking texts. Implementing classes
14
+ should provide concrete implementations for these methods tailored to their specific
15
+ chunking algorithms.
16
+ """
17
+ resource: Optional[str] = Field(default=ResourceTypes.PARSER.value)
18
+ type: Literal['ParserBase'] = 'ParserBase'
19
+
20
+ @abstractmethod
21
+ def parse(self, data: Union[str, Any]) -> List[IDocument]:
22
+ """
23
+ Public method to parse input data (either a str or a Message) into a list of Document instances.
24
+
25
+ This method leverages the abstract _parse_data method which must be
26
+ implemented by subclasses to define specific parsing logic.
27
+ """
28
+ pass
File without changes
@@ -0,0 +1,105 @@
1
+ from typing import Any, Callable, List, Optional, Dict
2
+ from pydantic import BaseModel, ConfigDict, Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.pipelines.IPipeline import IPipeline, PipelineStatus
5
+ import uuid
6
+
7
+
8
+ class PipelineBase(IPipeline, ComponentBase):
9
+ """
10
+ Base class providing default behavior for task orchestration,
11
+ error handling, and result aggregation.
12
+ """
13
+
14
+ resource: Optional[str] = Field(default=ResourceTypes.PIPELINE.value, frozen=True)
15
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
16
+ type: str = "PipelineBase"
17
+
18
+ # Pydantic model fields
19
+ id: str = Field(default_factory=lambda: str(uuid.uuid4()))
20
+ tasks: List[Dict[str, Any]] = Field(default_factory=list)
21
+ parallel: bool = Field(default=False)
22
+
23
+ def __init__(
24
+ self, tasks: Optional[List[Dict[str, Any]]] = None, parallel: bool = False
25
+ ):
26
+ """
27
+ Initialize the pipeline.
28
+
29
+ :param tasks: Optional list of tasks to initialize pipeline with
30
+ :param parallel: Flag to indicate parallel or sequential execution
31
+ """
32
+ super().__init__()
33
+ self.tasks = tasks or []
34
+ self._results: List[Any] = []
35
+ self._status: PipelineStatus = PipelineStatus.PENDING
36
+ self.parallel = parallel
37
+
38
+ def add_task(self, task: Callable, *args: Any, **kwargs: Any) -> None:
39
+ """
40
+ Add a task to the pipeline.
41
+
42
+ :param task: Callable task to be executed
43
+ :param args: Positional arguments for the task
44
+ :param kwargs: Keyword arguments for the task
45
+ """
46
+ task_entry = {"callable": task, "args": args, "kwargs": kwargs}
47
+ self.tasks.append(task_entry)
48
+
49
+ def execute(self, *args: Any, **kwargs: Any) -> List[Any]:
50
+ """
51
+ Execute pipeline tasks.
52
+
53
+ :return: List of results from pipeline execution
54
+ """
55
+ try:
56
+ self._status = PipelineStatus.RUNNING
57
+ self._results = []
58
+
59
+ if self.parallel:
60
+ # Implement parallel execution logic
61
+ from concurrent.futures import ThreadPoolExecutor
62
+
63
+ with ThreadPoolExecutor() as executor:
64
+ futures = [
65
+ executor.submit(
66
+ task["callable"], *task["args"], **task["kwargs"]
67
+ )
68
+ for task in self.tasks
69
+ ]
70
+ self._results = [future.result() for future in futures]
71
+ else:
72
+ # Sequential execution
73
+ for task in self.tasks:
74
+ result = task["callable"](*task["args"], **task["kwargs"])
75
+ self._results.append(result)
76
+
77
+ self._status = PipelineStatus.COMPLETED
78
+ return self._results
79
+
80
+ except Exception as e:
81
+ self._status = PipelineStatus.FAILED
82
+ raise RuntimeError(f"Pipeline execution failed: {e}")
83
+
84
+ def get_status(self) -> PipelineStatus:
85
+ """
86
+ Get the current status of the pipeline.
87
+
88
+ :return: Current pipeline status
89
+ """
90
+ return self._status
91
+
92
+ def reset(self) -> None:
93
+ """
94
+ Reset the pipeline to its initial state.
95
+ """
96
+ self._results = []
97
+ self._status = PipelineStatus.PENDING
98
+
99
+ def get_results(self) -> List[Any]:
100
+ """
101
+ Get the results of the pipeline execution.
102
+
103
+ :return: List of results
104
+ """
105
+ return self._results
File without changes
@@ -0,0 +1,37 @@
1
+ from typing import Optional, Literal
2
+ from pydantic import ConfigDict, Field
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.prompts.IPrompt import IPrompt
5
+
6
+ class PromptBase(IPrompt, ComponentBase):
7
+ """
8
+ The ChatPrompt class represents a simple, chat-like prompt system where a
9
+ message can be set and retrieved as needed. It's particularly useful in
10
+ applications involving conversational agents, chatbots, or any system that
11
+ requires dynamic text-based interactions.
12
+ """
13
+ prompt: str = ""
14
+ resource: Optional[str] = Field(default=ResourceTypes.PROMPT.value, frozen=True)
15
+ type: Literal['PromptBase'] = 'PromptBase'
16
+
17
+ def __call__(self):
18
+ """
19
+ Enables the instance to be callable, allowing direct retrieval of the message.
20
+ This method facilitates intuitive access to the prompt's message, mimicking callable
21
+ behavior seen in functional programming paradigms.
22
+
23
+ Returns:
24
+ - str: The current message stored in the prompt.
25
+ """
26
+ return self.prompt
27
+
28
+ def set_prompt(self, prompt: str):
29
+ """
30
+ Updates the internal message of the chat prompt. This method provides a way to change
31
+ the content of the prompt dynamically, reflecting changes in the conversational context
32
+ or user inputs.
33
+
34
+ Parameters:
35
+ - message (str): The new message to set for the prompt.
36
+ """
37
+ self.prompt = prompt
@@ -0,0 +1,40 @@
1
+ from typing import Dict, List, Generator, Any, 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
+
8
+ class PromptGeneratorBase(IPrompt, ITemplate, ComponentBase):
9
+ """
10
+ A class that generates prompts based on a template and a list of variable sets.
11
+ It implements the IPrompt and ITemplate interfaces.
12
+ """
13
+
14
+ template: str = ""
15
+ variables: Union[List[Dict[str, Any]], Dict[str, Any]] = {}
16
+ resource: Optional[str] = Field(default=ResourceTypes.PROMPT.value, frozen=True)
17
+ type: Literal['PromptGeneratorBase'] = 'PromptGeneratorBase'
18
+
19
+ def set_template(self, template: str) -> None:
20
+ self.template = template
21
+
22
+ def set_variables(self, variables: List[Dict[str, Any]]) -> None:
23
+ self.variables = variables
24
+
25
+ def generate_prompt(self, variables: Dict[str, Any]) -> str:
26
+ """
27
+ Generates a prompt using the provided variables if any
28
+ else uses the next variables set in the list.
29
+ """
30
+ variables = variables if variables else self.variables.pop(0) if self.variables else {}
31
+ return self.template.format(**variables)
32
+
33
+ def __call__(self) -> Generator[str, None, None]:
34
+ """
35
+ Returns a generator that yields prompts constructed from the template and
36
+ each set of variables in the variables list.
37
+ """
38
+ for variables_set in self.variables:
39
+ yield self.generate_prompt(variables_set)
40
+ self.variables = []
@@ -0,0 +1,37 @@
1
+ from typing import List, Tuple, Optional, Any, Literal
2
+ from pydantic import Field, ConfigDict
3
+ from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
4
+ from swarmauri_core.prompts.IPromptMatrix import IPromptMatrix
5
+
6
+ class PromptMatrixBase(IPromptMatrix, ComponentBase):
7
+ matrix: List[List[str]] = []
8
+ resource: Optional[str] = Field(default=ResourceTypes.PROMPT.value)
9
+ type: Literal['PromptMatrixBase'] = 'PromptMatrixBase'
10
+
11
+ @property
12
+ def shape(self) -> Tuple[int, int]:
13
+ """Get the shape (number of agents, sequence length) of the prompt matrix."""
14
+ if self.matrix:
15
+ return len(self.matrix), len(self.matrix[0])
16
+ return 0, 0
17
+
18
+ def add_prompt_sequence(self, sequence: List[Optional[str]]) -> None:
19
+ if not self.matrix or (self.matrix and len(sequence) == len(self.matrix[0])):
20
+ self.matrix.append(sequence)
21
+ else:
22
+ raise ValueError("Sequence length does not match the prompt matrix dimensions.")
23
+
24
+ def remove_prompt_sequence(self, index: int) -> None:
25
+ if 0 <= index < len(self.matrix):
26
+ self.matrix.pop(index)
27
+ else:
28
+ raise IndexError("Index out of range.")
29
+
30
+ def get_prompt_sequence(self, index: int) -> List[Optional[str]]:
31
+ if 0 <= index < len(self._matrix):
32
+ return self.matrix[index]
33
+ else:
34
+ raise IndexError("Index out of range.")
35
+
36
+ def show(self) -> List[List[Optional[str]]]:
37
+ return self.matrix