@@ -36,7 +36,11 @@ def adapt(llm_handler, cache_data_convert, update_cache_callback, *args, **kwarg
36
36
else : # temperature <= 0
37
37
cache_skip = kwargs .pop ("cache_skip" , False )
38
38
cache_factor = kwargs .pop ("cache_factor" , 1.0 )
39
- pre_embedding_res = chat_cache .pre_embedding_func (
39
+ pre_embedding_res = time_cal (
40
+ chat_cache .pre_embedding_func ,
41
+ func_name = "pre_process" ,
42
+ report_func = chat_cache .report .pre ,
43
+ )(
40
44
kwargs ,
41
45
extra_param = context .get ("pre_embedding_func" , None ),
42
46
prompts = chat_cache .config .prompts ,
@@ -81,7 +85,11 @@ def adapt(llm_handler, cache_data_convert, update_cache_callback, *args, **kwarg
81
85
else rank_threshold
82
86
)
83
87
for cache_data in cache_data_list :
84
- ret = chat_cache .data_manager .get_scalar_data (
88
+ ret = time_cal (
89
+ chat_cache .data_manager .get_scalar_data ,
90
+ func_name = "get_data" ,
91
+ report_func = chat_cache .report .data ,
92
+ )(
85
93
cache_data ,
86
94
extra_param = context .get ("get_scalar_data" , None ),
87
95
session = session ,
@@ -112,7 +120,11 @@ def adapt(llm_handler, cache_data_convert, update_cache_callback, *args, **kwarg
112
120
"search_result" : cache_data ,
113
121
"embedding" : ret .embedding_data ,
114
122
}
115
- rank = chat_cache .similarity_evaluation .evaluation (
123
+ rank = time_cal (
124
+ chat_cache .similarity_evaluation .evaluation ,
125
+ func_name = "evaluation" ,
126
+ report_func = chat_cache .report .evaluation ,
127
+ )(
116
128
eval_query_data ,
117
129
eval_cache_data ,
118
130
extra_param = context .get ("evaluation_func" , None ),
@@ -129,16 +141,25 @@ def adapt(llm_handler, cache_data_convert, update_cache_callback, *args, **kwarg
129
141
cache_answers = sorted (cache_answers , key = lambda x : x [0 ], reverse = True )
130
142
answers_dict = dict ((d [1 ], d [2 ]) for d in cache_answers )
131
143
if len (cache_answers ) != 0 :
132
- if chat_cache .post_process_messages_func is temperature_softmax :
133
- return_message = chat_cache .post_process_messages_func (
134
- messages = [t [1 ] for t in cache_answers ],
135
- scores = [t [0 ] for t in cache_answers ],
136
- temperature = temperature ,
137
- )
138
- else :
139
- return_message = chat_cache .post_process_messages_func (
140
- [t [1 ] for t in cache_answers ]
141
- )
144
+
145
+ def post_process ():
146
+ if chat_cache .post_process_messages_func is temperature_softmax :
147
+ return_message = chat_cache .post_process_messages_func (
148
+ messages = [t [1 ] for t in cache_answers ],
149
+ scores = [t [0 ] for t in cache_answers ],
150
+ temperature = temperature ,
151
+ )
152
+ else :
153
+ return_message = chat_cache .post_process_messages_func (
154
+ [t [1 ] for t in cache_answers ]
155
+ )
156
+ return return_message
157
+
158
+ return_message = time_cal (
159
+ post_process ,
160
+ func_name = "post_process" ,
161
+ report_func = chat_cache .report .post ,
162
+ )()
142
163
chat_cache .report .hint_cache ()
143
164
if session :
144
165
chat_cache .data_manager .add_session (
@@ -156,7 +177,9 @@ def adapt(llm_handler, cache_data_convert, update_cache_callback, *args, **kwarg
156
177
llm_handler , cache_data_convert , update_cache_callback , * args , ** kwargs
157
178
)
158
179
else :
159
- llm_data = llm_handler (* args , ** kwargs )
180
+ llm_data = time_cal (
181
+ llm_handler , func_name = "llm_request" , report_func = chat_cache .report .llm
182
+ )(* args , ** kwargs )
160
183
161
184
if cache_enable :
162
185
try :
@@ -166,13 +189,23 @@ def update_cache_func(handled_llm_data, question=None):
166
189
question = pre_store_data
167
190
else :
168
191
question .content = pre_store_data
169
- chat_cache .data_manager .save (
192
+ time_cal (
193
+ chat_cache .data_manager .save ,
194
+ func_name = "save" ,
195
+ report_func = chat_cache .report .save ,
196
+ )(
170
197
question ,
171
198
handled_llm_data ,
172
199
embedding_data ,
173
200
extra_param = context .get ("save_func" , None ),
174
201
session = session ,
175
202
)
203
+ if (
204
+ chat_cache .report .op_save .count > 0
205
+ and chat_cache .report .op_save .count % chat_cache .config .auto_flush
206
+ == 0
207
+ ):
208
+ chat_cache .flush ()
176
209
177
210
llm_data = update_cache_callback (
178
211
llm_data , update_cache_func , * args , ** kwargs
0 commit comments