Merge branch 'main' into feature/email_management_98
Browse filesFiles changed (6)
1234/Brain/firebase_cred.json/.ideaBrain/firebase_cred.json/Brain/src/rising_plugin/gmail/credentials.json12345/Brain/firebase_cred.json/.ideaBrain/firebase_cred.jsonBrain/logs
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081822023-06-11 01:39:05,597 ERROR sendNotification 2023-06-11 03:49:04,950 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-11 03:49:04,950 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-11 03:49:04,950 DEBUG System: You are a helpful assistant.2023-06-11 03:49:04,950 DEBUG 2023-06-11 03:49:04,950 DEBUG User: Who won the world series in 2020?2023-06-11 03:49:04,950 DEBUG 2023-06-11 03:49:04,950 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-11 03:49:04,950 DEBUG 2023-06-11 03:49:04,950 DEBUG User: Where was it played?2023-06-11 03:49:04,951 DEBUG 2023-06-11 03:49:04,951 DEBUG ----------- END OF CONTEXT ----------------2023-06-11 03:49:14,350 WARNING API Rate Limit Reached. Waiting 10 seconds... Error: 2023-06-11 03:49:34,004 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-11 03:49:34,004 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-11 03:49:34,004 DEBUG System: You are a helpful assistant.2023-06-11 03:49:34,004 DEBUG 2023-06-11 03:49:34,004 DEBUG User: Who won the world series in 2020?2023-06-11 03:49:34,004 DEBUG 2023-06-11 03:49:34,004 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-11 03:49:34,004 DEBUG 2023-06-11 03:49:34,004 DEBUG User: Where was it played?2023-06-11 03:49:34,004 DEBUG 2023-06-11 03:49:34,004 DEBUG ----------- END OF CONTEXT ----------------2023-06-11 03:50:02,195 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-11 03:50:02,196 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-11 03:50:02,196 DEBUG System: You are a helpful assistant.2023-06-11 03:50:02,196 DEBUG 2023-06-11 03:50:02,196 DEBUG User: Who won the world series in 2020?2023-06-11 03:50:02,197 DEBUG 2023-06-11 03:50:02,197 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-11 03:50:02,197 DEBUG 2023-06-11 03:50:02,197 DEBUG User: Where was it played?2023-06-11 03:50:02,197 DEBUG 2023-06-11 03:50:02,197 DEBUG ----------- END OF CONTEXT ----------------2023-06-11 03:52:01,682 WARNING API Rate Limit Reached. Waiting 10 seconds... Error: 2023-06-11 03:52:04,881 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-11 03:52:04,882 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-11 03:52:04,882 DEBUG System: You are a helpful assistant.2023-06-11 03:52:04,882 DEBUG 2023-06-11 03:52:04,882 DEBUG User: Who won the world series in 2020?2023-06-11 03:52:04,883 DEBUG 2023-06-11 03:52:04,883 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-11 03:52:04,883 DEBUG 2023-06-11 03:52:04,884 DEBUG User: Where was it played?2023-06-11 03:52:04,884 DEBUG 2023-06-11 03:52:04,884 DEBUG ----------- END OF CONTEXT ----------------2023-06-11 03:59:41,875 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-11 03:59:41,876 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-11 03:59:41,876 DEBUG System: You are a helpful assistant.2023-06-11 03:59:41,876 DEBUG 2023-06-11 03:59:41,876 DEBUG User: Who won the world series in 2020?2023-06-11 03:59:41,876 DEBUG 2023-06-11 03:59:41,876 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-11 03:59:41,876 DEBUG 2023-06-11 03:59:41,876 DEBUG User: Where was it played?2023-06-11 03:59:41,876 DEBUG 2023-06-11 03:59:41,876 DEBUG ----------- END OF CONTEXT ----------------2023-06-12 17:08:50,779 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-12 17:08:50,780 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-12 17:08:50,780 DEBUG System: You are a helpful assistant.2023-06-12 17:08:50,780 DEBUG 2023-06-12 17:08:50,780 DEBUG User: Who won the world series in 2020?2023-06-12 17:08:50,780 DEBUG 2023-06-12 17:08:50,780 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-12 17:08:50,780 DEBUG 2023-06-12 17:08:50,780 DEBUG User: Where was it played?2023-06-12 17:08:50,780 DEBUG 2023-06-12 17:08:50,780 DEBUG ----------- END OF CONTEXT ----------------2023-06-16 14:22:55,555 ERROR sendNotification json parsing or get completion error2023-06-16 14:23:59,508 ERROR sendNotification json parsing or get completion error2023-06-16 15:58:51,640 DEBUG Chat with AI on model : gpt-3.5-turbo2023-06-16 15:58:51,641 DEBUG ------------ CONTEXT SENT TO AI ---------------2023-06-16 15:58:51,641 DEBUG System: You are a helpful assistant.2023-06-16 15:58:51,642 DEBUG 2023-06-16 15:58:51,642 DEBUG User: Who won the world series in 2020?2023-06-16 15:58:51,642 DEBUG 2023-06-16 15:58:51,642 DEBUG Assistant: The Los Angeles Dodgers won the World Series in 2020.2023-06-16 15:58:51,642 DEBUG 2023-06-16 15:58:51,642 DEBUG User: Where was it played?2023-06-16 15:58:51,642 DEBUG 2023-06-16 15:58:51,642 DEBUG ----------- END OF CONTEXT ----------------68 unmodified lines69707168 unmodified linesdef to_req_model(self, basic_req: BasicReq.Confs) -> ReqModel:return ReqModel(basic_req.to_json())68 unmodified lines69707172737475767778798081828384858668 unmodified linesdef to_req_model(self, basic_req: BasicReq.Confs) -> ReqModel:return ReqModel(basic_req.to_json())"""mapping data from a ContactModel into json{"contactId": int,"displayName": string,"phoneNumbers": [string]}"""def to_contact_result_format(self, contact: ContactModel) -> Any:return {"contactId": contact.contact_id,"displayName": contact.display_name,"phoneNumbers": contact.phone_numbers,}
226 unmodified lines227228229226 unmodified linesimap_folder: strdata: Body226 unmodified lines227228229230231232233234235236226 unmodified linesimap_folder: strdata: Body"""endpoint : /contact/get_by_ids"""class GetContactsByIds(BasicReq):contactIds: list[str]
19 unmodified lines20212223242566 unmodified lines92939495969798316 unmodified lines41541641741841942042124 unmodified lines44644744844945045145296 unmodified lines54955055155255319 unmodified linesget_client_info,AutoTaskDelete,EmailReader,)from Brain.src.rising_plugin.risingplugin import (getCompletion,66 unmodified lines# check contact queryingtry:contacts_service = ContactsService(setting=setting)if result["program"] == ProgramType.AUTO_TASK:auto_task_service = AutoTaskService()result["content"] = auto_task_service.ask_task_with_autogpt(316 unmodified linesfor contact in data.contacts:contacts.append(assembler.to_contact_model(contact))# train contactcontacts_service = ContactsService(setting=setting)contacts_service.train(uuid, contacts)except Exception as e:if isinstance(e, BrainException):24 unmodified lines# parsing contacts# train contactcontacts_service = ContactsService(setting=setting)contacts_service.delete_all(uuid)except Exception as e:if isinstance(e, BrainException):96 unmodified linesreturn e.get_response_exp()return assembler.to_response(400, "Failed to read emails", "")return assembler.to_response(200, "", result)return router19 unmodified lines2021222324252666 unmodified lines93949596979899100101316 unmodified lines41841942042142242342442542624 unmodified lines45145245345445545645745845996 unmodified lines55655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459519 unmodified linesget_client_info,AutoTaskDelete,EmailReader,GetContactsByIds,)from Brain.src.rising_plugin.risingplugin import (getCompletion,66 unmodified lines# check contact queryingtry:contacts_service = ContactsService(firebase_app=firebase_app, setting=setting)if result["program"] == ProgramType.AUTO_TASK:auto_task_service = AutoTaskService()result["content"] = auto_task_service.ask_task_with_autogpt(316 unmodified linesfor contact in data.contacts:contacts.append(assembler.to_contact_model(contact))# train contactcontacts_service = ContactsService(firebase_app=firebase_app, setting=setting)contacts_service.train(uuid, contacts)except Exception as e:if isinstance(e, BrainException):24 unmodified lines# parsing contacts# train contactcontacts_service = ContactsService(firebase_app=firebase_app, setting=setting)contacts_service.delete_all(uuid)except Exception as e:if isinstance(e, BrainException):96 unmodified linesreturn e.get_response_exp()return assembler.to_response(400, "Failed to read emails", "")return assembler.to_response(200, "", result))"""@generator.request_body({"token": "String","uuid": "String","contactIds": [String]})@generator.response(status_code=200, schema={"message": "message", "result": "test_result"})"""@router.post("/contacts/get_by_ids")def get_contacts_by_ids(data: GetContactsByIds):try:setting, firebase_app = firebase_admin_with_setting(data)except BrainException as ex:return ex.get_response_exp()token: str = setting.tokenuuid: str = setting.uuidresult = ContactsService(firebase_app=firebase_app, setting=setting).get_contacts_by_ids(uuid=uuid, contactIds=data.contactIds)return assembler.to_response(200, "Success to get contacts by uuid", result)return router
1234568 unmodified lines151617181920212223243 unmodified lines282930313233347 unmodified lines4243444546474849505152531 unmodified line55565758596024 unmodified lines858687"""service to manage contacts"""from typing import List, Anyfrom Brain.src.model.req_model import ReqModelfrom Brain.src.rising_plugin.csv_embed import get_embedfrom Brain.src.rising_plugin.pinecone_engine import (8 unmodified linesfrom Brain.src.common.utils import PINECONE_INDEX_NAMEfrom Brain.src.model.contact_model import ContactModel, ContactStatusclass ContactsService:def __init__(self, setting: ReqModel):self.setting = setting"""train contacts (getting embedding) and update pinecone with embeddings by contact_idtrain datatype:3 unmodified linesdef train(self, uuid: str, contacts: List[ContactModel]) -> None:# getting index namespaceof pineconepinecone_namespace = self.get_pinecone_index_namespace(uuid)for contact in contacts:# generate key and values for pinecone datakey = contact.contact_idvalue = f"{contact.display_name}, {contact.get_str_phones()}"7 unmodified linesvalue=vectoring_values,setting=self.setting,)elif contact.status == ContactStatus.DELETED:delete_pinecone(namespace=pinecone_namespace,key=key,setting=self.setting,)elif contact.status == ContactStatus.UPDATED:update_pinecone(namespace=pinecone_namespace,1 unmodified linevalue=vectoring_values,setting=self.setting,)""""query contact with search textresponse: list of contactId as index key of pinecone"""24 unmodified linesdef get_pinecone_index_namespace(self, uuid: str) -> str:return get_pinecone_index_namespace(f"{uuid}-contacts")123456788 unmodified lines1718192021222324252627282930313233343 unmodified lines3839404142434445467 unmodified lines54555657585960616263646566671 unmodified line6970717273747524 unmodified lines100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153"""service to manage contacts"""from typing import List, Anyfrom Brain.src.common.assembler import Assemblerfrom Brain.src.model.req_model import ReqModelfrom Brain.src.rising_plugin.csv_embed import get_embedfrom Brain.src.rising_plugin.pinecone_engine import (8 unmodified linesfrom Brain.src.common.utils import PINECONE_INDEX_NAMEfrom Brain.src.model.contact_model import ContactModel, ContactStatusimport firebase_adminfrom firebase_admin import firestoreclass ContactsService:db: Anyphones_ref: Anydef __init__(self, firebase_app: firebase_admin.App, setting: ReqModel):self.firebase_app = firebase_appself.setting = settingself.init_firestore()"""train contacts (getting embedding) and update pinecone with embeddings by contact_idtrain datatype:3 unmodified linesdef train(self, uuid: str, contacts: List[ContactModel]) -> None:# getting index namespaceof pineconepinecone_namespace = self.get_pinecone_index_namespace(uuid)for contact in contacts:# Save the data# generate key and values for pinecone datakey = contact.contact_idvalue = f"{contact.display_name}, {contact.get_str_phones()}"7 unmodified linesvalue=vectoring_values,setting=self.setting,)self.create_one_contact(uuid=uuid, contact=contact)elif contact.status == ContactStatus.DELETED:delete_pinecone(namespace=pinecone_namespace,key=key,setting=self.setting,)self.delete_one_contact(uuid=uuid, contact=contact)elif contact.status == ContactStatus.UPDATED:update_pinecone(namespace=pinecone_namespace,1 unmodified linevalue=vectoring_values,setting=self.setting,)self.update_one_contact(uuid=uuid, contact=contact)""""query contact with search textresponse: list of contactId as index key of pinecone"""24 unmodified linesdef get_pinecone_index_namespace(self, uuid: str) -> str:return get_pinecone_index_namespace(f"{uuid}-contacts")"""init firestore to save user's contacts"""def init_firestore(self):self.db = firestore.client(app=self.firebase_app)self.phones_ref = self.db.collection("phones")"""create a contact into document which name is uuid in phone collections in firestore"""def create_one_contact(self, uuid: str, contact: ContactModel):assembler = Assembler()data = assembler.to_contact_result_format(contact)phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.set(data)"""update a contact into document which name is uuid in phone collections in firestore"""def update_one_contact(self, uuid: str, contact: ContactModel):assembler = Assembler()data = assembler.to_contact_result_format(contact)phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.update(data)"""delete a contact into document which name is uuid in phone collections in firestore"""def delete_one_contact(self, uuid: str, contact: ContactModel):phones_doc_ref = self.phones_ref.document(uuid)contacts_doc_ref = phones_doc_ref.collection("contacts").document(contact.contact_id)contacts_doc_ref.delete()def get_contacts_by_ids(self, uuid: str, contactIds: list[str]) -> []:phones_doc_ref = self.phones_ref.document(uuid)contacts_ref = phones_doc_ref.collection("contacts")# Retrieve all documents in the 'contacts' sub-collectioncontacts = contacts_ref.where("contactId", "in", contactIds).stream()result = []# Iterate through the documents and print out their datafor contact in contacts:result.append(contact.to_dict())return result
.gitignore+2-1
Brain/logs/activity.logDeleted-82
Brain/src/common/assembler.py+15
Brain/src/model/requests/request_model.py+7
Brain/src/router/api.py+45-3
Brain/src/service/contact_service.py+67-1