Spaces:
Paused
Paused
:gem: [Feature] MessageStreamer: Support stop sequence and auto removal
Browse files9 unmodified lines101112131314151617181920212223242547 unmodified lines7374757677787980818283848526 unmodified lines1121131141151161171181191201081211221231241251131261271281291301311321331344 unmodified lines1391401411251421431441459 unmodified lines MODEL_MAP = { "mixtral-8x7b": "mistralai/Mixtral-8x7B-Instruct-v0.1", # 72.62, fast [Recommended] "mistral-7b": "mistralai/Mistral-7B-Instruct-v0.2", # 65.71, fast "openchat-3.5": "openchat/openchat_3.5", # 61.24, fast "openchat-3.5": "openchat/openchat-3.5-1210", # ??, fast # "zephyr-7b-alpha": "HuggingFaceH4/zephyr-7b-alpha", # 59.5, fast # "zephyr-7b-beta": "HuggingFaceH4/zephyr-7b-beta", # 61.95, slow "default": "mistralai/Mixtral-8x7B-Instruct-v0.1", } STOP_SEQUENCES_MAP = { "mixtral-8x7b": "</s>", "mistral-7b": "</s>", "openchat-3.5": "<|end_of_turn|>", }
def __init__(self, model: str): if model in self.MODEL_MAP.keys():47 unmodified lines }, "stream": True, }
if self.model in self.STOP_SEQUENCES_MAP.keys(): self.stop_sequences = self.STOP_SEQUENCES_MAP[self.model] # self.request_body["parameters"]["stop_sequences"] = [ # self.STOP_SEQUENCES[self.model] # ]
logger.back(self.request_url) enver.set_envs(proxies=True) stream_response = requests.post(26 unmodified lines ] logger.back(final_output)
final_content = "" for line in stream_response.iter_lines(): if not line: continue content = self.parse_line(line)
if content.strip() == "</s>": if content.strip() == self.stop_sequences: logger.success("\n[Finished]") break else: logger.back(content, end="") final_output["choices"][0]["message"]["content"] += content final_content += content
if self.model in self.STOP_SEQUENCES_MAP.keys(): final_content = final_content.replace(self.stop_sequences, "")
final_output["choices"][0]["message"]["content"] = final_content return final_output
def chat_return_generator(self, stream_response):4 unmodified lines
content = self.parse_line(line)
if content.strip() == "</s>": if content.strip() == self.stop_sequences: content_type = "Finished" logger.success("\n[Finished]") is_finished = Truenetworks/message_streamer.py+21-4