ai-parrot 0.1.0__cp311-cp311-manylinux_2_28_x86_64.whl → 0.2.1__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ai-parrot
3
- Version: 0.1.0
3
+ Version: 0.2.1
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=6kiE38EgnPxtjJc1dde6QCacXZOByne7mWHI8_7_M-E,4150
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=JhX3p58JOZ_NOGA2KeSy5_F1V-BPCf-j5PB_1iDw7yc,373
8
- parrot/chatbots/__init__.py,sha256=nsu6UPfb6ATv7U9IEHSe2HoGOE9LKLhiFm9gXWjjbMI,201
9
- parrot/chatbots/abstract.py,sha256=sm4zzapNG_CF_uZrYp91GHMo2SJrOgChX1L-7DHceOo,32968
7
+ parrot/version.py,sha256=ySJiD_gpM6lKn3IqSBYrc1kqg43oubJCIQHgj6rU0Z8,373
8
+ parrot/chatbots/__init__.py,sha256=ypskCnME0xUv6psBEGCEyXCrD0J0ULHSllpVmSxqb4A,200
9
+ parrot/chatbots/abstract.py,sha256=sQsvcBmAnN9QRa2Ls-P72GOJixEoe5Pf6d4K8orM9d8,33278
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
@@ -16,7 +16,8 @@ parrot/chatbots/copilot.py,sha256=lnlqVXzk4orm-f3qU5iRswwW7WRMV_BISUqw2o0Krzo,47
16
16
  parrot/chatbots/dataframe.py,sha256=CfZiLKIwnaku52nl2PNjciqRlH8m2lM4buO6xI7P408,3914
17
17
  parrot/chatbots/hragents.py,sha256=PyNIBJ2OH5CtfVydccgpY50V6GI3cLKuVdOMaa7sQz0,574
18
18
  parrot/chatbots/oddie.py,sha256=RMbANmJZP1_vLVGKRNBKmA8otyAiWPkvpA0rJ0U3tZk,796
19
- parrot/chatbots/retrievals/__init__.py,sha256=GOidRGK4O6d0msMC0czIVoscyRvC6YkR8qJGvqqCJec,17404
19
+ parrot/chatbots/odoo.py,sha256=RMbANmJZP1_vLVGKRNBKmA8otyAiWPkvpA0rJ0U3tZk,796
20
+ parrot/chatbots/retrievals/__init__.py,sha256=MfcCFvD4Z5mon7R9ZxGtbAONm36rsRRmYv-C_iwoGe8,19802
20
21
  parrot/chatbots/retrievals/constitutional.py,sha256=x7kFR0KpmkR0Wz6bXNOeU3Hesn_EXc6eOSd4TdXxb8o,600
21
22
  parrot/crew/__init__.py,sha256=oWLEWNNdYHB2AZUDUZVlSsdMOJiWamvM-jVZ8SzoWQE,77
22
23
  parrot/crew/tools/__init__.py,sha256=n2nXEVl8VeWmdI_NyGbiVTAq_S51ebNExuyRM7u9SeI,569
@@ -32,7 +33,7 @@ parrot/crew/tools/search.py,sha256=itWpJD_78IXVtBSKrQIAamCPLbejwmUj1oCBKqBxvO0,1
32
33
  parrot/crew/tools/url.py,sha256=m5v9XFQPotHRID7NmY-NQVmXtXEJvfly6tFMslL8U_0,682
33
34
  parrot/handlers/__init__.py,sha256=WKn2yg4pSi5-IivkQ34uHSfTG7f1nYj4jB8-4wNG2_A,64
34
35
  parrot/handlers/bots.py,sha256=GG2W8y_GC71f8_mMHxwAYP-ope7ecNP_GShL9c66_uY,5782
35
- parrot/handlers/chat.py,sha256=zgb-vW1SeUCHSwi_ov2m6pepvMvLhy-i8lmSTRtOzY0,5475
36
+ parrot/handlers/chat.py,sha256=iqTChdNqcbhCR2meOqLhPx2XQiSiDzzFP8nRAcPH_7s,5437
36
37
  parrot/interfaces/__init__.py,sha256=m3FpxsFeEKq_hvQR9YRGAhZS6u8LZZBuzf6-njugiHE,69
