swarmauri 0.1.6__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.
- swarmauri/__init__.py +1 -0
- swarmauri/community/__init__.py +0 -0
- swarmauri/community/document_stores/__init__.py +0 -0
- swarmauri/community/document_stores/base/__init__.py +0 -0
- swarmauri/community/document_stores/concrete/RedisDocumentStore.py +73 -0
- swarmauri/community/document_stores/concrete/__init__.py +0 -0
- swarmauri/community/retrievers/__init__.py +2 -0
- swarmauri/community/retrievers/base/__init__.py +2 -0
- swarmauri/community/retrievers/concrete/RedisDocumentRetriever.py +53 -0
- swarmauri/community/retrievers/concrete/__init__.py +2 -0
- swarmauri/community/tools/__init__.py +0 -0
- swarmauri/community/tools/base/__init__.py +0 -0
- swarmauri/community/tools/concrete/DownloadPdfTool.py +64 -0
- swarmauri/community/tools/concrete/EntityRecognitionTool.py +31 -0
- swarmauri/community/tools/concrete/GmailReadTool.py +117 -0
- swarmauri/community/tools/concrete/GmailSendTool.py +105 -0
- swarmauri/community/tools/concrete/PaCMAP.py +66 -0
- swarmauri/community/tools/concrete/SentimentAnalysisTool.py +26 -0
- swarmauri/community/tools/concrete/WebScrapingTool.py +51 -0
- swarmauri/community/tools/concrete/__init__.py +0 -0
- swarmauri/core/__init__.py +0 -0
- swarmauri/core/agent_apis/IAgentCommands.py +83 -0
- swarmauri/core/agent_apis/IAgentRouterCRUD.py +56 -0
- swarmauri/core/agent_apis/__init__.py +0 -0
- swarmauri/core/agents/ISwarmAgent.py +55 -0
- swarmauri/core/agents/__init__.py +0 -0
- swarmauri/core/chains/ICallableChain.py +15 -0
- swarmauri/core/chains/__init__.py +1 -0
- swarmauri/core/chunkers/IChunker.py +32 -0
- swarmauri/core/chunkers/__init__.py +7 -0
- swarmauri/core/conversations/IConversation.py +44 -0
- swarmauri/core/conversations/IMaxSize.py +17 -0
- swarmauri/core/conversations/ISystemContext.py +24 -0
- swarmauri/core/conversations/__init__.py +0 -0
- swarmauri/core/document_stores/IDocumentStore.py +75 -0
- swarmauri/core/document_stores/__init__.py +0 -0
- swarmauri/core/documents/IDocument.py +72 -0
- swarmauri/core/documents/IEmbed.py +24 -0
- swarmauri/core/documents/__init__.py +0 -0
- swarmauri/core/messages/IMessage.py +26 -0
- swarmauri/core/messages/__init__.py +1 -0
- swarmauri/core/models/IFit.py +13 -0
- swarmauri/core/models/IModel.py +22 -0
- swarmauri/core/models/IPredict.py +13 -0
- swarmauri/core/models/__init__.py +0 -0
- swarmauri/core/parsers/IParser.py +20 -0
- swarmauri/core/parsers/__init__.py +0 -0
- swarmauri/core/prompts/IPrompt.py +21 -0
- swarmauri/core/prompts/__init__.py +0 -0
- swarmauri/core/retrievers/IRetriever.py +25 -0
- swarmauri/core/retrievers/__init__.py +0 -0
- swarmauri/core/swarm_apis/IAgentRegistration.py +72 -0
- swarmauri/core/swarm_apis/ISwarmAPI.py +40 -0
- swarmauri/core/swarm_apis/__init__.py +0 -0
- swarmauri/core/swarms/ISwarm.py +0 -0
- swarmauri/core/swarms/__init__.py +0 -0
- swarmauri/core/toolkits/IToolkit.py +52 -0
- swarmauri/core/toolkits/__init__.py +0 -0
- swarmauri/core/tools/IParameter.py +87 -0
- swarmauri/core/tools/ITool.py +35 -0
- swarmauri/core/tools/__init__.py +0 -0
- swarmauri/core/tracing/IChainTracer.py +25 -0
- swarmauri/core/tracing/ITraceContext.py +29 -0
- swarmauri/core/tracing/ITracer.py +45 -0
- swarmauri/core/tracing/__init__.py +0 -0
- swarmauri/core/utils/ITransactional.py +24 -0
- swarmauri/core/utils/__init__.py +0 -0
- swarmauri/core/vector_stores/IAngleBetweenVectors.py +23 -0
- swarmauri/core/vector_stores/IDecompose.py +24 -0
- swarmauri/core/vector_stores/IDistanceSimilarity.py +49 -0
- swarmauri/core/vector_stores/IDivergence.py +21 -0
- swarmauri/core/vector_stores/IGradient.py +22 -0
- swarmauri/core/vector_stores/IOrthogonalProject.py +21 -0
- swarmauri/core/vector_stores/IProject.py +22 -0
- swarmauri/core/vector_stores/IReflect.py +21 -0
- swarmauri/core/vector_stores/ISimilarity.py +26 -0
- swarmauri/core/vector_stores/ISimiliarityQuery.py +19 -0
- swarmauri/core/vector_stores/IVectorArithmetic.py +31 -0
- swarmauri/core/vector_stores/IVectorBasisCheck.py +20 -0
- swarmauri/core/vector_stores/IVectorLinearCombination.py +21 -0
- swarmauri/core/vector_stores/IVectorNorm.py +49 -0
- swarmauri/core/vector_stores/IVectorProduct.py +66 -0
- swarmauri/core/vector_stores/IVectorRotate.py +24 -0
- swarmauri/core/vector_stores/IVectorSpan.py +21 -0
- swarmauri/core/vector_stores/IVectorStore.py +56 -0
- swarmauri/core/vector_stores/__init__.py +0 -0
- swarmauri/core/vectorizers/IVectorize.py +21 -0
- swarmauri/core/vectorizers/__init__.py +1 -0
- swarmauri/core/vectors/IVector.py +18 -0
- swarmauri/core/vectors/IVectorMeta.py +28 -0
- swarmauri/core/vectors/IVectorTransform.py +49 -0
- swarmauri/core/vectors/__init__.py +0 -0
- swarmauri/experimental/__init__.py +2 -0
- swarmauri/experimental/conversations/ConsensusBuildingConversation.py +90 -0
- swarmauri/experimental/conversations/SemanticConversation.py +55 -0
- swarmauri/experimental/conversations/__init__.py +0 -0
- swarmauri/experimental/models/HierarchicalAttentionModel.py +66 -0
- swarmauri/experimental/models/SageMaker.py +42 -0
- swarmauri/experimental/models/__init__.py +0 -0
- swarmauri/experimental/parsers/PDFToTextParser.py +42 -0
- swarmauri/experimental/parsers/__init__.py +2 -0
- swarmauri/experimental/tools/CypherQueryTool.py +43 -0
- swarmauri/experimental/tools/FileDownloaderTool.py +36 -0
- swarmauri/experimental/tools/LinkedInArticleTool.py +79 -0
- swarmauri/experimental/tools/OutlookSendMailTool.py +82 -0
- swarmauri/experimental/tools/SQLite3QueryTool.py +42 -0
- swarmauri/experimental/tools/TwitterPostTool.py +41 -0
- swarmauri/experimental/tools/__init__.py +2 -0
- swarmauri/experimental/utils/ISerializable.py +21 -0
- swarmauri/experimental/utils/__init__.py +2 -0
- swarmauri/experimental/utils/get_last_frame.py +20 -0
- swarmauri/experimental/utils/save_schema.py +71 -0
- swarmauri/experimental/vector_stores/CanberraDistance.py +67 -0
- swarmauri/experimental/vector_stores/ChebyshevDistance.py +47 -0
- swarmauri/experimental/vector_stores/HaversineDistance.py +50 -0
- swarmauri/experimental/vector_stores/ManhattanDistance.py +49 -0
- swarmauri/experimental/vector_stores/MinkowskiDistance.py +68 -0
- swarmauri/experimental/vector_stores/SSASimilarity.py +51 -0
- swarmauri/experimental/vector_stores/SSIVSimilarity.py +51 -0
- swarmauri/experimental/vector_stores/ScannVectorStore.py +149 -0
- swarmauri/experimental/vector_stores/SorensenDiceDistance.py +51 -0
- swarmauri/experimental/vector_stores/SquaredEuclideanDistance.py +46 -0
- swarmauri/experimental/vector_stores/__init__.py +2 -0
- swarmauri/standard/__init__.py +2 -0
- swarmauri/standard/agents/__init__.py +2 -0
- swarmauri/standard/agents/base/SwarmAgentBase.py +95 -0
- swarmauri/standard/agents/base/__init__.py +2 -0
- swarmauri/standard/agents/concrete/ChatSwarmAgent.py +48 -0
- swarmauri/standard/agents/concrete/MultiPartyChatSwarmAgent.py +54 -0
- swarmauri/standard/agents/concrete/MultiPartyToolAgent.py +97 -0
- swarmauri/standard/agents/concrete/SimpleSwarmAgent.py +34 -0
- swarmauri/standard/agents/concrete/SingleCommandAgent.py +27 -0
- swarmauri/standard/agents/concrete/ToolAgent.py +91 -0
- swarmauri/standard/agents/concrete/__init__.py +2 -0
- swarmauri/standard/apis/__init__.py +0 -0
- swarmauri/standard/apis/base/__init__.py +0 -0
- swarmauri/standard/apis/concrete/__init__.py +0 -0
- swarmauri/standard/chains/__init__.py +1 -0
- swarmauri/standard/chains/base/__init__.py +1 -0
- swarmauri/standard/chains/concrete/CallableChain.py +21 -0
- swarmauri/standard/chains/concrete/__init__.py +1 -0
- swarmauri/standard/chunkers/__init__.py +0 -0
- swarmauri/standard/chunkers/base/__init__.py +0 -0
- swarmauri/standard/chunkers/concrete/DelimiterBasedChunker.py +40 -0
- swarmauri/standard/chunkers/concrete/FixedLengthChunker.py +39 -0
- swarmauri/standard/chunkers/concrete/SimpleSentenceChunker.py +29 -0
- swarmauri/standard/chunkers/concrete/SlidingWindowChunker.py +39 -0
- swarmauri/standard/chunkers/concrete/__init__.py +0 -0
- swarmauri/standard/conversations/__init__.py +0 -0
- swarmauri/standard/conversations/base/ConversationBase.py +37 -0
- swarmauri/standard/conversations/base/SystemContextBase.py +32 -0
- swarmauri/standard/conversations/base/__init__.py +0 -0
- swarmauri/standard/conversations/concrete/LimitedSizeConversation.py +39 -0
- swarmauri/standard/conversations/concrete/LimitedSystemContextConversation.py +87 -0
- swarmauri/standard/conversations/concrete/SharedConversation.py +115 -0
- swarmauri/standard/conversations/concrete/SimpleConversation.py +11 -0
- swarmauri/standard/conversations/concrete/__init__.py +0 -0
- swarmauri/standard/document_stores/__init__.py +0 -0
- swarmauri/standard/document_stores/base/DocumentStoreBase.py +76 -0
- swarmauri/standard/document_stores/base/__init__.py +0 -0
- swarmauri/standard/document_stores/concrete/Doc2VecDocumentStore.py +57 -0
- swarmauri/standard/document_stores/concrete/TFIDFDocumentStore.py +56 -0
- swarmauri/standard/document_stores/concrete/Word2VecDocumentStore.py +78 -0
- swarmauri/standard/document_stores/concrete/__init__.py +0 -0
- swarmauri/standard/documents/__init__.py +0 -0
- swarmauri/standard/documents/base/DocumentBase.py +64 -0
- swarmauri/standard/documents/base/EmbeddedBase.py +22 -0
- swarmauri/standard/documents/base/__init__.py +0 -0
- swarmauri/standard/documents/concrete/Document.py +6 -0
- swarmauri/standard/documents/concrete/EmbeddedDocument.py +9 -0
- swarmauri/standard/documents/concrete/__init__.py +0 -0
- swarmauri/standard/messages/__init__.py +0 -0
- swarmauri/standard/messages/base/MessageBase.py +55 -0
- swarmauri/standard/messages/base/__init__.py +0 -0
- swarmauri/standard/messages/concrete/AgentMessage.py +9 -0
- swarmauri/standard/messages/concrete/FunctionMessage.py +25 -0
- swarmauri/standard/messages/concrete/HumanMessage.py +21 -0
- swarmauri/standard/messages/concrete/SystemMessage.py +16 -0
- swarmauri/standard/messages/concrete/__init__.py +4 -0
- swarmauri/standard/models/__init__.py +0 -0
- swarmauri/standard/models/base/ModelBase.py +28 -0
- swarmauri/standard/models/base/__init__.py +0 -0
- swarmauri/standard/models/concrete/AzureGPT.py +69 -0
- swarmauri/standard/models/concrete/OpenAIImageGenerator.py +43 -0
- swarmauri/standard/models/concrete/OpenAIModel.py +63 -0
- swarmauri/standard/models/concrete/OpenAIToolModel.py +21 -0
- swarmauri/standard/models/concrete/__init__.py +0 -0
- swarmauri/standard/parsers/__init__.py +0 -0
- swarmauri/standard/parsers/base/__init__.py +0 -0
- swarmauri/standard/parsers/concrete/BERTEmbeddingParser.py +58 -0
- swarmauri/standard/parsers/concrete/CSVParser.py +45 -0
- swarmauri/standard/parsers/concrete/EntityRecognitionParser.py +41 -0
- swarmauri/standard/parsers/concrete/HtmlTagStripParser.py +37 -0
- swarmauri/standard/parsers/concrete/KeywordExtractorParser.py +44 -0
- swarmauri/standard/parsers/concrete/MarkdownParser.py +40 -0
- swarmauri/standard/parsers/concrete/OpenAPISpecParser.py +45 -0
- swarmauri/standard/parsers/concrete/PhoneNumberExtractorParser.py +40 -0
- swarmauri/standard/parsers/concrete/PythonParser.py +53 -0
- swarmauri/standard/parsers/concrete/RegExParser.py +43 -0
- swarmauri/standard/parsers/concrete/TextBlobNounParser.py +41 -0
- swarmauri/standard/parsers/concrete/TextBlobSentenceParser.py +39 -0
- swarmauri/standard/parsers/concrete/TfidfParser.py +17 -0
- swarmauri/standard/parsers/concrete/URLExtractorParser.py +45 -0
- swarmauri/standard/parsers/concrete/XMLParser.py +47 -0
- swarmauri/standard/parsers/concrete/__init__.py +0 -0
- swarmauri/standard/prompts/__init__.py +0 -0
- swarmauri/standard/prompts/base/__init__.py +0 -0
- swarmauri/standard/prompts/concrete/Prompt.py +40 -0
- swarmauri/standard/prompts/concrete/PromptTemplate.py +58 -0
- swarmauri/standard/prompts/concrete/__init__.py +0 -0
- swarmauri/standard/retrievers/__init__.py +2 -0
- swarmauri/standard/retrievers/base/DocumentRetrieverBase.py +39 -0
- swarmauri/standard/retrievers/base/__init__.py +2 -0
- swarmauri/standard/retrievers/concrete/__init__.py +2 -0
- swarmauri/standard/states/__init__.py +0 -0
- swarmauri/standard/states/base/__init__.py +0 -0
- swarmauri/standard/states/concrete/__init__.py +0 -0
- swarmauri/standard/swarms/__init__.py +0 -0
- swarmauri/standard/swarms/base/__init__.py +0 -0
- swarmauri/standard/swarms/concrete/__init__.py +0 -0
- swarmauri/standard/toolkits/__init__.py +0 -0
- swarmauri/standard/toolkits/base/ToolkitBase.py +76 -0
- swarmauri/standard/toolkits/base/__init__.py +0 -0
- swarmauri/standard/toolkits/concrete/Toolkit.py +17 -0
- swarmauri/standard/toolkits/concrete/__init__.py +0 -0
- swarmauri/standard/tools/__init__.py +0 -0
- swarmauri/standard/tools/base/ToolBase.py +80 -0
- swarmauri/standard/tools/base/__init__.py +0 -0
- swarmauri/standard/tools/concrete/AdditionTool.py +36 -0
- swarmauri/standard/tools/concrete/Parameter.py +102 -0
- swarmauri/standard/tools/concrete/TestTool.py +26 -0
- swarmauri/standard/tools/concrete/WeatherTool.py +29 -0
- swarmauri/standard/tools/concrete/__init__.py +0 -0
- swarmauri/standard/tracing/__init__.py +1 -0
- swarmauri/standard/tracing/base/__init__.py +1 -0
- swarmauri/standard/tracing/concrete/CallableTracer.py +32 -0
- swarmauri/standard/tracing/concrete/ChainTracer.py +51 -0
- swarmauri/standard/tracing/concrete/SimpleTraceContext.py +21 -0
- swarmauri/standard/tracing/concrete/SimpleTracer.py +40 -0
- swarmauri/standard/tracing/concrete/TracedVariable.py +28 -0
- swarmauri/standard/tracing/concrete/VariableTracer.py +23 -0
- swarmauri/standard/tracing/concrete/__init__.py +1 -0
- swarmauri/standard/utils/__init__.py +0 -0
- swarmauri/standard/vector_stores/__init__.py +2 -0
- swarmauri/standard/vector_stores/base/__init__.py +2 -0
- swarmauri/standard/vector_stores/concrete/ChiSquaredDistance.py +36 -0
- swarmauri/standard/vector_stores/concrete/CosineDistance.py +63 -0
- swarmauri/standard/vector_stores/concrete/EuclideanDistance.py +50 -0
- swarmauri/standard/vector_stores/concrete/FaissVectorStore.py +78 -0
- swarmauri/standard/vector_stores/concrete/JaccardIndexDistance.py +71 -0
- swarmauri/standard/vector_stores/concrete/LevenshteinDistance.py +73 -0
- swarmauri/standard/vector_stores/concrete/VectorProduct.py +33 -0
- swarmauri/standard/vector_stores/concrete/WeaviateVectorStore.py +36 -0
- swarmauri/standard/vector_stores/concrete/__init__.py +2 -0
- swarmauri/standard/vectorizers/__init__.py +1 -0
- swarmauri/standard/vectorizers/base/__init__.py +1 -0
- swarmauri/standard/vectorizers/concrete/BERTEmbeddingVectorizer.py +59 -0
- swarmauri/standard/vectorizers/concrete/TFIDFVectorizer.py +56 -0
- swarmauri/standard/vectorizers/concrete/__init__.py +1 -0
- swarmauri/standard/vectors/__init__.py +2 -0
- swarmauri/standard/vectors/base/VectorBase.py +30 -0
- swarmauri/standard/vectors/base/__init__.py +2 -0
- swarmauri/standard/vectors/concrete/SimpleVector.py +7 -0
- swarmauri/standard/vectors/concrete/__init__.py +2 -0
- swarmauri-0.1.6.dist-info/METADATA +88 -0
- swarmauri-0.1.6.dist-info/RECORD +268 -0
- swarmauri-0.1.6.dist-info/WHEEL +5 -0
- swarmauri-0.1.6.dist-info/top_level.txt +1 -0
swarmauri/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.6"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from typing import List, Optional
|
|
2
|
+
from ....standard.document_stores.base.DocumentStoreBase import DocumentStoreBase
|
|
3
|
+
from ....core.documents.IDocument import IDocument
|
|
4
|
+
import redis
|
|
5
|
+
import json
|
|
6
|
+
from redis.commands.search.field import TextField, NumericField, TagField
|
|
7
|
+
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RedisDocumentStore(DocumentStoreBase):
|
|
11
|
+
def __init__(self, host, password, port, db):
|
|
12
|
+
"""Store connection details without initializing the Redis client."""
|
|
13
|
+
self._host = host
|
|
14
|
+
self._password = password
|
|
15
|
+
self._port = port
|
|
16
|
+
self._db = db
|
|
17
|
+
self._redis_client = None # Delayed initialization
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def redis_client(self):
|
|
21
|
+
"""Lazily initialize and return the Redis client using a factory method."""
|
|
22
|
+
if self._redis_client is None:
|
|
23
|
+
print('here')
|
|
24
|
+
self._redis_client = redis.Redis(host=self._host,
|
|
25
|
+
password=self._password,
|
|
26
|
+
port=self._port,
|
|
27
|
+
db=self._db)
|
|
28
|
+
print('there')
|
|
29
|
+
return self._redis_client
|
|
30
|
+
|
|
31
|
+
def add_document(self, document: IDocument) -> None:
|
|
32
|
+
|
|
33
|
+
data = document.as_dict()
|
|
34
|
+
doc_id = data['id']
|
|
35
|
+
del data['id']
|
|
36
|
+
self.redis_client.json().set(doc_id, '$', json.dumps(data))
|
|
37
|
+
|
|
38
|
+
def add_documents(self, documents: List[IDocument]) -> None:
|
|
39
|
+
with self.redis_client.pipeline() as pipe:
|
|
40
|
+
for document in documents:
|
|
41
|
+
pipe.set(document.doc_id, document)
|
|
42
|
+
pipe.execute()
|
|
43
|
+
|
|
44
|
+
def get_document(self, doc_id: str) -> Optional[IDocument]:
|
|
45
|
+
result = self.redis_client.json().get(doc_id)
|
|
46
|
+
if result:
|
|
47
|
+
return json.loads(result)
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
def get_all_documents(self) -> List[IDocument]:
|
|
51
|
+
keys = self.redis_client.keys('*')
|
|
52
|
+
documents = []
|
|
53
|
+
for key in keys:
|
|
54
|
+
document_data = self.redis_client.get(key)
|
|
55
|
+
if document_data:
|
|
56
|
+
documents.append(json.loads(document_data))
|
|
57
|
+
return documents
|
|
58
|
+
|
|
59
|
+
def update_document(self, doc_id: str, updated_document: IDocument) -> None:
|
|
60
|
+
self.add_document(updated_document)
|
|
61
|
+
|
|
62
|
+
def delete_document(self, doc_id: str) -> None:
|
|
63
|
+
self.redis_client.delete(doc_id)
|
|
64
|
+
|
|
65
|
+
def __getstate__(self):
|
|
66
|
+
"""Return the object state for serialization, excluding the Redis client."""
|
|
67
|
+
state = self.__dict__.copy()
|
|
68
|
+
state['_redis_client'] = None # Exclude Redis client from serialization
|
|
69
|
+
return state
|
|
70
|
+
|
|
71
|
+
def __setstate__(self, state):
|
|
72
|
+
"""Restore the object state after serialization, reinitializing the Redis client."""
|
|
73
|
+
self.__dict__.update(state)
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
from redisearch import Client, Query
|
|
3
|
+
from ....core.documents.IDocument import IDocument
|
|
4
|
+
from ....standard.document_stores.concrete.ConcreteDocument import ConcreteDocument
|
|
5
|
+
from ....standard.retrievers.base.DocumentRetrieverBase import DocumentRetrieverBase
|
|
6
|
+
|
|
7
|
+
class RedisDocumentRetriever(DocumentRetrieverBase):
|
|
8
|
+
"""
|
|
9
|
+
A document retriever that fetches documents from a Redis store.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(self, redis_idx_name, redis_host, redis_port):
|
|
13
|
+
"""
|
|
14
|
+
Initializes a new instance of RedisDocumentRetriever.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
redis_client (Redis): An instance of the Redis client.
|
|
18
|
+
"""
|
|
19
|
+
self._redis_client = None
|
|
20
|
+
self._redis_idx_name = redis_idx_name
|
|
21
|
+
self._redis_host = redis_host
|
|
22
|
+
self._redis_port = redis_port
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def redis_client(self):
|
|
26
|
+
"""Lazily initialize and return the Redis client using a factory method."""
|
|
27
|
+
if self._redis_client is None:
|
|
28
|
+
self._redis_client = Client(self.redis_idx_name, host=self.redis_host, port=self.redis_port)
|
|
29
|
+
return self._redis_client
|
|
30
|
+
|
|
31
|
+
def retrieve(self, query: str, top_k: int = 5) -> List[IDocument]:
|
|
32
|
+
"""
|
|
33
|
+
Retrieve the most relevant documents based on the given query.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
query (str): The query string used for document retrieval.
|
|
37
|
+
top_k (int, optional): The number of top relevant documents to retrieve. Defaults to 5.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
List[IDocument]: A list of the top_k most relevant documents.
|
|
41
|
+
"""
|
|
42
|
+
query_result = self.redis_client.search(Query(query).paging(0, top_k))
|
|
43
|
+
|
|
44
|
+
documents = [
|
|
45
|
+
ConcreteDocument(
|
|
46
|
+
doc_id=doc.id,
|
|
47
|
+
content=doc.text, # Note: Adjust 'text' based on actual Redis document schema
|
|
48
|
+
metadata=doc.__dict__ # Including full document fields and values in metadata
|
|
49
|
+
)
|
|
50
|
+
for doc in query_result.docs
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
return documents
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Dict
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from ...standard.tools.base.ToolBase import ToolBase
|
|
5
|
+
from ...standard.tools.concrete.Parameter import Parameter
|
|
6
|
+
|
|
7
|
+
class DownloadPDFTool(ToolBase):
|
|
8
|
+
def __init__(self):
|
|
9
|
+
parameters = [
|
|
10
|
+
Parameter(
|
|
11
|
+
name="url",
|
|
12
|
+
type="string",
|
|
13
|
+
description="The URL of the PDF file to download",
|
|
14
|
+
required=True
|
|
15
|
+
),
|
|
16
|
+
Parameter(
|
|
17
|
+
name="destination",
|
|
18
|
+
type="string",
|
|
19
|
+
description="The path where the PDF file will be saved",
|
|
20
|
+
required=True
|
|
21
|
+
)
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
super().__init__(name="DownloadPDFTool",
|
|
25
|
+
description="Downloads a PDF from a specified URL and saves it to a specified path.",
|
|
26
|
+
parameters=parameters)
|
|
27
|
+
|
|
28
|
+
def __call__(self, url: str, destination: str) -> Dict[str, str]:
|
|
29
|
+
"""
|
|
30
|
+
Download the PDF from the specified URL and saves it to the given destination path.
|
|
31
|
+
|
|
32
|
+
Parameters:
|
|
33
|
+
- url (str): The URL from where to download the PDF.
|
|
34
|
+
- destination (str): The local file path where the PDF should be saved.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
- Dict[str, str]: A dictionary containing the result message and the destination path.
|
|
38
|
+
"""
|
|
39
|
+
try:
|
|
40
|
+
# Send a GET request to the specified URL
|
|
41
|
+
response = requests.get(url, stream=True)
|
|
42
|
+
|
|
43
|
+
# Raise an HTTPError if the status code is not 200 (OK)
|
|
44
|
+
response.raise_for_status()
|
|
45
|
+
|
|
46
|
+
# Ensure destination directory exists
|
|
47
|
+
Path(destination).parent.mkdir(parents=True, exist_ok=True)
|
|
48
|
+
|
|
49
|
+
# Open a file at the specified destination path and write the content of the response to it
|
|
50
|
+
with open(Path(destination), 'wb') as file:
|
|
51
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
52
|
+
file.write(chunk)
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
"message": "PDF downloaded successfully.",
|
|
56
|
+
"destination": destination
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
except requests.exceptions.RequestException as e:
|
|
60
|
+
# Handle requests-related errors
|
|
61
|
+
return {"error": f"Failed to download PDF: {e}"}
|
|
62
|
+
except IOError as e:
|
|
63
|
+
# Handle file I/O errors
|
|
64
|
+
return {"error": f"Failed to save PDF: {e}"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from transformers import pipeline, logging as hf_logging
|
|
3
|
+
from ....standard.tools.base.ToolBase import ToolBase
|
|
4
|
+
from ....standard.tools.concrete.Parameter import Parameter
|
|
5
|
+
|
|
6
|
+
hf_logging.set_verbosity_error()
|
|
7
|
+
|
|
8
|
+
class EntityRecognitionTool(ToolBase):
|
|
9
|
+
def __init__(self):
|
|
10
|
+
parameters = [
|
|
11
|
+
Parameter("text","string","The text for entity recognition",True)
|
|
12
|
+
]
|
|
13
|
+
super().__init__(name="EntityRecognitionTool",
|
|
14
|
+
description="Extracts named entities from text",
|
|
15
|
+
parameters=parameters)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def __call__(self, text: str) -> dict:
|
|
19
|
+
try:
|
|
20
|
+
self.nlp = pipeline("ner")
|
|
21
|
+
entities = self.nlp(text)
|
|
22
|
+
organized_entities = {}
|
|
23
|
+
for entity in entities:
|
|
24
|
+
if entity['entity'] not in organized_entities:
|
|
25
|
+
organized_entities[entity['entity']] = []
|
|
26
|
+
organized_entities[entity['entity']].append(entity['word'])
|
|
27
|
+
return json.dumps(organized_entities)
|
|
28
|
+
except Exception as e:
|
|
29
|
+
raise e
|
|
30
|
+
finally:
|
|
31
|
+
del self.nlp
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import base64
|
|
3
|
+
import json
|
|
4
|
+
from googleapiclient import discovery
|
|
5
|
+
from google.oauth2 import service_account
|
|
6
|
+
from googleapiclient.discovery import build
|
|
7
|
+
from ....standard.tools.base.ToolBase import ToolBase
|
|
8
|
+
from ....standard.tools.concrete.Parameter import Parameter
|
|
9
|
+
|
|
10
|
+
class GmailReadTool(ToolBase):
|
|
11
|
+
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
|
|
12
|
+
|
|
13
|
+
def __init__(self, credentials_path: str, sender_email: str):
|
|
14
|
+
"""
|
|
15
|
+
Initializes the GmailReadTool with a path to the credentials JSON file.
|
|
16
|
+
|
|
17
|
+
Parameters:
|
|
18
|
+
credentials_path (str): The path to the Gmail service JSON file.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
parameters = [
|
|
22
|
+
Parameter(
|
|
23
|
+
name="query",
|
|
24
|
+
type="string",
|
|
25
|
+
description='''The query to filter emails. For example, "is:unread" or "from:example@gmail.com" or "from:sender@company.com"''',
|
|
26
|
+
required=True
|
|
27
|
+
),
|
|
28
|
+
Parameter(
|
|
29
|
+
name="max_results",
|
|
30
|
+
type="integer",
|
|
31
|
+
description='''The number of emails to return. Defaults to 10.'''
|
|
32
|
+
)
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
super().__init__(name="GmailReadTool",
|
|
37
|
+
description="Read emails from a Gmail account.",
|
|
38
|
+
parameters = parameters)
|
|
39
|
+
self.credentials_path = credentials_path
|
|
40
|
+
self.sender_email = sender_email
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def authenticate(self):
|
|
44
|
+
"""
|
|
45
|
+
Authenticates the user and creates a Gmail API service.
|
|
46
|
+
"""
|
|
47
|
+
credentials = service_account.Credentials.from_service_account_file(
|
|
48
|
+
self.credentials_path, scopes=self.SCOPES)
|
|
49
|
+
|
|
50
|
+
delegated_credentials = credentials.with_subject(self.sender_email)
|
|
51
|
+
self.service = discovery.build('gmail', 'v1', credentials=delegated_credentials)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def __call__(self, query='', max_results=10):
|
|
56
|
+
"""
|
|
57
|
+
Fetches emails from the authenticated Gmail account based on the given query.
|
|
58
|
+
|
|
59
|
+
Parameters:
|
|
60
|
+
query (str): The query to filter emails. For example, "is:unread".
|
|
61
|
+
max_results (int): The maximum number of email messages to fetch.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
list: A list of email messages.
|
|
65
|
+
"""
|
|
66
|
+
self.authenticate()
|
|
67
|
+
try:
|
|
68
|
+
# Call the Gmail API
|
|
69
|
+
|
|
70
|
+
gmail_messages = self.service.users().messages()
|
|
71
|
+
results = gmail_messages.list(userId='me', q=query, maxResults=max_results).execute()
|
|
72
|
+
messages = results.get('messages', [])
|
|
73
|
+
message_data = ""
|
|
74
|
+
for message in messages:
|
|
75
|
+
|
|
76
|
+
msg = gmail_messages.get(userId='me', id=message['threadId'], format="full").execute()
|
|
77
|
+
headers = msg['payload']['headers']
|
|
78
|
+
|
|
79
|
+
sender = next(header['value'] for header in headers if header['name'] == 'From')
|
|
80
|
+
subject = next(header['value'] for header in headers if header['name'] == 'Subject')
|
|
81
|
+
reply_to = next((header['value'] for header in headers if header['name'] == 'Reply-To'), subject)
|
|
82
|
+
date_time = next(header['value'] for header in headers if header['name'] == 'Date')
|
|
83
|
+
|
|
84
|
+
#part = msg['payload']['parts'][0]
|
|
85
|
+
#data = part['body']['data']
|
|
86
|
+
#decoded_data = base64.urlsafe_b64decode(data.encode('ASCII'))
|
|
87
|
+
|
|
88
|
+
formatted_msg = f"\nsender:{sender} reply-to:{reply_to} subject: {subject} date_time:{date_time}"
|
|
89
|
+
|
|
90
|
+
message_data += formatted_msg
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
return message_data
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
except Exception as e:
|
|
98
|
+
print(f"An error occurred: {e}")
|
|
99
|
+
return []
|
|
100
|
+
|
|
101
|
+
finally:
|
|
102
|
+
del self.service
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import json
|
|
3
|
+
from email.mime.multipart import MIMEMultipart
|
|
4
|
+
from email.mime.text import MIMEText
|
|
5
|
+
from googleapiclient import discovery
|
|
6
|
+
from google.oauth2 import service_account
|
|
7
|
+
from googleapiclient.discovery import build
|
|
8
|
+
from swarmauri.standard.tools.base.ToolBase import ToolBase
|
|
9
|
+
from swarmauri.standard.tools.concrete.Parameter import Parameter
|
|
10
|
+
|
|
11
|
+
class GmailSendTool(ToolBase):
|
|
12
|
+
SCOPES = ['https://www.googleapis.com/auth/gmail.send']
|
|
13
|
+
|
|
14
|
+
def __init__(self, credentials_path: str, sender_email: str):
|
|
15
|
+
"""
|
|
16
|
+
Initializes the GmailSendTool with a path to the credentials JSON file and the sender email.
|
|
17
|
+
|
|
18
|
+
Parameters:
|
|
19
|
+
credentials_path (str): The path to the Gmail service JSON file.
|
|
20
|
+
sender_email (str): The email address being used to send emails.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
parameters = [
|
|
24
|
+
Parameter(
|
|
25
|
+
name="recipients",
|
|
26
|
+
type="string",
|
|
27
|
+
description="The email addresses of the recipients, separated by commas",
|
|
28
|
+
required=True
|
|
29
|
+
),
|
|
30
|
+
Parameter(
|
|
31
|
+
name="subject",
|
|
32
|
+
type="string",
|
|
33
|
+
description="The subject of the email",
|
|
34
|
+
required=True
|
|
35
|
+
),
|
|
36
|
+
Parameter(
|
|
37
|
+
name="htmlMsg",
|
|
38
|
+
type="string",
|
|
39
|
+
description="The HTML message to be sent as the email body",
|
|
40
|
+
required=True
|
|
41
|
+
)
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
super().__init__(name="GmailSendTool",
|
|
45
|
+
description="Sends an email using the Gmail API.",
|
|
46
|
+
parameters=parameters)
|
|
47
|
+
self.credentials_path = credentials_path
|
|
48
|
+
self.sender_email = sender_email
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def authenticate(self):
|
|
52
|
+
"""
|
|
53
|
+
Authenticates the user and creates a Gmail API service for sending emails.
|
|
54
|
+
"""
|
|
55
|
+
credentials = service_account.Credentials.from_service_account_file(
|
|
56
|
+
self.credentials_path, scopes=self.SCOPES)
|
|
57
|
+
|
|
58
|
+
delegated_credentials = credentials.with_subject(self.sender_email)
|
|
59
|
+
self.service = build('gmail', 'v1', credentials=delegated_credentials)
|
|
60
|
+
|
|
61
|
+
def create_message(self, to: str, subject: str, message_text: str):
|
|
62
|
+
"""
|
|
63
|
+
Create a MIMEText message for sending an email.
|
|
64
|
+
|
|
65
|
+
Parameters:
|
|
66
|
+
sender (str): The email address of the sender.
|
|
67
|
+
to (str): The email address of the recipient.
|
|
68
|
+
subject (str): The subject of the email.
|
|
69
|
+
message_text (str): The HTML body of the email.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
The created MIMEText message.
|
|
73
|
+
"""
|
|
74
|
+
message = MIMEMultipart('alternative')
|
|
75
|
+
message['from'] = self.sender_email
|
|
76
|
+
message['to'] = to
|
|
77
|
+
message['subject'] = subject
|
|
78
|
+
mime_text = MIMEText(message_text, 'html')
|
|
79
|
+
message.attach(mime_text)
|
|
80
|
+
raw_message = base64.urlsafe_b64encode(message.as_string().encode('utf-8'))
|
|
81
|
+
return {'raw': raw_message.decode('utf-8')}
|
|
82
|
+
|
|
83
|
+
def __call__(self, recipients, subject, htmlMsg):
|
|
84
|
+
"""
|
|
85
|
+
Sends an email to the specified recipients with the given subject and HTML message.
|
|
86
|
+
|
|
87
|
+
Parameters:
|
|
88
|
+
sender (str): The email address of the sender.
|
|
89
|
+
recipients (str): The email address of the recipients, separated by commas.
|
|
90
|
+
subject (str): The subject of the email.
|
|
91
|
+
htmlMsg (str): The HTML content of the email body.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
The result of sending the email or an error message if the operation fails.
|
|
95
|
+
"""
|
|
96
|
+
self.authenticate()
|
|
97
|
+
try:
|
|
98
|
+
message = self.create_message(recipients, subject, htmlMsg)
|
|
99
|
+
sent_message = (self.service.users().messages().send(userId='me', body=message).execute())
|
|
100
|
+
return f"Email sent successfully to {recipients}"
|
|
101
|
+
|
|
102
|
+
except Exception as e:
|
|
103
|
+
return f"An error occurred in sending the email: {e}"
|
|
104
|
+
finally:
|
|
105
|
+
del self.service
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from ....core.tools.ITool import ITool
|
|
2
|
+
from ....standard.tools.concrete.Parameter import Parameter # Update import path as necessary
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pacmap # Ensure pacmap is installed
|
|
5
|
+
|
|
6
|
+
class PaCMAPTool(ITool):
|
|
7
|
+
"""
|
|
8
|
+
A tool for applying the PaCMAP method for dimensionality reduction.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def __init__(self):
|
|
12
|
+
parameters = [
|
|
13
|
+
Parameter(
|
|
14
|
+
name="X",
|
|
15
|
+
type="object",
|
|
16
|
+
description="X (np.ndarray): The high-dimensional data points to reduce.",
|
|
17
|
+
required=True
|
|
18
|
+
),
|
|
19
|
+
Parameter(
|
|
20
|
+
name="n_neighbors",
|
|
21
|
+
type="integer",
|
|
22
|
+
description="The size of local neighborhood (in terms of number of neighboring data points) used for manifold approximation.",
|
|
23
|
+
required=False
|
|
24
|
+
),
|
|
25
|
+
Parameter(
|
|
26
|
+
name="n_components",
|
|
27
|
+
type="integer",
|
|
28
|
+
description="The dimension of the space into which to embed the data.",
|
|
29
|
+
required=True
|
|
30
|
+
),
|
|
31
|
+
Parameter(
|
|
32
|
+
name="n_iterations",
|
|
33
|
+
type="integer",
|
|
34
|
+
description="The number of iterations used for optimization.",
|
|
35
|
+
required=False
|
|
36
|
+
)
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
super().__init__(name="PaCMAPTool",
|
|
40
|
+
description="Applies PaCMAP for dimensionality reduction.",
|
|
41
|
+
parameters=parameters)
|
|
42
|
+
|
|
43
|
+
def __call__(self, **kwargs) -> np.ndarray:
|
|
44
|
+
"""
|
|
45
|
+
Applies the PaCMAP algorithm on the provided dataset.
|
|
46
|
+
|
|
47
|
+
Parameters:
|
|
48
|
+
- kwargs: Additional keyword arguments for the PaCMAP algorithm.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
- np.ndarray: The reduced dimension data points.
|
|
52
|
+
"""
|
|
53
|
+
# Set default values for any unspecified parameters
|
|
54
|
+
X = kwargs.get('X')
|
|
55
|
+
n_neighbors = kwargs.get('n_neighbors', 30)
|
|
56
|
+
n_components = kwargs.get('n_components', 2)
|
|
57
|
+
n_iterations = kwargs.get('n_iterations', 500)
|
|
58
|
+
|
|
59
|
+
# Instantiate the PaCMAP instance with specified parameters
|
|
60
|
+
embedder = pacmap.PaCMAP(n_neighbors=n_neighbors, n_components=n_components,
|
|
61
|
+
n_iters=n_iterations, **kwargs)
|
|
62
|
+
|
|
63
|
+
# Fit the model and transform the data
|
|
64
|
+
X_reduced = embedder.fit_transform(X)
|
|
65
|
+
|
|
66
|
+
return X_reduced
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from transformers import pipeline
|
|
2
|
+
from transformers import logging as hf_logging
|
|
3
|
+
|
|
4
|
+
from ....standard.tools.base.ToolBase import ToolBase
|
|
5
|
+
from ....standard.tools.concrete.Parameter import Parameter
|
|
6
|
+
|
|
7
|
+
hf_logging.set_verbosity_error()
|
|
8
|
+
|
|
9
|
+
class SentimentAnalysisTool(ToolBase):
|
|
10
|
+
def __init__(self):
|
|
11
|
+
super().__init__("SentimentAnalysisTool",
|
|
12
|
+
"Analyzes the sentiment of the given text.",
|
|
13
|
+
parameters=[
|
|
14
|
+
Parameter("text", "string", "The text for sentiment analysis", True)
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def __call__(self, text: str) -> str:
|
|
19
|
+
try:
|
|
20
|
+
self.analyzer = pipeline("sentiment-analysis")
|
|
21
|
+
result = self.analyzer(text)
|
|
22
|
+
return result[0]['label']
|
|
23
|
+
except:
|
|
24
|
+
raise
|
|
25
|
+
finally:
|
|
26
|
+
del self.analyzer
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from bs4 import BeautifulSoup
|
|
3
|
+
from ....standard.tools.base.ToolBase import ToolBase
|
|
4
|
+
from ....standard.tools.concrete.Parameter import Parameter
|
|
5
|
+
|
|
6
|
+
class WebScrapingTool(ToolBase):
|
|
7
|
+
def __init__(self):
|
|
8
|
+
parameters = [
|
|
9
|
+
Parameter(
|
|
10
|
+
name="url",
|
|
11
|
+
type="string",
|
|
12
|
+
description="URL of the link, website, webpage, etc... to scrape",
|
|
13
|
+
required=True
|
|
14
|
+
),
|
|
15
|
+
Parameter(
|
|
16
|
+
name="selector",
|
|
17
|
+
type="string",
|
|
18
|
+
description="CSS selector to target specific elements",
|
|
19
|
+
required=True
|
|
20
|
+
)
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
super().__init__(name="WebScrapingTool",
|
|
24
|
+
description="This is a web scraping tool that you can utilize to scrape links, websites, webpages, etc... This tool uses python's requests and BeautifulSoup libraries to parse a URL using a CSS to target specific elements.",
|
|
25
|
+
parameters=parameters)
|
|
26
|
+
|
|
27
|
+
def __call__(self, url: str, selector: str) -> str:
|
|
28
|
+
"""
|
|
29
|
+
Fetches content from the specified URL and extracts elements based on the provided CSS selector.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
url (str): The URL of the webpage to scrape.
|
|
33
|
+
selector (str): CSS selector to target specific elements in the webpage.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
str: Extracted text from the selector or an error message.
|
|
37
|
+
"""
|
|
38
|
+
try:
|
|
39
|
+
response = requests.get(url)
|
|
40
|
+
response.raise_for_status() # Raises HTTPError for bad requests (4xx or 5xx)
|
|
41
|
+
|
|
42
|
+
html_content = response.content
|
|
43
|
+
soup = BeautifulSoup(html_content, 'html.parser')
|
|
44
|
+
|
|
45
|
+
elements = soup.select(selector)
|
|
46
|
+
extracted_text = '\n'.join([element.text for element in elements])
|
|
47
|
+
return extracted_text
|
|
48
|
+
except requests.RequestException as e:
|
|
49
|
+
return f"Request Exception: {str(e)}"
|
|
50
|
+
except Exception as e:
|
|
51
|
+
return f"Unexpected error: {str(e)}"
|
|
File without changes
|
|
File without changes
|