MCPcopy Create free account
hub / github.com/Hunyuan-PromptEnhancer/PromptEnhancer / stream_single

Function stream_single

inference/app_stream.py:224–249  ·  view source on GitHub ↗
(prompt, sys_prompt, temperature, max_new_tokens, device,
                  model_path, device_map, torch_dtype, state)

Source from the content-addressed store, hash-verified

222 return state
223
224def stream_single(prompt, sys_prompt, temperature, max_new_tokens, device,
225 model_path, device_map, torch_dtype, state):
226 if not prompt or not str(prompt).strip():
227 yield "", "请先输入提示词。", state
228 return
229
230 t0 = time.time()
231 state = ensure_enhancer(state, model_path, device_map, torch_dtype)
232 enhancer = state["enhancer"]
233
234 emitted = ""
235 try:
236 for chunk in enhancer.predict_stream(
237 prompt_cot=prompt,
238 sys_prompt=sys_prompt,
239 temperature=temperature,
240 max_new_tokens=max_new_tokens,
241 device=device
242 ):
243 emitted = chunk
244 info = f"已接收 {len(emitted)} 字符,用时 {time.time()-t0:.2f}s"
245 yield emitted, info, state
246 # 结束时再给一次最终状态(可选)
247 yield emitted, f"完成。总耗时 {time.time()-t0:.2f}s", state
248 except Exception as e:
249 yield "", f"推理失败:{e}", state
250
251
252# 示例数据

Callers

nothing calls this directly

Calls 2

predict_streamMethod · 0.80
ensure_enhancerFunction · 0.70

Tested by

no test coverage detected