ai-parrot 0.8.3__cp311-cp311-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.
- ai_parrot-0.8.3.dist-info/LICENSE +21 -0
- ai_parrot-0.8.3.dist-info/METADATA +306 -0
- ai_parrot-0.8.3.dist-info/RECORD +128 -0
- ai_parrot-0.8.3.dist-info/WHEEL +6 -0
- ai_parrot-0.8.3.dist-info/top_level.txt +2 -0
- parrot/__init__.py +30 -0
- parrot/bots/__init__.py +5 -0
- parrot/bots/abstract.py +1115 -0
- parrot/bots/agent.py +492 -0
- parrot/bots/basic.py +9 -0
- parrot/bots/bose.py +17 -0
- parrot/bots/chatbot.py +271 -0
- parrot/bots/cody.py +17 -0
- parrot/bots/copilot.py +117 -0
- parrot/bots/data.py +730 -0
- parrot/bots/dataframe.py +103 -0
- parrot/bots/hrbot.py +15 -0
- parrot/bots/interfaces/__init__.py +1 -0
- parrot/bots/interfaces/retrievers.py +12 -0
- parrot/bots/notebook.py +619 -0
- parrot/bots/odoo.py +17 -0
- parrot/bots/prompts/__init__.py +41 -0
- parrot/bots/prompts/agents.py +91 -0
- parrot/bots/prompts/data.py +214 -0
- parrot/bots/retrievals/__init__.py +1 -0
- parrot/bots/retrievals/constitutional.py +19 -0
- parrot/bots/retrievals/multi.py +122 -0
- parrot/bots/retrievals/retrieval.py +610 -0
- parrot/bots/tools/__init__.py +7 -0
- parrot/bots/tools/eda.py +325 -0
- parrot/bots/tools/pdf.py +50 -0
- parrot/bots/tools/plot.py +48 -0
- parrot/bots/troc.py +16 -0
- parrot/conf.py +170 -0
- parrot/crew/__init__.py +3 -0
- parrot/crew/tools/__init__.py +22 -0
- parrot/crew/tools/bing.py +13 -0
- parrot/crew/tools/config.py +43 -0
- parrot/crew/tools/duckgo.py +62 -0
- parrot/crew/tools/file.py +24 -0
- parrot/crew/tools/google.py +168 -0
- parrot/crew/tools/gtrends.py +16 -0
- parrot/crew/tools/md2pdf.py +25 -0
- parrot/crew/tools/rag.py +42 -0
- parrot/crew/tools/search.py +32 -0
- parrot/crew/tools/url.py +21 -0
- parrot/exceptions.cpython-311-x86_64-linux-gnu.so +0 -0
- parrot/handlers/__init__.py +4 -0
- parrot/handlers/agents.py +292 -0
- parrot/handlers/bots.py +196 -0
- parrot/handlers/chat.py +192 -0
- parrot/interfaces/__init__.py +6 -0
- parrot/interfaces/database.py +27 -0
- parrot/interfaces/http.py +805 -0
- parrot/interfaces/images/__init__.py +0 -0
- parrot/interfaces/images/plugins/__init__.py +18 -0
- parrot/interfaces/images/plugins/abstract.py +58 -0
- parrot/interfaces/images/plugins/exif.py +709 -0
- parrot/interfaces/images/plugins/hash.py +52 -0
- parrot/interfaces/images/plugins/vision.py +104 -0
- parrot/interfaces/images/plugins/yolo.py +66 -0
- parrot/interfaces/images/plugins/zerodetect.py +197 -0
- parrot/llms/__init__.py +1 -0
- parrot/llms/abstract.py +69 -0
- parrot/llms/anthropic.py +58 -0
- parrot/llms/gemma.py +15 -0
- parrot/llms/google.py +44 -0
- parrot/llms/groq.py +67 -0
- parrot/llms/hf.py +45 -0
- parrot/llms/openai.py +61 -0
- parrot/llms/pipes.py +114 -0
- parrot/llms/vertex.py +89 -0
- parrot/loaders/__init__.py +9 -0
- parrot/loaders/abstract.py +628 -0
- parrot/loaders/files/__init__.py +0 -0
- parrot/loaders/files/abstract.py +39 -0
- parrot/loaders/files/text.py +63 -0
- parrot/loaders/txt.py +26 -0
- parrot/manager.py +333 -0
- parrot/models.py +504 -0
- parrot/py.typed +0 -0
- parrot/stores/__init__.py +11 -0
- parrot/stores/abstract.py +248 -0
- parrot/stores/chroma.py +188 -0
- parrot/stores/duck.py +162 -0
- parrot/stores/embeddings/__init__.py +10 -0
- parrot/stores/embeddings/abstract.py +46 -0
- parrot/stores/embeddings/base.py +52 -0
- parrot/stores/embeddings/bge.py +20 -0
- parrot/stores/embeddings/fastembed.py +17 -0
- parrot/stores/embeddings/google.py +18 -0
- parrot/stores/embeddings/huggingface.py +20 -0
- parrot/stores/embeddings/ollama.py +14 -0
- parrot/stores/embeddings/openai.py +26 -0
- parrot/stores/embeddings/transformers.py +21 -0
- parrot/stores/embeddings/vertexai.py +17 -0
- parrot/stores/empty.py +10 -0
- parrot/stores/faiss.py +160 -0
- parrot/stores/milvus.py +397 -0
- parrot/stores/postgres.py +653 -0
- parrot/stores/qdrant.py +170 -0
- parrot/tools/__init__.py +23 -0
- parrot/tools/abstract.py +68 -0
- parrot/tools/asknews.py +33 -0
- parrot/tools/basic.py +51 -0
- parrot/tools/bby.py +359 -0
- parrot/tools/bing.py +13 -0
- parrot/tools/docx.py +343 -0
- parrot/tools/duck.py +62 -0
- parrot/tools/execute.py +56 -0
- parrot/tools/gamma.py +28 -0
- parrot/tools/google.py +170 -0
- parrot/tools/gvoice.py +301 -0
- parrot/tools/results.py +278 -0
- parrot/tools/stack.py +27 -0
- parrot/tools/weather.py +70 -0
- parrot/tools/wikipedia.py +58 -0
- parrot/tools/zipcode.py +198 -0
- parrot/utils/__init__.py +2 -0
- parrot/utils/parsers/__init__.py +5 -0
- parrot/utils/parsers/toml.cpython-311-x86_64-linux-gnu.so +0 -0
- parrot/utils/toml.py +11 -0
- parrot/utils/types.cpython-311-x86_64-linux-gnu.so +0 -0
- parrot/utils/uv.py +11 -0
- parrot/version.py +10 -0
- resources/users/__init__.py +5 -0
- resources/users/handlers.py +13 -0
- 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
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)
|