Spaces:
Running
Running
:gem: [Feature] HuggingchatStreamer: Build pipeline of chat_response
Browse files30 unmodified lines31323334353637117 unmodified lines1551561571581591601614 unmodified lines16616716816917030 unmodified linesself.model = "mixtral-8x7b"self.model_fullname = MODEL_MAP[self.model]self.message_outputer = OpenaiStreamOutputer(model=self.model)# export HF_ENDPOINT=https://hf-mirror.comself.tokenizer = AutoTokenizer.from_pretrained(self.model_fullname)def count_tokens(self, text):117 unmodified linesapi_key: str = None,use_cache: bool = False,):passdef chat_return_dict(self, stream_response):pass4 unmodified linesif __name__ == "__main__":streamer = HuggingchatStreamer(model="mixtral-8x7b")conversation_id = streamer.get_conversation_id()# python -m networks.huggingchat_streamer30 unmodified lines313233343536117 unmodified lines1541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891904 unmodified lines19519619719819920030 unmodified linesself.model = "mixtral-8x7b"self.model_fullname = MODEL_MAP[self.model]self.message_outputer = OpenaiStreamOutputer(model=self.model)self.tokenizer = AutoTokenizer.from_pretrained(self.model_fullname)def count_tokens(self, text):117 unmodified linesapi_key: str = None,use_cache: bool = False,):self.get_hf_chat_id()self.get_conversation_id()message_id = self.get_message_id()request_url = f"https://huggingface.co/chat/conversation/{self.conversation_id}"request_headers = copy.deepcopy(HUGGINGCHAT_POST_HEADERS)extra_headers = {"Content-Type": "text/event-stream","Referer": request_url,"Cookie": f"hf-chat={self.hf_chat_id}",}request_headers.update(extra_headers)request_body = {"files": [],"id": message_id,"inputs": prompt,"is_continue": False,"is_retry": False,"web_search": False,}self.log_request(request_url, method="POST")res = requests.post(request_url,headers=request_headers,json=request_body,proxies=PROXIES,stream=True,)self.log_response(res, stream=True, iter_lines=True, verbose=True)return resdef chat_return_dict(self, stream_response):pass4 unmodified linesif __name__ == "__main__":streamer = HuggingchatStreamer(model="mixtral-8x7b")prompt = "who are you?"streamer.chat_response(prompt=prompt)# HF_ENDPOINT=https://hf-mirror.com python -m networks.huggingchat_streamer
networks/huggingchat_streamer.py+34-4