@@ -3312,21 +3312,29 @@ async def expand_query(query: Any = None, max_new: Any = None) -> Dict[str, Any]
33123312 cap = max (0 , min (2 , int (max_new )))
33133313 except (ValueError , TypeError ):
33143314 cap = 2
3315- from scripts .refrag_llamacpp import LlamaCppRefragClient , is_decoder_enabled # type: ignore
3316- if not is_decoder_enabled ():
3317- return {"alternates" : [], "hint" : "decoder disabled: set REFRAG_DECODER=1 and start llamacpp (LLAMACPP_URL)" }
3315+ runtime = str (os .environ .get ("REFRAG_RUNTIME" , "llamacpp" )).strip ().lower ()
3316+ dec_on = str (os .environ .get ("REFRAG_DECODER" , "0" )).strip ().lower () in {"1" , "true" , "yes" , "on" }
3317+ if runtime == "glm" :
3318+ if not (dec_on and os .environ .get ("GLM_API_KEY" )):
3319+ return {"alternates" : [], "hint" : "decoder disabled: set REFRAG_DECODER=1 and GLM_API_KEY; or use llamacpp" }
3320+ from scripts .refrag_glm import GLMRefragClient # type: ignore
3321+ client = GLMRefragClient ()
3322+ else :
3323+ from scripts .refrag_llamacpp import LlamaCppRefragClient , is_decoder_enabled # type: ignore
3324+ if not is_decoder_enabled ():
3325+ return {"alternates" : [], "hint" : "decoder disabled: set REFRAG_DECODER=1 and start llamacpp (LLAMACPP_URL)" }
3326+ client = LlamaCppRefragClient ()
33183327 if not qlist :
33193328 return {"alternates" : []}
33203329 prompt = (
33213330 "You expand code search queries. Given short queries, propose up to 2 compact alternates.\n "
33223331 "Return JSON array of strings only. No explanations.\n "
33233332 f"Queries: { qlist } \n "
33243333 )
3325- client = LlamaCppRefragClient ()
33263334 out = client .generate_with_soft_embeddings (
33273335 prompt = prompt ,
33283336 max_tokens = int (os .environ .get ("EXPAND_MAX_TOKENS" , "64" ) or 64 ),
3329- temperature = 0.0 , # Always 0 for deterministic expansion
3337+ temperature = 0.0 ,
33303338 top_k = int (os .environ .get ("EXPAND_TOP_K" , "30" ) or 30 ),
33313339 top_p = float (os .environ .get ("EXPAND_TOP_P" , "0.9" ) or 0.9 ),
33323340 stop = ["\n \n " ],
@@ -4790,8 +4798,13 @@ def _ca_build_prompt(context_blocks: list[str], citations: list[Dict[str, Any]],
47904798
47914799
47924800def _ca_decode (prompt : str , * , mtok : int , temp : float , top_k : int , top_p : float , stops : list [str ]) -> str :
4793- from scripts .refrag_llamacpp import LlamaCppRefragClient # type: ignore
4794- client = LlamaCppRefragClient ()
4801+ runtime = str (os .environ .get ("REFRAG_RUNTIME" , "llamacpp" )).strip ().lower ()
4802+ if runtime == "glm" :
4803+ from scripts .refrag_glm import GLMRefragClient # type: ignore
4804+ client = GLMRefragClient ()
4805+ else :
4806+ from scripts .refrag_llamacpp import LlamaCppRefragClient # type: ignore
4807+ client = LlamaCppRefragClient ()
47954808 return client .generate_with_soft_embeddings (
47964809 prompt = prompt ,
47974810 max_tokens = mtok ,
0 commit comments