ai-parrot 0.2.0__cp311-cp311-manylinux_2_28_x86_64.whl → 0.2.2__cp311-cp311-manylinux_2_28_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.2.0.dist-info → ai_parrot-0.2.2.dist-info}/METADATA +1 -1
- {ai_parrot-0.2.0.dist-info → ai_parrot-0.2.2.dist-info}/RECORD +12 -12
- parrot/chatbots/abstract.py +11 -8
- parrot/chatbots/retrievals/__init__.py +104 -42
- parrot/conf.py +1 -1
- parrot/handlers/chat.py +9 -9
- parrot/stores/abstract.py +1 -1
- parrot/stores/milvus.py +38 -8
- parrot/version.py +1 -1
- {ai_parrot-0.2.0.dist-info → ai_parrot-0.2.2.dist-info}/LICENSE +0 -0
- {ai_parrot-0.2.0.dist-info → ai_parrot-0.2.2.dist-info}/WHEEL +0 -0
- {ai_parrot-0.2.0.dist-info → ai_parrot-0.2.2.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ai-parrot
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Live Chatbots based on Langchain chatbots and Agents Integrated into Navigator Framework or used into aiohttp applications.
|
|
5
5
|
Home-page: https://github.com/phenobarbital/ai-parrot
|
|
6
6
|
Author: Jesus Lara
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
parrot/__init__.py,sha256=oBpxNjpQcJpAHWZU6Hi0tBMGTpTaJEKDXHbfAhqZZAQ,333
|
|
2
|
-
parrot/conf.py,sha256=
|
|
2
|
+
parrot/conf.py,sha256=JGCMuB6A_C_z78juMc_-UXCxlHb4rIB_wskSmCubFB0,4128
|
|
3
3
|
parrot/exceptions.cpython-311-x86_64-linux-gnu.so,sha256=p2epCb17B2DCUg3-CZizDQIsIXBhRph07DeJ1Egp8Z0,297896
|
|
4
4
|
parrot/manager.py,sha256=UShLbqfNyPvnGYHzprzQYwu_oj1L-Mhhk2qMRRnsfwo,5187
|
|
5
5
|
parrot/models.py,sha256=GlyWMe2OCgM9dySm2BzK60yKOMHqFth7TYHidTWnioY,12513
|
|
6
6
|
parrot/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
parrot/version.py,sha256
|
|
7
|
+
parrot/version.py,sha256=-soyx6MTab6HIEb_c5TDLZ5-rdqnRO3gWdWhzpWVQj8,373
|
|
8
8
|
parrot/chatbots/__init__.py,sha256=ypskCnME0xUv6psBEGCEyXCrD0J0ULHSllpVmSxqb4A,200
|
|
9
|
-
parrot/chatbots/abstract.py,sha256=
|
|
9
|
+
parrot/chatbots/abstract.py,sha256=axQkULxAoWGzwa8OZdgVo202DYWLBULW8CrHLqrvbYE,33106
|
|
10
10
|
parrot/chatbots/asktroc.py,sha256=gyWzyvpAnmXwXd-3DEKoIJtAxt6NnP5mUZdZbkFky8s,604
|
|
11
11
|
parrot/chatbots/base.py,sha256=fXqCzxeA2dU2wYlOV7jCMF4S9_8ohqGMdUfm2VQTfQQ,8054
|
|
12
12
|
parrot/chatbots/basic.py,sha256=DIMTPoGc90BRSlokeOdnjlEXAAfZlIFqxXWaMyAX9uk,232
|
|
@@ -17,7 +17,7 @@ parrot/chatbots/dataframe.py,sha256=CfZiLKIwnaku52nl2PNjciqRlH8m2lM4buO6xI7P408,
|
|
|
17
17
|
parrot/chatbots/hragents.py,sha256=PyNIBJ2OH5CtfVydccgpY50V6GI3cLKuVdOMaa7sQz0,574
|
|
18
18
|
parrot/chatbots/oddie.py,sha256=RMbANmJZP1_vLVGKRNBKmA8otyAiWPkvpA0rJ0U3tZk,796
|
|
19
19
|
parrot/chatbots/odoo.py,sha256=RMbANmJZP1_vLVGKRNBKmA8otyAiWPkvpA0rJ0U3tZk,796
|
|
20
|
-
parrot/chatbots/retrievals/__init__.py,sha256=
|
|
20
|
+
parrot/chatbots/retrievals/__init__.py,sha256=i6ExSr7k9rysBzMpweBS9gbKSxJDjIikrGCjwzt-Wh0,19575
|
|
21
21
|
parrot/chatbots/retrievals/constitutional.py,sha256=x7kFR0KpmkR0Wz6bXNOeU3Hesn_EXc6eOSd4TdXxb8o,600
|
|
22
22
|
parrot/crew/__init__.py,sha256=oWLEWNNdYHB2AZUDUZVlSsdMOJiWamvM-jVZ8SzoWQE,77
|
|
23
23
|
parrot/crew/tools/__init__.py,sha256=n2nXEVl8VeWmdI_NyGbiVTAq_S51ebNExuyRM7u9SeI,569
|
|
@@ -33,7 +33,7 @@ parrot/crew/tools/search.py,sha256=itWpJD_78IXVtBSKrQIAamCPLbejwmUj1oCBKqBxvO0,1
|
|
|
33
33
|
parrot/crew/tools/url.py,sha256=m5v9XFQPotHRID7NmY-NQVmXtXEJvfly6tFMslL8U_0,682
|
|
34
34
|
parrot/handlers/__init__.py,sha256=WKn2yg4pSi5-IivkQ34uHSfTG7f1nYj4jB8-4wNG2_A,64
|
|
35
35
|
parrot/handlers/bots.py,sha256=GG2W8y_GC71f8_mMHxwAYP-ope7ecNP_GShL9c66_uY,5782
|
|
36
|
-
parrot/handlers/chat.py,sha256=
|
|
36
|
+
parrot/handlers/chat.py,sha256=iqTChdNqcbhCR2meOqLhPx2XQiSiDzzFP8nRAcPH_7s,5437
|
|
37
37
|
parrot/interfaces/__init__.py,sha256=m3FpxsFeEKq_hvQR9YRGAhZS6u8LZZBuzf6-njugiHE,69
|
|
38
38
|
parrot/interfaces/database.py,sha256=PHy133KTqa9K0tALOQt1q0ufwUZ4n7rndZrhob6Wbk4,609
|
|
39
39
|
parrot/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -78,8 +78,8 @@ parrot/loaders/handlers/data.py,sha256=olZ2p-wyUMGoazah7tgHY7V9buGX1FOeJ-cv2vGEo
|
|
|
78
78
|
parrot/loaders/utils/__init__.py,sha256=SkDyK3MuPGhp0NM6kHvaxQDe97Gcl3n9t5A741OVh1c,28
|
|
79
79
|
parrot/loaders/utils/models.py,sha256=BHcnFzS7oOKUGG-vPy_TlqeFNAC8puRgsIMX2mSgKxY,1059
|
|
80
80
|
parrot/stores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
81
|
-
parrot/stores/abstract.py,sha256=
|
|
82
|
-
parrot/stores/milvus.py,sha256=
|
|
81
|
+
parrot/stores/abstract.py,sha256=hbRI6wJGCShMlfDc0UkQx7gD9r3LJrBpif6tAKXeDAE,5106
|
|
82
|
+
parrot/stores/milvus.py,sha256=s6BeFDxot9njxUkdB_pPZRjmrgZYa_xuNm--TlG_PjI,18930
|
|
83
83
|
parrot/stores/qdrant.py,sha256=y-jG5sB6ICESyxdpyGBhQ-hgTDLxxPtM5xYZTWIRiAY,4720
|
|
84
84
|
parrot/tools/__init__.py,sha256=lIPK9acoJE2wmxmfbFIQl6dEpUcsBAkapLWvnP_RWG0,669
|
|
85
85
|
parrot/tools/abstract.py,sha256=pVSZw8MDpbVcQ-CHaGwP6CpqXHIs8hH8Oy1AqUuMmrw,1706
|
|
@@ -102,8 +102,8 @@ resources/users/handlers.py,sha256=BGzqBvPY_OaIF_nONWX4b_B5OyyBrdGuSihIsdlFwjk,2
|
|
|
102
102
|
resources/users/models.py,sha256=glk7Emv7QCi6i32xRFDrGc8UwK23_LPg0XUOJoHnwRU,6799
|
|
103
103
|
settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
104
104
|
settings/settings.py,sha256=9ueEvyLNurUX-AaIeRPV8GKX1c4YjDLbksUAeqEq6Ck,1854
|
|
105
|
-
ai_parrot-0.2.
|
|
106
|
-
ai_parrot-0.2.
|
|
107
|
-
ai_parrot-0.2.
|
|
108
|
-
ai_parrot-0.2.
|
|
109
|
-
ai_parrot-0.2.
|
|
105
|
+
ai_parrot-0.2.2.dist-info/LICENSE,sha256=vRKOoa7onTsLNvSzJtGtMaNhWWh8B3YAT733Tlu6M4o,1070
|
|
106
|
+
ai_parrot-0.2.2.dist-info/METADATA,sha256=HQMbR7U-zS_IJUSlQwbU7zkDRgHIkFl3NQjYPQ8YaK8,9336
|
|
107
|
+
ai_parrot-0.2.2.dist-info/WHEEL,sha256=czZm5XKxt3lM6KcAi6fwGhndrA0uZKYAkkvqX1vZAww,113
|
|
108
|
+
ai_parrot-0.2.2.dist-info/top_level.txt,sha256=qHoO4BhYDfeTkyKnciZSQtn5FSLN3Q-P5xCTkyvbuxg,26
|
|
109
|
+
ai_parrot-0.2.2.dist-info/RECORD,,
|
parrot/chatbots/abstract.py
CHANGED
|
@@ -125,7 +125,8 @@ from ..conf import (
|
|
|
125
125
|
MAX_VRAM_AVAILABLE,
|
|
126
126
|
RAM_AVAILABLE,
|
|
127
127
|
default_dsn,
|
|
128
|
-
REDIS_HISTORY_URL
|
|
128
|
+
REDIS_HISTORY_URL,
|
|
129
|
+
EMBEDDING_DEFAULT_MODEL
|
|
129
130
|
)
|
|
130
131
|
from ..interfaces import DBInterface
|
|
131
132
|
from ..models import ChatbotModel
|
|
@@ -146,16 +147,17 @@ class AbstractChatbot(ABC, DBInterface):
|
|
|
146
147
|
"You are {name}, an expert AI assistant and {role} Working at {company}.\n\n"
|
|
147
148
|
"Your primary function is to {goal}\n"
|
|
148
149
|
"Use the provided context of the documents you have processed or extracted from other provided tools or sources to provide informative, detailed and accurate responses.\n"
|
|
149
|
-
"I am here to help with {role}
|
|
150
|
+
"I am here to help with {role}.\n"
|
|
151
|
+
"**Backstory:**\n"
|
|
152
|
+
"{backstory}.\n\n"
|
|
150
153
|
"Focus on answering the question directly but detailed. Do not include an introduction or greeting in your response.\n\n"
|
|
151
154
|
"{company_information}\n\n"
|
|
155
|
+
"Here is a brief summary of relevant information:\n"
|
|
152
156
|
"Context: {context}\n\n"
|
|
153
157
|
"Given this information, please provide answers to the following question adding detailed and useful insights:\n\n"
|
|
154
|
-
"Chat History
|
|
155
|
-
"Human
|
|
156
|
-
"
|
|
157
|
-
"{summaries}\n\n"
|
|
158
|
-
"Assistant Answer:\n"
|
|
158
|
+
"**Chat History:** {chat_history}\n\n"
|
|
159
|
+
"**Human Question:** {question}\n"
|
|
160
|
+
"Assistant Answer:\n\n"
|
|
159
161
|
"{rationale}\n"
|
|
160
162
|
"You are a fluent speaker, you can talk and respond fluently in English and Spanish, and you must answer in the same language as the user's question. If the user's language is not English, you should translate your response into their language.\n"
|
|
161
163
|
)
|
|
@@ -536,7 +538,7 @@ class AbstractChatbot(ABC, DBInterface):
|
|
|
536
538
|
models = file_config.get('models', {})
|
|
537
539
|
if not self.embedding_model_name:
|
|
538
540
|
self.embedding_model_name = models.get(
|
|
539
|
-
'
|
|
541
|
+
'embedding', EMBEDDING_DEFAULT_MODEL
|
|
540
542
|
)
|
|
541
543
|
if not self.tokenizer_model_name:
|
|
542
544
|
self.tokenizer_model_name = models.get('tokenizer')
|
|
@@ -626,6 +628,7 @@ class AbstractChatbot(ABC, DBInterface):
|
|
|
626
628
|
if MILVUS_ENABLED is True:
|
|
627
629
|
self._store = MilvusStore(
|
|
628
630
|
embeddings=embed,
|
|
631
|
+
embedding_name=self.embedding_model_name,
|
|
629
632
|
use_bge=self.use_bge,
|
|
630
633
|
use_fastembed=self.use_fastembed,
|
|
631
634
|
**config
|
|
@@ -108,12 +108,14 @@ class RetrievalManager:
|
|
|
108
108
|
def create_memory(
|
|
109
109
|
self,
|
|
110
110
|
key: str = 'chat_history',
|
|
111
|
-
input_key: str = 'question'
|
|
111
|
+
input_key: str = 'question',
|
|
112
|
+
output_key: str = 'answer'
|
|
112
113
|
):
|
|
113
114
|
return ConversationBufferMemory(
|
|
114
115
|
memory_key=key,
|
|
115
116
|
return_messages=True,
|
|
116
|
-
input_key=input_key
|
|
117
|
+
input_key=input_key,
|
|
118
|
+
output_key=output_key
|
|
117
119
|
)
|
|
118
120
|
|
|
119
121
|
### Different types of Retrieval
|
|
@@ -122,7 +124,7 @@ class RetrievalManager:
|
|
|
122
124
|
question: str = None,
|
|
123
125
|
chain_type: str = 'stuff',
|
|
124
126
|
search_type: str = 'similarity',
|
|
125
|
-
search_kwargs: dict = {"k":
|
|
127
|
+
search_kwargs: dict = {"k": 4, "fetch_k": 10, "lambda_mult": 0.89},
|
|
126
128
|
return_docs: bool = True,
|
|
127
129
|
metric_type: str = None,
|
|
128
130
|
memory: Any = None,
|
|
@@ -137,18 +139,27 @@ class RetrievalManager:
|
|
|
137
139
|
vector = self.store.get_vector(
|
|
138
140
|
metric_type=metric_type
|
|
139
141
|
)
|
|
140
|
-
|
|
142
|
+
simil_retriever = VectorStoreRetriever(
|
|
141
143
|
vectorstore=vector,
|
|
142
|
-
search_type=
|
|
144
|
+
search_type='similarity',
|
|
143
145
|
chain_type=chain_type,
|
|
144
146
|
search_kwargs=search_kwargs
|
|
145
147
|
)
|
|
148
|
+
retriever = vector.as_retriever(
|
|
149
|
+
search_type=search_type,
|
|
150
|
+
search_kwargs=search_kwargs
|
|
151
|
+
)
|
|
146
152
|
if self.kb:
|
|
147
153
|
# Get a BM25 Retriever:
|
|
148
154
|
b25_retriever = BM25Retriever.from_documents(self.kb)
|
|
149
155
|
retriever = EnsembleRetriever(
|
|
150
|
-
retrievers=[retriever, b25_retriever],
|
|
151
|
-
weights=[0.
|
|
156
|
+
retrievers=[simil_retriever, retriever, b25_retriever],
|
|
157
|
+
weights=[0.6, 0.3, 0.1]
|
|
158
|
+
)
|
|
159
|
+
else:
|
|
160
|
+
retriever = EnsembleRetriever(
|
|
161
|
+
retrievers=[simil_retriever, retriever],
|
|
162
|
+
weights=[0.7, 0.3]
|
|
152
163
|
)
|
|
153
164
|
custom_template = self.template.format_map(
|
|
154
165
|
SafeDict(
|
|
@@ -209,7 +220,7 @@ class RetrievalManager:
|
|
|
209
220
|
question: str = None,
|
|
210
221
|
chain_type: str = 'stuff',
|
|
211
222
|
search_type: str = 'mmr',
|
|
212
|
-
search_kwargs: dict = {"k":
|
|
223
|
+
search_kwargs: dict = {"k": 4, "fetch_k": 10, "lambda_mult": 0.89},
|
|
213
224
|
return_docs: bool = True,
|
|
214
225
|
metric_type: str = None,
|
|
215
226
|
use_llm: str = None
|
|
@@ -235,14 +246,14 @@ class RetrievalManager:
|
|
|
235
246
|
b25_retriever = BM25Retriever.from_documents(self.kb)
|
|
236
247
|
retriever = EnsembleRetriever(
|
|
237
248
|
retrievers=[simil_retriever, retriever, b25_retriever],
|
|
238
|
-
weights=[0.
|
|
249
|
+
weights=[0.6, 0.3, 0.1]
|
|
239
250
|
)
|
|
240
251
|
else:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
retriever = simil_retriever
|
|
252
|
+
retriever = EnsembleRetriever(
|
|
253
|
+
retrievers=[simil_retriever, retriever],
|
|
254
|
+
weights=[0.7, 0.3]
|
|
255
|
+
)
|
|
256
|
+
# retriever = simil_retriever
|
|
246
257
|
custom_template = self.template.format_map(
|
|
247
258
|
SafeDict(
|
|
248
259
|
chat_history=''
|
|
@@ -284,13 +295,15 @@ class RetrievalManager:
|
|
|
284
295
|
chain_type=chain_type,
|
|
285
296
|
retriever=retriever,
|
|
286
297
|
return_source_documents=return_docs,
|
|
298
|
+
verbose=True,
|
|
287
299
|
chain_type_kwargs={
|
|
288
300
|
"prompt": PromptTemplate(
|
|
289
301
|
template=custom_template,
|
|
290
|
-
input_variables=['
|
|
302
|
+
input_variables=['context', 'question']
|
|
291
303
|
)
|
|
292
304
|
},
|
|
293
305
|
)
|
|
306
|
+
# Debug Code ::
|
|
294
307
|
# print('=====================')
|
|
295
308
|
# print(custom_template)
|
|
296
309
|
# response = self.chain.invoke(question)
|
|
@@ -311,6 +324,7 @@ class RetrievalManager:
|
|
|
311
324
|
# distance = 'EMPTY'
|
|
312
325
|
# print('DISTANCE > ', distance)
|
|
313
326
|
# print('CHAIN > ', self.chain)
|
|
327
|
+
|
|
314
328
|
return self
|
|
315
329
|
|
|
316
330
|
def get_current_context(self):
|
|
@@ -328,7 +342,7 @@ class RetrievalManager:
|
|
|
328
342
|
count = 0
|
|
329
343
|
d = {}
|
|
330
344
|
for source in source_documents:
|
|
331
|
-
if count >=
|
|
345
|
+
if count >= 20:
|
|
332
346
|
break # Exit loop after processing 10 documents
|
|
333
347
|
metadata = source.metadata
|
|
334
348
|
if 'url' in metadata:
|
|
@@ -433,42 +447,91 @@ class RetrievalManager:
|
|
|
433
447
|
)
|
|
434
448
|
|
|
435
449
|
|
|
436
|
-
def question(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
450
|
+
async def question(
|
|
451
|
+
self,
|
|
452
|
+
question: str = None,
|
|
453
|
+
chain_type: str = 'stuff',
|
|
454
|
+
search_type: str = 'similarity',
|
|
455
|
+
search_kwargs: dict = {"k": 4, "fetch_k": 10, "lambda_mult": 0.89},
|
|
456
|
+
return_docs: bool = True,
|
|
457
|
+
metric_type: str = None,
|
|
458
|
+
memory: Any = None,
|
|
459
|
+
**kwargs
|
|
460
|
+
):
|
|
461
|
+
# Generating Vector:
|
|
462
|
+
async with self.store as store: #pylint: disable=E1101
|
|
463
|
+
vector = store.get_vector(metric_type=metric_type)
|
|
464
|
+
retriever = VectorStoreRetriever(
|
|
465
|
+
vectorstore=vector,
|
|
466
|
+
search_type=search_type,
|
|
467
|
+
chain_type=chain_type,
|
|
468
|
+
search_kwargs=search_kwargs
|
|
448
469
|
)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
self.logger.error(
|
|
454
|
-
f"Error validating response: {exc}"
|
|
470
|
+
custom_template = self.template.format_map(
|
|
471
|
+
SafeDict(
|
|
472
|
+
summaries=''
|
|
473
|
+
)
|
|
455
474
|
)
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
f"Error on response: {exc.payload}"
|
|
475
|
+
_prompt = PromptTemplate(
|
|
476
|
+
template=custom_template,
|
|
477
|
+
input_variables=["context", "chat_history", "question"],
|
|
460
478
|
)
|
|
461
|
-
|
|
479
|
+
try:
|
|
480
|
+
chain = ConversationalRetrievalChain.from_llm(
|
|
481
|
+
llm=self.model,
|
|
482
|
+
retriever=retriever,
|
|
483
|
+
chain_type=chain_type,
|
|
484
|
+
verbose=False,
|
|
485
|
+
memory=memory,
|
|
486
|
+
return_source_documents=return_docs,
|
|
487
|
+
return_generated_question=True,
|
|
488
|
+
combine_docs_chain_kwargs={"prompt": _prompt},
|
|
489
|
+
**kwargs
|
|
490
|
+
)
|
|
491
|
+
response = chain.invoke(
|
|
492
|
+
question
|
|
493
|
+
)
|
|
494
|
+
except Exception as exc:
|
|
495
|
+
self.logger.error(
|
|
496
|
+
f"Error invoking chain: {exc}"
|
|
497
|
+
)
|
|
498
|
+
return None, None
|
|
499
|
+
try:
|
|
500
|
+
qa_response = ChatResponse(**response)
|
|
501
|
+
except (ValueError, TypeError) as exc:
|
|
502
|
+
self.logger.error(
|
|
503
|
+
f"Error validating response: {exc}"
|
|
504
|
+
)
|
|
505
|
+
return None, None
|
|
506
|
+
except ValidationError as exc:
|
|
507
|
+
self.logger.error(
|
|
508
|
+
f"Error on response: {exc.payload}"
|
|
509
|
+
)
|
|
510
|
+
return None, None
|
|
462
511
|
try:
|
|
463
|
-
|
|
512
|
+
qa_response.response = self.as_markdown(
|
|
464
513
|
qa_response
|
|
465
|
-
)
|
|
514
|
+
)
|
|
515
|
+
# # saving question to Usage Log
|
|
516
|
+
# if self.request:
|
|
517
|
+
# tasker = self.request.app['service_queue']
|
|
518
|
+
# await tasker.put(
|
|
519
|
+
# self.log_usage,
|
|
520
|
+
# response=qa_response,
|
|
521
|
+
# request=self.request
|
|
522
|
+
# )
|
|
523
|
+
# else:
|
|
524
|
+
# asyncio.create_task(
|
|
525
|
+
# self.log_usage(response=qa_response)
|
|
526
|
+
# )
|
|
527
|
+
return qa_response
|
|
466
528
|
except Exception as exc:
|
|
467
529
|
self.logger.exception(
|
|
468
530
|
f"Error on response: {exc}"
|
|
469
531
|
)
|
|
470
532
|
return None, None
|
|
471
533
|
|
|
534
|
+
|
|
472
535
|
async def invoke(self, question):
|
|
473
536
|
# Invoke the chain with the given question
|
|
474
537
|
try:
|
|
@@ -481,7 +544,6 @@ class RetrievalManager:
|
|
|
481
544
|
)
|
|
482
545
|
return None, None
|
|
483
546
|
try:
|
|
484
|
-
print('RESPONSE > ', response)
|
|
485
547
|
qa_response = ChatResponse(**response)
|
|
486
548
|
except (ValueError, TypeError) as exc:
|
|
487
549
|
self.logger.error(
|
parrot/conf.py
CHANGED
|
@@ -85,7 +85,7 @@ QDRANT_CONN_TYPE = config.get('QDRANT_CONN_TYPE', fallback='server')
|
|
|
85
85
|
EMBEDDING_DEVICE = config.get('EMBEDDING_DEVICE', fallback='cpu')
|
|
86
86
|
EMBEDDING_DEFAULT_MODEL = config.get(
|
|
87
87
|
'EMBEDDING_DEFAULT_MODEL',
|
|
88
|
-
fallback='
|
|
88
|
+
fallback='thenlper/gte-base'
|
|
89
89
|
)
|
|
90
90
|
MAX_VRAM_AVAILABLE = config.get('MAX_VRAM_AVAILABLE', fallback=20000)
|
|
91
91
|
RAM_AVAILABLE = config.get('RAM_AVAILABLE', fallback=819200)
|
parrot/handlers/chat.py
CHANGED
|
@@ -48,7 +48,6 @@ class ChatHandler(BaseView):
|
|
|
48
48
|
post.
|
|
49
49
|
description: Post method for ChatHandler.
|
|
50
50
|
"""
|
|
51
|
-
print('ARGS > ', args, kwargs)
|
|
52
51
|
app = self.request.app
|
|
53
52
|
name = self.request.match_info.get('chatbot_name', None)
|
|
54
53
|
qs = self.query_parameters(self.request)
|
|
@@ -92,19 +91,20 @@ class ChatHandler(BaseView):
|
|
|
92
91
|
session = self.request.session
|
|
93
92
|
try:
|
|
94
93
|
session_id = session.get('session_id', None)
|
|
95
|
-
# print('SESSION ID > ', session_id)
|
|
96
94
|
memory_key = f'{session.session_id}_{name}_message_store'
|
|
97
|
-
# print('MEM STORAGE > ', memory_key)
|
|
98
95
|
memory = chatbot.get_memory(session_id=memory_key)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
qa = retrieval.conversation(
|
|
96
|
+
with chatbot.get_retrieval(request=self.request) as retrieval:
|
|
97
|
+
result = await retrieval.question(
|
|
102
98
|
question=question,
|
|
103
|
-
search_kwargs={"k": 10},
|
|
104
|
-
use_llm=llm,
|
|
105
99
|
memory=memory
|
|
106
100
|
)
|
|
107
|
-
|
|
101
|
+
# qa = retrieval.qa(
|
|
102
|
+
# question=question,
|
|
103
|
+
# search_kwargs={"k": 10},
|
|
104
|
+
# use_llm=llm,
|
|
105
|
+
# # memory=memory
|
|
106
|
+
# )
|
|
107
|
+
# result = await qa.invoke(question)
|
|
108
108
|
# Drop "memory" information:
|
|
109
109
|
result.chat_history = None
|
|
110
110
|
result.source_documents = None
|
parrot/stores/abstract.py
CHANGED
|
@@ -32,7 +32,7 @@ class AbstractStore(ABC):
|
|
|
32
32
|
self._connected: bool = False
|
|
33
33
|
self.use_bge: bool = kwargs.pop("use_bge", False)
|
|
34
34
|
self.fastembed: bool = kwargs.pop("use_fastembed", False)
|
|
35
|
-
self.embedding_name: str = EMBEDDING_DEFAULT_MODEL
|
|
35
|
+
self.embedding_name: str = kwargs.pop('embedding_name', EMBEDDING_DEFAULT_MODEL)
|
|
36
36
|
self.dimension: int = kwargs.pop("dimension", 768)
|
|
37
37
|
self._metric_type: str = kwargs.pop("metric_type", 'COSINE')
|
|
38
38
|
self._index_type: str = kwargs.pop("index_type", 'IVF_FLAT')
|
parrot/stores/milvus.py
CHANGED
|
@@ -106,7 +106,30 @@ class MilvusStore(AbstractStore):
|
|
|
106
106
|
self.kwargs['db_name'] = self.database
|
|
107
107
|
self.use_database(self.database, create=True)
|
|
108
108
|
|
|
109
|
-
def
|
|
109
|
+
async def __aenter__(self):
|
|
110
|
+
try:
|
|
111
|
+
self.tensor = torch.randn(1000, 1000).cuda()
|
|
112
|
+
except RuntimeError:
|
|
113
|
+
self.tensor = None
|
|
114
|
+
if self._embed_ is None:
|
|
115
|
+
self._embed_ = self.create_embedding(
|
|
116
|
+
model_name=self.embedding_name
|
|
117
|
+
)
|
|
118
|
+
self._client_id = str(uuid.uuid4())
|
|
119
|
+
self._client, self.client_id = self.connect(client_id=self._client_id)
|
|
120
|
+
return self
|
|
121
|
+
|
|
122
|
+
async def __aexit__(self, exc_type, exc_value, traceback):
|
|
123
|
+
# closing Embedding
|
|
124
|
+
self._embed_ = None
|
|
125
|
+
del self.tensor
|
|
126
|
+
try:
|
|
127
|
+
self.close(client_id=self.client_id)
|
|
128
|
+
torch.cuda.empty_cache()
|
|
129
|
+
except RuntimeError:
|
|
130
|
+
pass
|
|
131
|
+
|
|
132
|
+
def connect(self, client_id: str = None) -> tuple:
|
|
110
133
|
# 1. Set up a pyMilvus default connection
|
|
111
134
|
# Unique connection:
|
|
112
135
|
if not client_id:
|
|
@@ -118,6 +141,7 @@ class MilvusStore(AbstractStore):
|
|
|
118
141
|
self._client = MilvusClient(
|
|
119
142
|
**self.kwargs
|
|
120
143
|
)
|
|
144
|
+
print('CONN > ', self._client, client_id, connections)
|
|
121
145
|
self._connected = True
|
|
122
146
|
return self._client, client_id
|
|
123
147
|
|
|
@@ -133,7 +157,6 @@ class MilvusStore(AbstractStore):
|
|
|
133
157
|
"port": self.port,
|
|
134
158
|
**kwargs
|
|
135
159
|
}
|
|
136
|
-
print('ARGS >', args)
|
|
137
160
|
try:
|
|
138
161
|
conn = connections.connect(**args)
|
|
139
162
|
db.create_database(db_name)
|
|
@@ -452,8 +475,9 @@ class MilvusStore(AbstractStore):
|
|
|
452
475
|
self,
|
|
453
476
|
collection: str = None,
|
|
454
477
|
metric_type: str = None,
|
|
455
|
-
nprobe: int =
|
|
456
|
-
metadata_field: str = None
|
|
478
|
+
nprobe: int = 32,
|
|
479
|
+
metadata_field: str = None,
|
|
480
|
+
consistency_level: str = 'session'
|
|
457
481
|
) -> Milvus:
|
|
458
482
|
if not metric_type:
|
|
459
483
|
metric_type = self._metric_type
|
|
@@ -462,7 +486,7 @@ class MilvusStore(AbstractStore):
|
|
|
462
486
|
_search = {
|
|
463
487
|
"search_params": {
|
|
464
488
|
"metric_type": metric_type,
|
|
465
|
-
"params": {"nprobe": nprobe},
|
|
489
|
+
"params": {"nprobe": nprobe, "nlist": 1024},
|
|
466
490
|
}
|
|
467
491
|
}
|
|
468
492
|
if metadata_field:
|
|
@@ -474,7 +498,7 @@ class MilvusStore(AbstractStore):
|
|
|
474
498
|
return Milvus(
|
|
475
499
|
embedding_function=_embed_,
|
|
476
500
|
collection_name=collection,
|
|
477
|
-
consistency_level=
|
|
501
|
+
consistency_level=consistency_level,
|
|
478
502
|
connection_args={
|
|
479
503
|
**self.kwargs
|
|
480
504
|
},
|
|
@@ -484,7 +508,13 @@ class MilvusStore(AbstractStore):
|
|
|
484
508
|
**_search
|
|
485
509
|
)
|
|
486
510
|
|
|
487
|
-
def similarity_search(
|
|
511
|
+
def similarity_search(
|
|
512
|
+
self,
|
|
513
|
+
query: str,
|
|
514
|
+
collection: str = None,
|
|
515
|
+
limit: int = 2,
|
|
516
|
+
consistency_level: str = 'Bounded'
|
|
517
|
+
) -> list:
|
|
488
518
|
if collection is None:
|
|
489
519
|
collection = self.collection
|
|
490
520
|
if self._embed_ is None:
|
|
@@ -496,7 +526,7 @@ class MilvusStore(AbstractStore):
|
|
|
496
526
|
vector_db = Milvus(
|
|
497
527
|
embedding_function=_embed_,
|
|
498
528
|
collection_name=collection,
|
|
499
|
-
consistency_level=
|
|
529
|
+
consistency_level=consistency_level,
|
|
500
530
|
connection_args={
|
|
501
531
|
**self.kwargs
|
|
502
532
|
},
|
parrot/version.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
__title__ = "ai-parrot"
|
|
4
4
|
__description__ = "Live Chatbots based on Langchain chatbots and Agents \
|
|
5
5
|
Integrated into Navigator Framework or used into aiohttp applications."
|
|
6
|
-
__version__ = "0.2.
|
|
6
|
+
__version__ = "0.2.2"
|
|
7
7
|
__author__ = "Jesus Lara"
|
|
8
8
|
__author_email__ = "jesuslarag@gmail.com"
|
|
9
9
|
__license__ = "MIT"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|