21
21
from gptcache .embedding .base import BaseEmbedding
22
22
from gptcache .manager import manager_factory
23
23
from gptcache .manager .data_manager import DataManager
24
+ from gptcache .processor .context import (
25
+ SummarizationContextProcess ,
26
+ SelectiveContextProcess ,
27
+ ConcatContextProcess ,
28
+ )
24
29
from gptcache .processor .post import temperature_softmax
25
30
from gptcache .processor .pre import get_prompt
26
31
from gptcache .similarity_evaluation import (
@@ -192,9 +197,15 @@ def init_similar_cache_from_config(config_dir: str, cache_obj: Optional[Cache] =
192
197
else :
193
198
init_conf = {}
194
199
195
- model_src = init_conf .get ("model_source" , "onnx" )
196
- model_config = init_conf .get ("model_config" , {})
197
- embedding_model = _get_model (model_src , model_config )
200
+ # Due to the problem with the first naming, it is reserved to ensure compatibility
201
+ embedding = init_conf .get ("model_source" , "" )
202
+ if not embedding :
203
+ embedding = init_conf .get ("embedding" , "onnx" )
204
+ # ditto
205
+ embedding_config = init_conf .get ("model_config" , {})
206
+ if not embedding_config :
207
+ embedding_config = init_conf .get ("embedding_config" , {})
208
+ embedding_model = _get_model (embedding , embedding_config )
198
209
199
210
storage_config = init_conf .get ("storage_config" , {})
200
211
storage_config .setdefault ("manager" , "sqlite,faiss" )
@@ -205,13 +216,23 @@ def init_similar_cache_from_config(config_dir: str, cache_obj: Optional[Cache] =
205
216
data_manager = manager_factory (** storage_config )
206
217
207
218
eval_strategy = init_conf .get ("evaluation" , "distance" )
208
- eval_kws = init_conf .get ("evaluation_kws" )
209
- evaluation = _get_eval (eval_strategy , eval_kws )
219
+ # Due to the problem with the first naming, it is reserved to ensure compatibility
220
+ eval_config = init_conf .get ("evaluation_kws" , {})
221
+ if not eval_config :
222
+ eval_config = init_conf .get ("evaluation_config" , {})
223
+ evaluation = _get_eval (eval_strategy , eval_config )
210
224
211
225
cache_obj = cache_obj if cache_obj else cache
212
226
213
- pre_prcocess = init_conf .get ("pre_function" , "get_prompt" )
214
- pre_func = _get_pre_func (pre_prcocess )
227
+ pre_process = init_conf .get ("pre_context_function" )
228
+ if pre_process :
229
+ pre_func = _get_pre_context_function (
230
+ pre_process , init_conf .get ("pre_context_config" )
231
+ )
232
+ pre_func = pre_func .pre_process
233
+ else :
234
+ pre_process = init_conf .get ("pre_function" , "get_prompt" )
235
+ pre_func = _get_pre_func (pre_process )
215
236
216
237
post_process = init_conf .get ("post_function" , "first" )
217
238
post_func = _get_post_func (post_process )
@@ -273,8 +294,19 @@ def _get_eval(strategy, kws=None):
273
294
return KReciprocalEvaluation (** kws )
274
295
275
296
276
- def _get_pre_func (pre_prcocess ):
277
- return getattr (gptcache .processor .pre , pre_prcocess )
297
+ def _get_pre_func (pre_process ):
298
+ return getattr (gptcache .processor .pre , pre_process )
299
+
300
+
301
+ def _get_pre_context_function (pre_context_process , kws = None ):
302
+ pre_context_process = pre_context_process .lower ()
303
+ kws = kws or {}
304
+ if pre_context_process in "summarization" :
305
+ return SummarizationContextProcess (** kws )
306
+ if pre_context_process in "selective" :
307
+ return SelectiveContextProcess (** kws )
308
+ if pre_context_process in "concat" :
309
+ return ConcatContextProcess ()
278
310
279
311
280
312
def _get_post_func (post_process ):
0 commit comments