(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1,
do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs)
| 160 | |
| 161 | @torch.no_grad() |
| 162 | def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1, |
| 163 | do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs): |
| 164 | if history is None: |
| 165 | history = [] |
| 166 | if logits_processor is None: |
| 167 | logits_processor = LogitsProcessorList() |
| 168 | logits_processor.append(InvalidScoreLogitsProcessor()) |
| 169 | gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p, |
| 170 | "temperature": temperature, "logits_processor": logits_processor, **kwargs} |
| 171 | inputs = self.build_inputs(tokenizer, query, history=history) |
| 172 | outputs = self.generate(**inputs, **gen_kwargs) |
| 173 | outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):] |
| 174 | response = tokenizer.decode(outputs) |
| 175 | response = self.process_response(response) |
| 176 | history = history + [(query, response)] |
| 177 | return response, history |
| 178 | |
| 179 | @torch.no_grad() |
| 180 | def batch_generate(self, tokenizer, queries, max_length: int = 8192, num_beams=1, |
no test coverage detected