CoolFace
Modelpublic

aigenrec/luminabackend

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
notes_service.cpython-312.pyc55 linesDownload Raw Back to __pycache__
1�

2hn5i���ddlmZmZmZddlmZmZddlmZddl	m3Z4ddlmZddl
m
Z
ddlmZddlmZdd	lmZGd5�d�Ze�Zy)
�)�Dict�Any�List)�
create_client�Client)�settings)�logger)�uuid4)�datetime)�llm_service)�embedding_service)�qdrant_servicec�z�eZdZd�Zdededeeeffd�Zdedededeeeffd�Z		d
ded	ed6ede	edef7d�Z8y)�NotesServicec�^�ttjtj�|_y)N)rr�SUPABASE_URL�SUPABASE_SERVICE_KEY�client)�selfs �+D:\lumina\backend\services\notes_service.py�__init__zNotesService.__init__s ��+��!�!��)�)�9����10project_id�user_id�returnc��K�	|jjd�jd�jd|�jd|�j	�}|j11r*|j12d}|d|d|d|d|d|d	d13�Sy#t$r'}tjdt|�����d}~wwxYw�w)
zGet notes for a project�notes�*rrr�id�content�14created_at�15updated_at)rrrr r!r"NzError getting notes: )16r�table�select�eq�execute�data�	Exceptionr	�error�str)rrr�response�note�es      r�	get_noteszNotesService.get_notess�����	��{�{�(�(��1�8�8��=�@�@��j���b��G�$�W�W�Y�
��}�}��}�}�Q�'���t�*�"&�|�"4�#�I��#�I��"&�|�"4�"&�|�"4�
�����	��L�L�0��Q���9�:���	�s)�C�B
B�C�	C�"B>�>C�Cr c���K�	|j||��d{���}|r�|jjd�j|t	j17�j
�d��jd|d�j�}tjd|���nhtt��}|jjd�j||||d��j�}tjd|���|jr|jdSiS7��#t$r'}tj d	t|�����d}~wwxYw�w)18z$Create or update notes for a projectNr)r r"rzUpdated notes for project )rrrr zCreated notes for project rzError creating/updating notes: )r.rr#�updater�utcnow�	isoformatr%r&r	�infor*r19�insertr'r(r))rrrr �existingr+�note_idr-s        r�create_or_update_notesz#NotesService.create_or_update_notes*s7����	�!�^�^�J��@�@�H���;�;�,�,�W�5�<�<�&�"*�/�/�"3�"=�"=�"?�>���2�d�H�T�N�+�G�G�I��20���8���E�F��e�g�,���;�;�,�,�W�5�<�<�!�",�&�&�	>��21�7�9�����8���E�F�'/�}�}�8�=�=��#�<�"�<�-A��0�	��L�L�:�3�q�6�(�C�D���	�sE�E"�D/�D,�DD/�)E"�*D/�+E"�,D/�/	E�8"E�E�E"N�	note_type�topic�selected_documentsc���K�	tjd|�d|�d|���g}|r22||�d|��g}nd|vrgd�}nd|vrgd�}n|g}d	|��}g}t�}|D]z}	tj|	��d23{���}24tj||25d|rd|ind26�
��d27{���}|D]/}|d|vs�|j|�|j|d��1�||sydj|d28dD�cgc]}|d��	c}�}
d|�d|
�d�}d|d�g}tj|dd���d29{���}|S7��7��cc}w7�#t$r'}tjdt|�����d30}~wwxYw�w)zGenerate notes using AIzGenerating notes (z) for project z	, topic: z of �Summary)zoverview of the documentzmain concepts and themeszconclusion and resultsz31Key Points)zimportant definitionsz
key takeawayszcritical points�project_N�32�document_ids)�collection_name�query_vector�limit�filter_conditions�textz#No content found to generate notes.z33 34�z
Generate a **z9** based on the following content.35            36Content:37z�38 39Requirements:40- Use clear, professional Markdown formatting.41- Use headers, bullet points, and bold text for readability.42- Be comprehensive but concise.43- Structure it as a study guide or note set.44 45Respond ONLY with the Markdown content.�user)�roler g�?i�	)�temperature�46max_tokenszError generating notes: )r	r3�setr
�generate_embeddingr�search�append�add�joinr�chat_completionr(r)r*)rrr8r9r:�queriesr@�all_hits�47seen_texts�q�	embedding�results�hit�context�prompt�messagesr+r-s                  r�generate_noteszNotesService.generate_notesOs�����;	��K�K�,�Y�K�~�j�\�QZ�[`�Za�b�c��G�� �Y�K�t�E�7�";�<���i�'�l����*�W��$�+�� (���5�O��H���J���"3�"F�"F�q�"I�I�	� .� 5� 5�$3�!*��N`�~�7I�&J�fj�	!���#�C��6�{�*�4� ����,�"���s�6�{�3�#���<��k�k�(�3�B�-�"H�-�3�3�v�;�-�"H�I�G�'�y�k�2�	�	�48(�+�F�"(�F�;�<�H�(�8�8��s�_c�d�d�H��O�GJ����#I�"e���	��L�L�3�C��F�8�<�=���	�s}�E,�A/D9�3D.�4&D9�D0�D9�,+D9�E,�D9�*D2�61D9�'D7�(D9�-E,�.D9�0D9�2D9�9	E)�"E$�$E)�)E,)NN)�__name__�49__module__�__qualname__rr*rrr.r7rr[�rrrrs���50��#�����S�#�X���0#��#��#��	#�5152�c�3�h��#�R�(,�C��C��C��	C�53!��I�C�54
�
CrrN)�typingrrr�supabaserr�config.settingsr�utils.loggerr	�uuidr55r�services.llm_servicer�services.embedding_servicer
�services.qdrant_servicerr�
notes_servicer_rr�<module>ris9��"�"�*�$����,�8�2�G�G�R��
r