1+ from ...project import get_project_profile_config
12from ....connectors import Session
23from ....env import LOG , ProfileConfig , CONFIG
34from ....utils import get_blob_str , get_encoded_tokens
45from ....models .blob import Blob
56from ....models .utils import Promise , CODE
67from ....models .response import IdsData , ChatModalResponse
7- from ...profile import add_user_profiles , update_user_profiles , delete_user_profiles
8+ from ...profile import add_update_delete_user_profiles
89from ...event import append_user_event
910from .extract import extract_topics
1011from .merge import merge_or_valid_new_memos
1112from .summary import re_summary
1213from .organize import organize_profiles
1314from .types import MergeAddResult
1415from .event_summary import tag_event
15- from .entry_summary import entry_summary
16+ from .entry_summary import entry_chat_summary
1617
1718
1819def truncate_chat_blobs (
@@ -43,12 +44,18 @@ async def process_blobs(
4344 return Promise .reject (
4445 CODE .SERVER_PARSE_ERROR , "No blobs to process after truncating"
4546 )
46- p = await entry_summary (user_id , project_id , blobs )
47+
48+ p = await get_project_profile_config (project_id )
49+ if not p .ok ():
50+ return p
51+ project_profiles = p .data ()
52+
53+ p = await entry_chat_summary (user_id , project_id , blobs , project_profiles )
4754 if not p .ok ():
4855 return p
4956 user_memo_str = p .data ()
5057
51- p = await extract_topics (user_id , project_id , user_memo_str )
58+ p = await extract_topics (user_id , project_id , user_memo_str , project_profiles )
5259 if not p .ok ():
5360 return p
5461 extracted_data = p .data ()
@@ -59,7 +66,7 @@ async def process_blobs(
5966 fact_contents = extracted_data ["fact_contents" ],
6067 fact_attributes = extracted_data ["fact_attributes" ],
6168 profiles = extracted_data ["profiles" ],
62- config = extracted_data [ "config" ] ,
69+ config = project_profiles ,
6370 total_profiles = extracted_data ["total_profiles" ],
6471 )
6572 if not p .ok ():
@@ -74,7 +81,7 @@ async def process_blobs(
7481 p = await organize_profiles (
7582 project_id ,
7683 profile_options ,
77- config = extracted_data [ "config" ] ,
84+ config = project_profiles ,
7885 )
7986 if not p .ok ():
8087 LOG .error (f"Failed to organize profiles: { p .msg ()} " )
@@ -94,29 +101,21 @@ async def process_blobs(
94101 project_id ,
95102 user_memo_str ,
96103 delta_profile_data ,
97- extracted_data [ "config" ] ,
104+ project_profiles ,
98105 )
99106 if not p .ok ():
100107 return p
101108 eid = p .data ()
102- p = await exe_user_profile_add (user_id , project_id , profile_options )
103- if not p .ok ():
104- return p
105- add_profile_ids = p .data ().ids
106- p = await exe_user_profile_update (user_id , project_id , profile_options )
107- if not p .ok ():
108- return p
109- update_profile_ids = p .data ().ids
110- p = await exe_user_profile_delete (user_id , project_id , profile_options )
109+
110+ p = await handle_user_profile_db (user_id , project_id , profile_options )
111111 if not p .ok ():
112112 return p
113- delete_profile_ids = p .data ().ids
114113 return Promise .resolve (
115114 ChatModalResponse (
116115 event_id = eid ,
117- add_profiles = add_profile_ids ,
118- update_profiles = update_profile_ids ,
119- delete_profiles = delete_profile_ids ,
116+ add_profiles = p . data (). ids ,
117+ update_profiles = [ up [ "profile_id" ] for up in profile_options [ "update" ]] ,
118+ delete_profiles = profile_options [ "delete" ] ,
120119 )
121120 )
122121
@@ -149,44 +148,21 @@ async def handle_session_event(
149148 return eid
150149
151150
152- async def exe_user_profile_add (
151+ async def handle_user_profile_db (
153152 user_id : str , project_id : str , profile_options : MergeAddResult
154153) -> Promise [IdsData ]:
155- if not len (profile_options ["add" ]):
156- return Promise .resolve (IdsData (ids = []))
157154 LOG .info (f"Adding { len (profile_options ['add' ])} profiles for user { user_id } " )
158- task_add = await add_user_profiles (
155+ LOG .info (f"Updating { len (profile_options ['update' ])} profiles for user { user_id } " )
156+ LOG .info (f"Deleting { len (profile_options ['delete' ])} profiles for user { user_id } " )
157+
158+ p = await add_update_delete_user_profiles (
159159 user_id ,
160160 project_id ,
161161 [ap ["content" ] for ap in profile_options ["add" ]],
162162 [ap ["attributes" ] for ap in profile_options ["add" ]],
163- )
164- return task_add
165-
166-
167- async def exe_user_profile_update (
168- user_id : str , project_id : str , profile_options : MergeAddResult
169- ) -> Promise [IdsData ]:
170- if not len (profile_options ["update" ]):
171- return Promise .resolve (IdsData (ids = []))
172- LOG .info (f"Updating { len (profile_options ['update' ])} profiles for user { user_id } " )
173- task_update = await update_user_profiles (
174- user_id ,
175- project_id ,
176163 [up ["profile_id" ] for up in profile_options ["update" ]],
177164 [up ["content" ] for up in profile_options ["update" ]],
178165 [up ["attributes" ] for up in profile_options ["update" ]],
166+ profile_options ["delete" ],
179167 )
180- return task_update
181-
182-
183- async def exe_user_profile_delete (
184- user_id : str , project_id : str , profile_options : MergeAddResult
185- ) -> Promise [IdsData ]:
186- if not len (profile_options ["delete" ]):
187- return Promise .resolve (IdsData (ids = []))
188- LOG .info (f"Deleting { len (profile_options ['delete' ])} profiles for user { user_id } " )
189- task_delete = await delete_user_profiles (
190- user_id , project_id , profile_options ["delete" ]
191- )
192- return task_delete
168+ return p
0 commit comments