ai-parrot 0.8.3__cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.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.

Potentially problematic release.


This version of ai-parrot might be problematic. Click here for more details.

Files changed (128) hide show
  1. ai_parrot-0.8.3.dist-info/LICENSE +21 -0
  2. ai_parrot-0.8.3.dist-info/METADATA +306 -0
  3. ai_parrot-0.8.3.dist-info/RECORD +128 -0
  4. ai_parrot-0.8.3.dist-info/WHEEL +6 -0
  5. ai_parrot-0.8.3.dist-info/top_level.txt +2 -0
  6. parrot/__init__.py +30 -0
  7. parrot/bots/__init__.py +5 -0
  8. parrot/bots/abstract.py +1115 -0
  9. parrot/bots/agent.py +492 -0
  10. parrot/bots/basic.py +9 -0
  11. parrot/bots/bose.py +17 -0
  12. parrot/bots/chatbot.py +271 -0
  13. parrot/bots/cody.py +17 -0
  14. parrot/bots/copilot.py +117 -0
  15. parrot/bots/data.py +730 -0
  16. parrot/bots/dataframe.py +103 -0
  17. parrot/bots/hrbot.py +15 -0
  18. parrot/bots/interfaces/__init__.py +1 -0
  19. parrot/bots/interfaces/retrievers.py +12 -0
  20. parrot/bots/notebook.py +619 -0
  21. parrot/bots/odoo.py +17 -0
  22. parrot/bots/prompts/__init__.py +41 -0
  23. parrot/bots/prompts/agents.py +91 -0
  24. parrot/bots/prompts/data.py +214 -0
  25. parrot/bots/retrievals/__init__.py +1 -0
  26. parrot/bots/retrievals/constitutional.py +19 -0
  27. parrot/bots/retrievals/multi.py +122 -0
  28. parrot/bots/retrievals/retrieval.py +610 -0
  29. parrot/bots/tools/__init__.py +7 -0
  30. parrot/bots/tools/eda.py +325 -0
  31. parrot/bots/tools/pdf.py +50 -0
  32. parrot/bots/tools/plot.py +48 -0
  33. parrot/bots/troc.py +16 -0
  34. parrot/conf.py +170 -0
  35. parrot/crew/__init__.py +3 -0
  36. parrot/crew/tools/__init__.py +22 -0
  37. parrot/crew/tools/bing.py +13 -0
  38. parrot/crew/tools/config.py +43 -0
  39. parrot/crew/tools/duckgo.py +62 -0
  40. parrot/crew/tools/file.py +24 -0
  41. parrot/crew/tools/google.py +168 -0
  42. parrot/crew/tools/gtrends.py +16 -0
  43. parrot/crew/tools/md2pdf.py +25 -0
  44. parrot/crew/tools/rag.py +42 -0
  45. parrot/crew/tools/search.py +32 -0
  46. parrot/crew/tools/url.py +21 -0
  47. parrot/exceptions.cpython-312-x86_64-linux-gnu.so +0 -0
  48. parrot/handlers/__init__.py +4 -0
  49. parrot/handlers/agents.py +292 -0
  50. parrot/handlers/bots.py +196 -0
  51. parrot/handlers/chat.py +192 -0
  52. parrot/interfaces/__init__.py +6 -0
  53. parrot/interfaces/database.py +27 -0
  54. parrot/interfaces/http.py +805 -0
  55. parrot/interfaces/images/__init__.py +0 -0
  56. parrot/interfaces/images/plugins/__init__.py +18 -0
  57. parrot/interfaces/images/plugins/abstract.py +58 -0
  58. parrot/interfaces/images/plugins/exif.py +709 -0
  59. parrot/interfaces/images/plugins/hash.py +52 -0
  60. parrot/interfaces/images/plugins/vision.py +104 -0
  61. parrot/interfaces/images/plugins/yolo.py +66 -0
  62. parrot/interfaces/images/plugins/zerodetect.py +197 -0
  63. parrot/llms/__init__.py +1 -0
  64. parrot/llms/abstract.py +69 -0
  65. parrot/llms/anthropic.py +58 -0
  66. parrot/llms/gemma.py +15 -0
  67. parrot/llms/google.py +44 -0
  68. parrot/llms/groq.py +67 -0
  69. parrot/llms/hf.py +45 -0
  70. parrot/llms/openai.py +61 -0
  71. parrot/llms/pipes.py +114 -0
  72. parrot/llms/vertex.py +89 -0
  73. parrot/loaders/__init__.py +9 -0
  74. parrot/loaders/abstract.py +628 -0
  75. parrot/loaders/files/__init__.py +0 -0
  76. parrot/loaders/files/abstract.py +39 -0
  77. parrot/loaders/files/text.py +63 -0
  78. parrot/loaders/txt.py +26 -0
  79. parrot/manager.py +333 -0
  80. parrot/models.py +504 -0
  81. parrot/py.typed +0 -0
  82. parrot/stores/__init__.py +11 -0
  83. parrot/stores/abstract.py +248 -0
  84. parrot/stores/chroma.py +188 -0
  85. parrot/stores/duck.py +162 -0
  86. parrot/stores/embeddings/__init__.py +10 -0
  87. parrot/stores/embeddings/abstract.py +46 -0
  88. parrot/stores/embeddings/base.py +52 -0
  89. parrot/stores/embeddings/bge.py +20 -0
  90. parrot/stores/embeddings/fastembed.py +17 -0
  91. parrot/stores/embeddings/google.py +18 -0
  92. parrot/stores/embeddings/huggingface.py +20 -0
  93. parrot/stores/embeddings/ollama.py +14 -0
  94. parrot/stores/embeddings/openai.py +26 -0
  95. parrot/stores/embeddings/transformers.py +21 -0
  96. parrot/stores/embeddings/vertexai.py +17 -0
  97. parrot/stores/empty.py +10 -0
  98. parrot/stores/faiss.py +160 -0
  99. parrot/stores/milvus.py +397 -0
  100. parrot/stores/postgres.py +653 -0
  101. parrot/stores/qdrant.py +170 -0
  102. parrot/tools/__init__.py +23 -0
  103. parrot/tools/abstract.py +68 -0
  104. parrot/tools/asknews.py +33 -0
  105. parrot/tools/basic.py +51 -0
  106. parrot/tools/bby.py +359 -0
  107. parrot/tools/bing.py +13 -0
  108. parrot/tools/docx.py +343 -0
  109. parrot/tools/duck.py +62 -0
  110. parrot/tools/execute.py +56 -0
  111. parrot/tools/gamma.py +28 -0
  112. parrot/tools/google.py +170 -0
  113. parrot/tools/gvoice.py +301 -0
  114. parrot/tools/results.py +278 -0
  115. parrot/tools/stack.py +27 -0
  116. parrot/tools/weather.py +70 -0
  117. parrot/tools/wikipedia.py +58 -0
  118. parrot/tools/zipcode.py +198 -0
  119. parrot/utils/__init__.py +2 -0
  120. parrot/utils/parsers/__init__.py +5 -0
  121. parrot/utils/parsers/toml.cpython-312-x86_64-linux-gnu.so +0 -0
  122. parrot/utils/toml.py +11 -0
  123. parrot/utils/types.cpython-312-x86_64-linux-gnu.so +0 -0
  124. parrot/utils/uv.py +11 -0
  125. parrot/version.py +10 -0
  126. resources/users/__init__.py +5 -0
  127. resources/users/handlers.py +13 -0
  128. resources/users/models.py +205 -0
