(self, query, history=None, role="user")
| 161 | return tokens |
| 162 | |
| 163 | def build_chat_input(self, query, history=None, role="user"): |
| 164 | if history is None: |
| 165 | history = [] |
| 166 | input_ids = [] |
| 167 | for item in history: |
| 168 | content = item["content"] |
| 169 | if item["role"] == "system" and "tools" in item: |
| 170 | for function in item["tools"]: |
| 171 | content += f"\n\n## {function['name']}\n\n{json.dumps(function, ensure_ascii=False, indent=4)}" |
| 172 | content += "\n在调用上述函数时,请使用 Json 格式表示调用的参数。" |
| 173 | input_ids.extend(self.build_single_message(item["role"], item.get("metadata", ""), content)) |
| 174 | input_ids.extend(self.build_single_message(role, "", query)) |
| 175 | input_ids.extend([self.get_command("<|assistant|>")]) |
| 176 | return self.batch_encode_plus([input_ids], return_tensors="pt", is_split_into_words=True) |
| 177 | |
| 178 | def build_inputs_with_special_tokens( |
| 179 | self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None |
no test coverage detected