37
38
  parrot/interfaces/database.py,sha256=PHy133KTqa9K0tALOQt1q0ufwUZ4n7rndZrhob6Wbk4,609
38
39
  parrot/llms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -77,8 +78,8 @@ parrot/loaders/handlers/data.py,sha256=olZ2p-wyUMGoazah7tgHY7V9buGX1FOeJ-cv2vGEo
77
78
  parrot/loaders/utils/__init__.py,sha256=SkDyK3MuPGhp0NM6kHvaxQDe97Gcl3n9t5A741OVh1c,28
78
79
  parrot/loaders/utils/models.py,sha256=BHcnFzS7oOKUGG-vPy_TlqeFNAC8puRgsIMX2mSgKxY,1059
79
80
  parrot/stores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
80
- parrot/stores/abstract.py,sha256=LdI7taO_gC7YIzFaKlHXY6Kfbd-dpksYCJBYhyd3kLs,5076
81
- parrot/stores/milvus.py,sha256=V9VkejSNQxhGS4ByiHIJKtKx_QSHdb1j_rBKuLm8oY0,17993
81
+ parrot/stores/abstract.py,sha256=hbRI6wJGCShMlfDc0UkQx7gD9r3LJrBpif6tAKXeDAE,5106
82
+ parrot/stores/milvus.py,sha256=s6BeFDxot9njxUkdB_pPZRjmrgZYa_xuNm--TlG_PjI,18930
82
83
  parrot/stores/qdrant.py,sha256=y-jG5sB6ICESyxdpyGBhQ-hgTDLxxPtM5xYZTWIRiAY,4720
83
84
  parrot/tools/__init__.py,sha256=lIPK9acoJE2wmxmfbFIQl6dEpUcsBAkapLWvnP_RWG0,669
84
85
  parrot/tools/abstract.py,sha256=pVSZw8MDpbVcQ-CHaGwP6CpqXHIs8hH8Oy1AqUuMmrw,1706
@@ -101,8 +102,8 @@ resources/users/handlers.py,sha256=BGzqBvPY_OaIF_nONWX4b_B5OyyBrdGuSihIsdlFwjk,2
101
102
  resources/users/models.py,sha256=glk7Emv7QCi6i32xRFDrGc8UwK23_LPg0XUOJoHnwRU,6799
102
103
  settings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
103
104
  settings/settings.py,sha256=9ueEvyLNurUX-AaIeRPV8GKX1c4YjDLbksUAeqEq6Ck,1854
104
- ai_parrot-0.1.0.dist-info/LICENSE,sha256=vRKOoa7onTsLNvSzJtGtMaNhWWh8B3YAT733Tlu6M4o,1070
105
- ai_parrot-0.1.0.dist-info/METADATA,sha256=fwcnN1ALMLoPQXvSMDnjAPZ7xIFa2bMeJMgQeEYMZmk,9336
106
- ai_parrot-0.1.0.dist-info/WHEEL,sha256=czZm5XKxt3lM6KcAi6fwGhndrA0uZKYAkkvqX1vZAww,113
107
- ai_parrot-0.1.0.dist-info/top_level.txt,sha256=qHoO4BhYDfeTkyKnciZSQtn5FSLN3Q-P5xCTkyvbuxg,26
108
- ai_parrot-0.1.0.dist-info/RECORD,,
105
+ ai_parrot-0.2.1.dist-info/LICENSE,sha256=vRKOoa7onTsLNvSzJtGtMaNhWWh8B3YAT733Tlu6M4o,1070
106
+ ai_parrot-0.2.1.dist-info/METADATA,sha256=d1pyf6EdFGj4pmmk1wZFIFYKI6roPFZpgpSpf5f2_xw,9336
107
+ ai_parrot-0.2.1.dist-info/WHEEL,sha256=czZm5XKxt3lM6KcAi6fwGhndrA0uZKYAkkvqX1vZAww,113
108
+ ai_parrot-0.2.1.dist-info/top_level.txt,sha256=qHoO4BhYDfeTkyKnciZSQtn5FSLN3Q-P5xCTkyvbuxg,26
109
+ ai_parrot-0.2.1.dist-info/RECORD,,
@@ -3,5 +3,5 @@ from .basic import Chatbot
3
3
  from .asktroc import AskTROC