@@ -0,0 +1,20 @@
1
+ from langchain_community.embeddings import HuggingFaceBgeEmbeddings
2
+ from .base import BaseEmbed
3
+
4
+
5
+ class BgeEmbed(BaseEmbed):
6
+ """A wrapper class for VertexAI embeddings."""
7
+ model_name: str = "BAAI/bge-large-en-v1.5"
8
+
9
+ def _create_embedding(self, model_name: str = None, **kwargs):
10
+ # Embedding Model:
11
+ device = self._get_device()
12
+ model_args = {
13
+ **self.model_kwargs,
14
+ 'device': device,
15
+ }
16
+ return HuggingFaceBgeEmbeddings(
17
+ model_name=model_name or self.model_name,
18
+ model_kwargs=model_args,
19
+ encode_kwargs=self.encode_kwargs
20
+ )
@@ -0,0 +1,17 @@
1
+ from langchain_community.embeddings.fastembed import (
2
+ FastEmbedEmbeddings
3
+ )
4
+ from .abstract import AbstractEmbed
5
+
6
+
7
+ class FastembedEmbed(AbstractEmbed):
8
+ """A wrapper class for FastEmbed embeddings."""
9
+ model_name: str = "BAAI/bge-large-en-v1.5"
10
+
11
+ def _create_embedding(self, model_name: str = None, **kwargs):
12
+ # Embedding Model:
13
+ return FastEmbedEmbeddings(
14
+ model_name=model_name,
15
+ max_length=1024,
16
+ threads=4
17
+ )
@@ -0,0 +1,18 @@
1
+ from langchain_google_genai import (
2
+ GoogleGenerativeAIEmbeddings
3
+ )
4
+ from .abstract import AbstractEmbed
5
+ from ...conf import GOOGLE_API_KEY
6
+
7
+ class GoogleEmbed(AbstractEmbed):
8
+ """A wrapper class for VertexAI embeddings."""
9
+ model_name: str = "models/embedding-001"
10
+
11
+ def _create_embedding(self, model_name: str = None, api_key: str = None, **kwargs):
12
+ # Embedding Model:
13
+ api_key = api_key or GOOGLE_API_KEY
14
+ return GoogleGenerativeAIEmbeddings(
15
+ model=model_name or self.model_name,
16
+ google_api_key=api_key,
17
+ **kwargs
18
+ )
@@ -0,0 +1,20 @@
1
+ from langchain_huggingface import HuggingFaceEmbeddings
2
+ from .base import BaseEmbed
3
+
4
+
5
+ class HugginfaceEmbed(BaseEmbed):
6
+ """A wrapper class for HuggingFace embeddings."""
7
+ model_name: str = "sentence-transformers/all-mpnet-base-v2"
8
+
9
+ def _create_embedding(self, model_name: str = None, **kwargs):
10
+ # Embedding Model:
11
+ device = self._get_device()
12
+ model_args = {
13
+ **self.model_kwargs,
14
+ 'device': device,
15
+ }
16
+ return HuggingFaceEmbeddings(
17
+ model_name=model_name or self.model_name,
18
+ model_kwargs=model_args,
19
+ encode_kwargs=self.encode_kwargs
20
+ )
@@ -0,0 +1,14 @@
1
+ from langchain_ollama import OllamaEmbeddings
2
+ from .base import BaseEmbed
3
+
4
+
5
+ class OllamaEmbed(BaseEmbed):
6
+ """A wrapper class for Ollama embeddings."""
7
+ model_name: str = "llama3"
8
+
9
+ def _create_embedding(self, model_name: str = None, **kwargs):
10
+ # Embedding Model:
11
+ return OllamaEmbeddings(
12
+ model_name=model_name or self.model_name,
13
+ **kwargs
14
+ )
@@ -0,0 +1,26 @@
1
+ from langchain_openai import ( # pylint: disable=E0401, E0611
2
+ OpenAIEmbeddings
3
+ )
4
+ from .abstract import AbstractEmbed
5
+ from ...conf import OPENAI_API_KEY, OPENAI_ORGANIZATION
6
+
7
+
8
+ class OpenAIEmbed(AbstractEmbed):
9
+ """A wrapper class for OpenAI embeddings."""
10
+ model_name: str = "text-embedding-3-large"
11
+
12
+ def _create_embedding(
13
+ self,
14
+ model_name: str = None,
15
+ api_key: str = None,
16
+ organization: str = None,
17
+ **kwargs
18
+ ):
19
+ # Embedding
20
+ return OpenAIEmbeddings(
21
+ model=model_name or self.model_name,
22
+ dimensions=kwargs.get('dimensions', 512),
23
+ api_key=api_key or OPENAI_API_KEY,
24
+ organization=organization or OPENAI_ORGANIZATION,
25
+ max_retries=kwargs.get('max_retries', 4),
26
+ )
@@ -0,0 +1,21 @@
1
+ from langchain_huggingface import HuggingFaceEmbeddings
2
+ from .base import BaseEmbed
3
+
4
+
5
+ class TransformersEmbed(BaseEmbed):
6
+ """A wrapper class for Transformers embeddings."""
7
+ model_name: str = "all-MiniLM-L6-v2"
8
+ # "sentence-transformers/all-mpnet-base-v2"
9
+
10
+ def _create_embedding(self, model_name: str = None, **kwargs):
11
+ # Embedding Model:
12
+ device = self._get_device()
13
+ model_args = {
14
+ **self.model_kwargs,
15
+ 'device': device,
16
+ }
17
+ return HuggingFaceEmbeddings(
18
+ model_name=model_name or self.model_name,
19
+ model_kwargs=model_args,
20
+ encode_kwargs=self.encode_kwargs
21
+ )
@@ -0,0 +1,17 @@
1
+ from langchain_google_vertexai import VertexAIEmbeddings
2
+ from ...conf import VERTEX_PROJECT_ID, VERTEX_REGION
3
+ from .abstract import AbstractEmbed
4
+
5
+ class VertexAIEmbed(AbstractEmbed):
6
+ """A wrapper class for VertexAI embeddings."""
7
+ model_name: str = "text-embedding-004"
8
+
9
+ def _create_embedding(self, model_name: str = None, project_id: str = None, region: str = None):
10
+ # Embedding Model:
11
+ return VertexAIEmbeddings(
12
+ model_name=model_name or self.model_name,
13
+ project=project_id or VERTEX_PROJECT_ID,
14
+ location=region or VERTEX_REGION,
15
+ request_parallelism=5,
16
+ max_retries=4,
17
+ )
parrot/stores/empty.py ADDED
@@ -0,0 +1,10 @@
1
+ class EmptyStore:
2
+ """
3
+ Empty Store reference, used on bots without Vector Store Support.
4
+ """
5
+
6
+ async def __aenter__(self):
7
+ return self
8
+
9
+ async def __aexit__(self, exc_type, exc_value, traceback):
10
+ pass
parrot/stores/faiss.py ADDED
@@ -0,0 +1,160 @@
1
+ from collections.abc import Callable
2
+ from pathlib import PurePath
3
+ from typing import Optional, Union
4
+ from uuid import uuid4
5
+ import faiss
6
+ from langchain.docstore.document import Document
7
+ from langchain.memory import VectorStoreRetrieverMemory
8
+ from langchain_community.vectorstores import FAISS
9
+ from langchain_community.docstore.in_memory import InMemoryDocstore
10
+ from langchain_community.vectorstores.utils import DistanceStrategy
11
+ from .abstract import AbstractStore
12
+
13
+
14
+ class FaissStore(AbstractStore):
15
+ """FAISS DB Store Class.
16
+
17
+ Using FAISS as an in-memory Document Vector Store.
18
+
19
+ """
20
+
21
+ def __init__(
22
+ self,
23
+ embedding_model: Union[dict, str] = None,
24
+ embedding: Union[dict, Callable] = None,
25
+ **kwargs
26
+ ):
27
+ super().__init__(
28
+ embedding_model=embedding_model,
29
+ embedding=embedding,
30
+ **kwargs
31
+ )
32
+ self.index_path: PurePath = kwargs.pop('index_path', 'faiss_index')
33
+ if not self.index_path.exists():
34
+ self.index_path.mkdir(exist_ok=True)
35
+
36
+ async def connection(self):
37
+ """Initialize FAISS vector store.
38
+
39
+ If an index exists, load it; otherwise, create a new FAISS store.
40
+ """
41
+ try:
42
+ index_file = self.index_path.joinpath("index.faiss")
43
+ if not index_file.exists():
44
+ raise FileNotFoundError
45
+ self._connection = FAISS.load_local(
46
+ folder_path=self.index_path,
47
+ embeddings=self._embed_.embedding,
48
+ allow_dangerous_deserialization=True,
49
+ distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE
50
+ )
51
+ except FileNotFoundError:
52
+ # Create a new FAISS index if none exists.
53
+ print(len(self._embed_.embedding.embed_query("test")))
54
+ index = faiss.IndexFlatL2(len(self._embed_.embedding.embed_query("test")))
55
+ self._connection = FAISS(
56
+ embedding_function=self._embed_.embedding,
57
+ index=index,
58
+ docstore=InMemoryDocstore(),
59
+ index_to_docstore_id={},
60
+ normalize_L2=True,
61
+ distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE
62
+ )
63
+ self._connection.save_local(self.index_path) # Save the new index
64
+ self._connected = True
65
+ return self._connection
66
+
67
+ async def disconnect(self) -> None:
68
+ """Clears FAISS in-memory index."""
69
+ self._connection = None
70
+ self._connected = False
71
+
72
+ def get_vector(
73
+ self,
74
+ embedding: Optional[Callable] = None,
75
+ ) -> FAISS:
76
+ """Returns FAISS VectorStore instance."""
77
+ if embedding is not None:
78
+ _embed_ = embedding
79
+ else:
80
+ _embed_ = self.create_embedding(
81
+ embedding_model=self.embedding_model
82
+ )
83
+ return FAISS.load_local(
84
+ folder_path=self.index_path,
85
+ embeddings=_embed_,
86
+ allow_dangerous_deserialization=True,
87
+ distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE
88
+ )
89
+
90
+ async def from_documents(self, documents: list[Document], **kwargs):
91
+ """Save Documents as Vectors in FAISS."""
92
+ vectordb = await FAISS.afrom_documents(
93
+ documents=documents,
94
+ embedding=self._embed_.embedding,
95
+ allow_dangerous_deserialization=True,
96
+ distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE
97
+ )
98
+ vectordb.save_local(self.index_path) # Persist FAISS index
99
+ return vectordb
100
+
101
+ async def add_documents(
102
+ self,
103
+ documents: list,
104
+ embedding: Optional[Callable] = None,
105
+ ) -> bool:
106
+ """Add Documents to FAISS."""
107
+ async with self:
108
+ vector_db = self.get_vector(embedding=embedding)
109
+ await vector_db.aadd_documents(documents=documents)
110
+ vector_db.save_local(self.index_path) # Save updated index
111
+ return True
112
+
113
+ async def update_documents(
114
+ self,
115
+ documents: list,
116
+ embedding: Optional[Callable] = None,
117
+ ) -> bool:
118
+ """
119
+ Update Documents in FAISS (FAISS does not natively support updates).
120
+ """
121
+ async with self:
122
+ vector_db = self.get_vector(embedding=embedding)
123
+ if all('id' in doc for doc in documents):
124
+ ids = [doc.pop('id') for doc in documents]
125
+ vector_db.delete(ids) # Remove old entries
126
+ await vector_db.aadd_documents(documents=documents) # Add new versions
127
+ vector_db.save_local(self.index_path)
128
+ return True
129
+ return False
130
+
131
+ async def similarity_search(
132
+ self,
133
+ query: str,
134
+ embedding: Optional[Callable] = None,
135
+ limit: int = 2,
136
+ ) -> list:
137
+ """Performs similarity search in FAISS."""
138
+ async with self:
139
+ vector_db = self.get_vector(embedding=embedding)
140
+ return vector_db.similarity_search(query, k=limit)
141
+
142
+ def memory_retriever(
143
+ self,
144
+ documents: Optional[list] = None,
145
+ num_results: int = 5
146
+ ) -> VectorStoreRetrieverMemory:
147
+ """Retrieves stored memory-based documents."""
148
+ if not documents:
149
+ documents = []
150
+ vectordb = FAISS.from_documents(
151
+ documents=documents,
152
+ embedding=self._embed_.embedding,
153
+ allow_dangerous_deserialization=True,
154
+ distance_strategy=DistanceStrategy.EUCLIDEAN_DISTANCE
155
+ )
156
+ retriever = FAISS.as_retriever(
157
+ vectordb,
158
+ search_kwargs=dict(k=num_results)
159
+ )
160
+ return VectorStoreRetrieverMemory(retriever=retriever)