1
+ from ...project import get_project_profile_config
1
2
from ....connectors import Session
2
3
from ....env import LOG , ProfileConfig , CONFIG
3
4
from ....utils import get_blob_str , get_encoded_tokens
4
5
from ....models .blob import Blob
5
6
from ....models .utils import Promise , CODE
6
7
from ....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
8
9
from ...event import append_user_event
9
10
from .extract import extract_topics
10
11
from .merge import merge_or_valid_new_memos
11
12
from .summary import re_summary
12
13
from .organize import organize_profiles
13
14
from .types import MergeAddResult
14
15
from .event_summary import tag_event
15
- from .entry_summary import entry_summary
16
+ from .entry_summary import entry_chat_summary
16
17
17
18
18
19
def truncate_chat_blobs (
@@ -43,12 +44,18 @@ async def process_blobs(
43
44
return Promise .reject (
44
45
CODE .SERVER_PARSE_ERROR , "No blobs to process after truncating"
45
46
)
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 )
47
54
if not p .ok ():
48
55
return p
49
56
user_memo_str = p .data ()
50
57
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 )
52
59
if not p .ok ():
53
60
return p
54
61
extracted_data = p .data ()
@@ -59,7 +66,7 @@ async def process_blobs(
59
66
fact_contents = extracted_data ["fact_contents" ],
60
67
fact_attributes = extracted_data ["fact_attributes" ],
61
68
profiles = extracted_data ["profiles" ],
62
- config = extracted_data [ "config" ] ,
69
+ config = project_profiles ,
63
70
total_profiles = extracted_data ["total_profiles" ],
64
71
)
65
72
if not p .ok ():
@@ -74,7 +81,7 @@ async def process_blobs(
74
81
p = await organize_profiles (
75
82
project_id ,
76
83
profile_options ,
77
- config = extracted_data [ "config" ] ,
84
+ config = project_profiles ,
78
85
)
79
86
if not p .ok ():
80
87
LOG .error (f"Failed to organize profiles: { p .msg ()} " )
@@ -94,29 +101,21 @@ async def process_blobs(
94
101
project_id ,
95
102
user_memo_str ,
96
103
delta_profile_data ,
97
- extracted_data [ "config" ] ,
104
+ project_profiles ,
98
105
)
99
106
if not p .ok ():
100
107
return p
101
108
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 )
111
111
if not p .ok ():
112
112
return p
113
- delete_profile_ids = p .data ().ids
114
113
return Promise .resolve (
115
114
ChatModalResponse (
116
115
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" ] ,
120
119
)
121
120
)
122
121
@@ -149,44 +148,21 @@ async def handle_session_event(
149
148
return eid
150
149
151
150
152
- async def exe_user_profile_add (
151
+ async def handle_user_profile_db (
153
152
user_id : str , project_id : str , profile_options : MergeAddResult
154
153
) -> Promise [IdsData ]:
155
- if not len (profile_options ["add" ]):
156
- return Promise .resolve (IdsData (ids = []))
157
154
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 (
159
159
user_id ,
160
160
project_id ,
161
161
[ap ["content" ] for ap in profile_options ["add" ]],
162
162
[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 ,
176
163
[up ["profile_id" ] for up in profile_options ["update" ]],
177
164
[up ["content" ] for up in profile_options ["update" ]],
178
165
[up ["attributes" ] for up in profile_options ["update" ]],
166
+ profile_options ["delete" ],
179
167
)
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