4
4
  from .hragents import HRAgent
5
5
  from .bose import BoseBot
6
- from .oddie import OddieBot
6
+ from .odoo import OddieBot
7
7
  from .cody import Cody
@@ -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}, {backstory}.\n\n"
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: {chat_history}\n"
155
- "Human: {question}\n"
156
- "Here is a brief summary of relevant information:\n"
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
- 'embedding_name', None,
541
+ 'embedding', EMBEDDING_DEFAULT_MODEL
540
542
  )
541
543
  if not self.tokenizer_model_name:
542
544
  self.tokenizer_model_name = models.get('tokenizer')
@@ -624,8 +626,12 @@ class AbstractChatbot(ABC, DBInterface):
624
626
  )
625
627
  elif vector_db == 'MilvusStore':
626
628
  if MILVUS_ENABLED is True:
629
+ print('EMBEDDINGS > ', self.embeddings)
630
+ print('AQUI MILVUS >> ', embed)
631
+ print('AQUI MILVUS >> ', self.embedding_model_name)
627
632
  self._store = MilvusStore(
628
633
  embeddings=embed,
634
+ embedding_name=self.embedding_model_name,
629
635
  use_bge=self.use_bge,
630
636
  use_fastembed=self.use_fastembed,
631
637
  **config
@@ -0,0 +1,17 @@
1
+ from .basic import Chatbot
2
+
3
+
4
+ class OddieBot(Chatbot):
5
+ """Represents an agent in Navigator.
6
+
7
+ Each agent has a name, a role, a goal, a backstory,
8
+ and an optional language model (llm).
9
+ """
10
+ name: str = 'Oddie'
11
+ company: str = 'T-ROC Global'
12
+ company_website: str = 'https://www.trocglobal.com'
13
+ contact_information = 'communications@trocglobal.com'
14
+ contact_form = 'https://www.surveymonkey.com/r/TROC_Suggestion_Box'
15
+ role = "Odoo and ERP Specialist and Odoo Programmer"
16
+ goal = "To provide information and support on Odoo and ERP systems, help with troubleshooting, and answer any questions you may have about any Odoo and ERP systems implementation."
17
+ specialty_area = 'Bring useful information about Odoo ERP, documentation, usage, samples, etc.'
@@ -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": 10, "fetch_k": 30, "lambda_mult": 0.86},
127
+ search_kwargs: dict = {"k": 5, "fetch_k": 20, "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
- retriever = VectorStoreRetriever(
142
+ simil_retriever = VectorStoreRetriever(
141
143
  vectorstore=vector,
142
- search_type=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.9, 0.1]
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": 10, "fetch_k": 20, "lambda_mult": 0.86},
223
+ search_kwargs: dict = {"k": 5, "fetch_k": 40, "lambda_mult": 0.85},
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.3, 0.6, 0.1]
249
+ weights=[0.6, 0.3, 0.1]
239
250
  )
240
251
  else:
241
- # retriever = EnsembleRetriever(
242
- # retrievers=[simil_retriever, retriever],
243
- # weights=[0.7, 0.3]
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=['summaries', 'question']
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 >= 10:
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,95 @@ class RetrievalManager:
433
447
  )
434
448
 
435
449
 
