ai-parrot 0.8.3__cp39-cp39-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-39-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-39-x86_64-linux-gnu.so +0 -0
- parrot/utils/toml.py +11 -0
- parrot/utils/types.cpython-39-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
parrot/llms/hf.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from langchain_community.llms import HuggingFacePipeline # pylint: disable=import-error, E0611
|
|
2
|
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
3
|
+
from .abstract import AbstractLLM
|
|
4
|
+
|
|
5
|
+
class HuggingFace(AbstractLLM):
|
|
6
|
+
"""HuggingFace.
|
|
7
|
+
|
|
8
|
+
Load a LLM (Language Model) from HuggingFace Hub.
|
|
9
|
+
|
|
10
|
+
Only supports text-generation, text2text-generation, summarization and translation for now.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
_type_: an instance of HuggingFace LLM Model.
|
|
14
|
+
"""
|
|
15
|
+
model: str = "databricks/dolly-v2-3b"
|
|
16
|
+
embed_model: str = None
|
|
17
|
+
max_tokens: int = 1024
|
|
18
|
+
supported_models: list = [
|
|
19
|
+
"databricks/dolly-v2-3b",
|
|
20
|
+
"gpt2",
|
|
21
|
+
"bigscience/bloom-1b7",
|
|
22
|
+
"meta-llama/Llama-2-7b-hf"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
def __init__(self, *args, **kwargs):
|
|
26
|
+
self.batch_size = kwargs.get('batch_size', 4)
|
|
27
|
+
super().__init__(*args, **kwargs)
|
|
28
|
+
self._tokenizer = AutoTokenizer.from_pretrained(self.model, chunk_size=self.max_tokens)
|
|
29
|
+
self._model = AutoModelForCausalLM.from_pretrained(self.model, trust_remote_code=True)
|
|
30
|
+
self._llm = HuggingFacePipeline.from_model_id(
|
|
31
|
+
model_id=self.model,
|
|
32
|
+
task=self.task,
|
|
33
|
+
device_map='auto',
|
|
34
|
+
batch_size=self.batch_size,
|
|
35
|
+
model_kwargs={
|
|
36
|
+
"max_length": self.max_tokens,
|
|
37
|
+
"trust_remote_code": True
|
|
38
|
+
},
|
|
39
|
+
pipeline_kwargs={
|
|
40
|
+
"temperature": self.temperature,
|
|
41
|
+
"repetition_penalty":1.1,
|
|
42
|
+
"max_new_tokens": self.max_tokens,
|
|
43
|
+
**self.args
|
|
44
|
+
}
|
|
45
|
+
)
|
parrot/llms/openai.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from langchain_openai import ( # pylint: disable=E0401, E0611
|
|
2
|
+
OpenAI,
|
|
3
|
+
ChatOpenAI,
|
|
4
|
+
)
|
|
5
|
+
from navconfig import config
|
|
6
|
+
from navconfig.logging import logging
|
|
7
|
+
from .abstract import AbstractLLM
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
logging.getLogger(name='openai').setLevel(logging.WARNING)
|
|
11
|
+
logging.getLogger(name='httpcore').setLevel(logging.WARNING)
|
|
12
|
+
logging.getLogger(name='httpx').setLevel(logging.WARNING)
|
|
13
|
+
|
|
14
|
+
class OpenAILLM(AbstractLLM):
|
|
15
|
+
"""OpenAI.
|
|
16
|
+
Interact with OpenAI Language Model.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
_type_: an instance of OpenAI LLM Model.
|
|
20
|
+
"""
|
|
21
|
+
model: str = "gpt-4-turbo"
|
|
22
|
+
max_tokens: int = 8192
|
|
23
|
+
top_k: float = 40
|
|
24
|
+
top_p: float = 1.0
|
|
25
|
+
supported_models: list = [
|
|
26
|
+
"gpt-4.1",
|
|
27
|
+
"gpt-4o-mini",
|
|
28
|
+
'gpt-4.1-2025-04-14',
|
|
29
|
+
'o4-mini-2025-04-16',
|
|
30
|
+
"o3-2025-04-16",
|
|
31
|
+
'gpt-4-turbo',
|
|
32
|
+
'gpt-4o',
|
|
33
|
+
'gpt-3.5-turbo',
|
|
34
|
+
'gpt-3.5-turbo-instruct',
|
|
35
|
+
'dall-e-3'
|
|
36
|
+
'tts-1',
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
def __init__(self, *args, use_chat: bool = False, **kwargs):
|
|
40
|
+
self.model_type = kwargs.get("model_type", "text")
|
|
41
|
+
super().__init__(*args, **kwargs)
|
|
42
|
+
self.model = kwargs.get("model", "davinci")
|
|
43
|
+
self._api_key = kwargs.pop('api_key', config.get('OPENAI_API_KEY'))
|
|
44
|
+
organization = config.get("OPENAI_ORGANIZATION")
|
|
45
|
+
if use_chat:
|
|
46
|
+
base_llm = ChatOpenAI
|
|
47
|
+
else:
|
|
48
|
+
base_llm = OpenAI
|
|
49
|
+
args = {
|
|
50
|
+
"api_key": self._api_key,
|
|
51
|
+
"organization": organization,
|
|
52
|
+
"temperature": self.temperature,
|
|
53
|
+
"max_tokens": self.max_tokens,
|
|
54
|
+
"max_retries": 4,
|
|
55
|
+
"top_p": self.top_p,
|
|
56
|
+
"verbose": True
|
|
57
|
+
}
|
|
58
|
+
self._llm = base_llm(
|
|
59
|
+
model_name=self.model,
|
|
60
|
+
**args
|
|
61
|
+
)
|
parrot/llms/pipes.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from langchain_community.llms import HuggingFacePipeline # pylint: disable=import-error, E0611
|
|
3
|
+
from transformers import (
|
|
4
|
+
AutoModelForCausalLM,
|
|
5
|
+
AutoProcessor,
|
|
6
|
+
LlavaForConditionalGeneration,
|
|
7
|
+
AutoTokenizer,
|
|
8
|
+
GenerationConfig,
|
|
9
|
+
pipeline
|
|
10
|
+
)
|
|
11
|
+
from .abstract import AbstractLLM
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PipelineLLM(AbstractLLM):
|
|
15
|
+
"""PipelineLLM.
|
|
16
|
+
|
|
17
|
+
Load a LLM (Language Model) from HuggingFace Hub.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
_type_: an instance of HuggingFace LLM Model.
|
|
21
|
+
"""
|
|
22
|
+
model: str = "databricks/dolly-v2-3b"
|
|
23
|
+
embed_model: str = None
|
|
24
|
+
max_tokens: int = 1024
|
|
25
|
+
supported_models: list = [
|
|
26
|
+
"databricks/dolly-v2-3b",
|
|
27
|
+
"gpt2",
|
|
28
|
+
"bigscience/bloom-1b7",
|
|
29
|
+
"meta-llama/Llama-2-7b-hf",
|
|
30
|
+
'llava-hf/llava-1.5-7b-hf'
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
def __init__(self, *args, **kwargs):
|
|
34
|
+
self.batch_size = kwargs.get('batch_size', 4)
|
|
35
|
+
self.use_llava: bool = kwargs.get('use_llava', False)
|
|
36
|
+
self.model_args = kwargs.get('model_args', {})
|
|
37
|
+
super().__init__(*args, **kwargs)
|
|
38
|
+
dtype = kwargs.get('dtype', 'float16')
|
|
39
|
+
if dtype == 'bfloat16':
|
|
40
|
+
torch_dtype = torch.bfloat16
|
|
41
|
+
if dtype == 'float16':
|
|
42
|
+
torch_dtype = torch.float16
|
|
43
|
+
elif dtype == 'float32':
|
|
44
|
+
torch_dtype = torch.float32
|
|
45
|
+
elif dtype == 'float8':
|
|
46
|
+
torch_dtype = torch.float8
|
|
47
|
+
else:
|
|
48
|
+
torch_dtype = "auto"
|
|
49
|
+
use_fast = kwargs.get('use_fast', True)
|
|
50
|
+
if self.use_llava is False:
|
|
51
|
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
|
52
|
+
self.model,
|
|
53
|
+
chunk_size=self.max_tokens
|
|
54
|
+
)
|
|
55
|
+
self._model = AutoModelForCausalLM.from_pretrained(
|
|
56
|
+
self.model,
|
|
57
|
+
device_map="auto",
|
|
58
|
+
torch_dtype=torch_dtype,
|
|
59
|
+
trust_remote_code=True,
|
|
60
|
+
)
|
|
61
|
+
config = GenerationConfig(
|
|
62
|
+
do_sample=True,
|
|
63
|
+
temperature=self.temperature,
|
|
64
|
+
max_new_tokens=self.max_tokens,
|
|
65
|
+
top_p=self.top_p,
|
|
66
|
+
top_k=self.top_k,
|
|
67
|
+
repetition_penalty=1.15,
|
|
68
|
+
)
|
|
69
|
+
self._pipe = pipeline(
|
|
70
|
+
task=self.task,
|
|
71
|
+
model=self._model,
|
|
72
|
+
tokenizer=self.tokenizer,
|
|
73
|
+
return_full_text=True,
|
|
74
|
+
use_fast=use_fast,
|
|
75
|
+
device_map='auto',
|
|
76
|
+
batch_size=self.batch_size,
|
|
77
|
+
generation_config=config,
|
|
78
|
+
pad_token_id = 50256,
|
|
79
|
+
framework="pt"
|
|
80
|
+
)
|
|
81
|
+
else:
|
|
82
|
+
self._model = LlavaForConditionalGeneration.from_pretrained(
|
|
83
|
+
self.model,
|
|
84
|
+
device_map="auto",
|
|
85
|
+
torch_dtype=torch_dtype,
|
|
86
|
+
trust_remote_code=True,
|
|
87
|
+
low_cpu_mem_usage=True,
|
|
88
|
+
)
|
|
89
|
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model)
|
|
90
|
+
processor = AutoProcessor.from_pretrained(self.model)
|
|
91
|
+
self._pipe = pipeline(
|
|
92
|
+
task=self.task,
|
|
93
|
+
model=self._model,
|
|
94
|
+
tokenizer=self.tokenizer,
|
|
95
|
+
use_fast=use_fast,
|
|
96
|
+
device_map='auto',
|
|
97
|
+
batch_size=self.batch_size,
|
|
98
|
+
image_processor=processor.image_processor,
|
|
99
|
+
framework="pt",
|
|
100
|
+
**self.model_args
|
|
101
|
+
)
|
|
102
|
+
self._pipe.tokenizer.pad_token_id = self._pipe.model.config.eos_token_id
|
|
103
|
+
self._llm = HuggingFacePipeline(
|
|
104
|
+
model_id=self.model,
|
|
105
|
+
pipeline=self._pipe,
|
|
106
|
+
verbose=True
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def pipe(self, *args, **kwargs):
|
|
110
|
+
return self._pipe(
|
|
111
|
+
*args,
|
|
112
|
+
**kwargs,
|
|
113
|
+
generate_kwargs={"max_new_tokens": self.max_tokens}
|
|
114
|
+
)
|
parrot/llms/vertex.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from navconfig import config, BASE_DIR
|
|
3
|
+
from google.cloud import aiplatform
|
|
4
|
+
from google.oauth2 import service_account
|
|
5
|
+
from vertexai.preview.vision_models import ImageGenerationModel
|
|
6
|
+
from langchain_google_vertexai import (
|
|
7
|
+
ChatVertexAI,
|
|
8
|
+
VertexAI,
|
|
9
|
+
HarmBlockThreshold,
|
|
10
|
+
HarmCategory
|
|
11
|
+
)
|
|
12
|
+
from navconfig.logging import logging
|
|
13
|
+
from .abstract import AbstractLLM
|
|
14
|
+
|
|
15
|
+
logging.getLogger(name='httpcore').setLevel(logging.WARNING)
|
|
16
|
+
logging.getLogger(name='httpx').setLevel(logging.WARNING)
|
|
17
|
+
|
|
18
|
+
safety_settings = {
|
|
19
|
+
HarmCategory.HARM_CATEGORY_UNSPECIFIED: HarmBlockThreshold.BLOCK_NONE,
|
|
20
|
+
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
|
|
21
|
+
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
|
|
22
|
+
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
|
|
23
|
+
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_ONLY_HIGH,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class VertexLLM(AbstractLLM):
|
|
28
|
+
"""VertexLLM.
|
|
29
|
+
|
|
30
|
+
Interact with VertexAI Language Model.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
_type_: VertexAI LLM.
|
|
34
|
+
"""
|
|
35
|
+
model: str = "gemini-1.5-pro"
|
|
36
|
+
max_tokens: int = 8192
|
|
37
|
+
top_k: float = 40
|
|
38
|
+
top_p: float = 0.95
|
|
39
|
+
supported_models: list = [
|
|
40
|
+
"gemini-2.5-pro-exp-03-25",
|
|
41
|
+
"gemini-2.5-pro-preview-03-25",
|
|
42
|
+
"gemini-2.5-flash-preview-04-17",
|
|
43
|
+
"gemini-2.0-flash",
|
|
44
|
+
"gemini-2.0-flash-lite",
|
|
45
|
+
"gemini-2.0-flash-001",
|
|
46
|
+
"gemini-1.5-pro",
|
|
47
|
+
"gemini-1.5-flash-8b",
|
|
48
|
+
"gemini-1.5-pro-exp-0801",
|
|
49
|
+
"gemini-1.5-flash-preview-0514",
|
|
50
|
+
"gemini-1.5-flash-001",
|
|
51
|
+
"chat-bison@001",
|
|
52
|
+
"chat-bison@002",
|
|
53
|
+
"imagen-3.0-generate-002",
|
|
54
|
+
"gemini-2.0-flash-live-001",
|
|
55
|
+
"veo-2.0-generate-001"
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
def __init__(self, *args, use_chat: bool = False, **kwargs):
|
|
59
|
+
super().__init__(*args, **kwargs)
|
|
60
|
+
project_id = config.get("VERTEX_PROJECT_ID")
|
|
61
|
+
region = config.get("VERTEX_REGION")
|
|
62
|
+
config_file = config.get('GOOGLE_CREDENTIALS_FILE', 'env/google/vertexai.json')
|
|
63
|
+
config_dir = BASE_DIR.joinpath(config_file)
|
|
64
|
+
vertex_credentials = service_account.Credentials.from_service_account_file(
|
|
65
|
+
str(config_dir)
|
|
66
|
+
)
|
|
67
|
+
# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = str(config_dir)
|
|
68
|
+
args = {
|
|
69
|
+
"project": project_id,
|
|
70
|
+
"location": region,
|
|
71
|
+
"temperature": self.temperature,
|
|
72
|
+
"max_tokens": self.max_tokens,
|
|
73
|
+
"max_retries": 4,
|
|
74
|
+
"top_p": self.top_p,
|
|
75
|
+
# "top_k": self.top_k,
|
|
76
|
+
"verbose": True,
|
|
77
|
+
"credentials": vertex_credentials,
|
|
78
|
+
# "safety_settings": safety_settings
|
|
79
|
+
}
|
|
80
|
+
if use_chat is True:
|
|
81
|
+
base_llm = ChatVertexAI
|
|
82
|
+
else:
|
|
83
|
+
base_llm = VertexAI
|
|
84
|
+
self._llm = base_llm(
|
|
85
|
+
model_name=self.model,
|
|
86
|
+
**args
|
|
87
|
+
)
|
|
88
|
+
# LLM
|
|
89
|
+
self._version_ = aiplatform.__version__
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
####
|
|
2
|
+
# Copyright 2023 Jesus Lara.
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
#
|
|
5
|
+
# Loaders.
|
|
6
|
+
# Open, extract and load data from different sources.
|
|
7
|
+
#####
|
|
8
|
+
from langchain.docstore.document import Document
|
|
9
|
+
from .abstract import AbstractLoader
|