MCPcopy
hub / github.com/THUDM/LongWriter / build_chat_input

Method build_chat_input

train/patch/tokenization_chatglm.py:163–176  ·  view source on GitHub ↗
(self, query, history=None, role="user")

Source from the content-addressed store, hash-verified

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

Callers 3

predictFunction · 0.80
vllm_inference.pyFile · 0.80
chatMethod · 0.80

Calls 2

build_single_messageMethod · 0.95
get_commandMethod · 0.95

Tested by

no test coverage detected