436
- def question(self, question):
437
- # vector = self.store.get_vector()
438
- # docs = vector.similarity_search(self._question, k=1)
439
- # max_confidence_score = 0
440
- # for doc_id, similarity_score in docs:
441
- # max_confidence_score = max(max_confidence_score, similarity_score)
442
- try:
443
- # Invoke the chain with the given question
444
- response = self.chain.invoke(question)
445
- except Exception as exc:
446
- self.logger.error(
447
- f"Error invoking chain: {exc}"
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": 5, "fetch_k": 20, "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
+ # print('COLLECTION > ', self.store.collection, self.store.embedding_name)
463
+ # print('DB > ', self.store.database)
464
+ async with self.store as store: #pylint: disable=E1101
465
+ vector = store.get_vector(metric_type=metric_type)
466
+ # docs = vector.similarity_search(question, k=1)
467
+ # print('DOCS > ', docs)
468
+ retriever = VectorStoreRetriever(
469
+ vectorstore=vector,
470
+ search_type=search_type,
471
+ chain_type=chain_type,
472
+ search_kwargs=search_kwargs
448
473
  )
449
- return None, None
450
- try:
451
- qa_response = ChatResponse(**response)
452
- except (ValueError, TypeError) as exc:
453
- self.logger.error(
454
- f"Error validating response: {exc}"
474
+ custom_template = self.template.format_map(
475
+ SafeDict(
476
+ summaries=''
477
+ )
455
478
  )
456
- return None, None
457
- except ValidationError as exc:
458
- self.logger.error(
459
- f"Error on response: {exc.payload}"
479
+ _prompt = PromptTemplate(
480
+ template=custom_template,
481
+ input_variables=["context", "chat_history", "question"],
460
482
  )
461
- return None, None
483
+ try:
484
+ chain = ConversationalRetrievalChain.from_llm(
485
+ llm=self.model,
486
+ retriever=retriever,
487
+ chain_type=chain_type,
488
+ verbose=False,
489
+ memory=memory,
490
+ return_source_documents=return_docs,
491
+ return_generated_question=True,
492
+ combine_docs_chain_kwargs={"prompt": _prompt},
493
+ **kwargs
494
+ )
495
+ response = chain.invoke(
496
+ question
497
+ )
498
+ except Exception as exc:
499
+ self.logger.error(
500
+ f"Error invoking chain: {exc}"
501
+ )
502
+ return None, None
503
+ try:
504
+ qa_response = ChatResponse(**response)
505
+ except (ValueError, TypeError) as exc:
506
+ self.logger.error(
507
+ f"Error validating response: {exc}"
508
+ )
509
+ return None, None
510
+ except ValidationError as exc:
511
+ self.logger.error(
512
+ f"Error on response: {exc.payload}"
513
+ )
514
+ return None, None
462
515
  try:
463
- return self.as_markdown(
516
+ qa_response.response = self.as_markdown(
464
517
  qa_response
465
- ), qa_response
518
+ )
519
+ # # saving question to Usage Log
520
+ # if self.request:
521
+ # tasker = self.request.app['service_queue']
522
+ # await tasker.put(
523
+ # self.log_usage,
524
+ # response=qa_response,
525
+ # request=self.request
526
+ # )
527
+ # else:
528
+ # asyncio.create_task(
529
+ # self.log_usage(response=qa_response)
530
+ # )
531
+ return qa_response
466
532
  except Exception as exc:
467
533
  self.logger.exception(
468
534
  f"Error on response: {exc}"
469
535
  )
470
536
  return None, None
471
537
 
538
+
472
539
  async def invoke(self, question):
473
540
  # Invoke the chain with the given question
474
541
  try:
@@ -481,7 +548,6 @@ class RetrievalManager:
481
548
  )
482
549
  return None, None
483
550
  try:
484
- print('RESPONSE > ', response)
485
551
  qa_response = ChatResponse(**response)
486
552
  except (ValueError, TypeError) as exc:
487
553
  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='sentence-transformers/sentence-t5-large'
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
- # print('MEMORY >> ', memory)
100
- async with chatbot.get_retrieval(request=self.request) as retrieval:
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
- result = await qa.invoke(question)
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 connect(self, client_id: str = None):
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 = 200,
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='Bounded',
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(self, query: str, collection: str = None, limit: int = 2) -> list:
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='Bounded',
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.1.0"
6
+ __version__ = "0.2.1"
7
7
  __author__ = "Jesus Lara"
8
8
  __author_email__ = "jesuslarag@gmail.com"
9
9
  __license__ = "MIT"