Spaces:
Runtime error
Runtime error
[update]add main
Browse files
main.py
CHANGED
@@ -122,18 +122,31 @@ def chat_with_llm_streaming(question: str,
|
|
122 |
|
123 |
model, tokenizer = init_model(pretrained_model_name_or_path)
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
input_ids.append(tokenizer.eos_token_id)
|
|
|
137 |
input_ids = torch.tensor([input_ids], dtype=torch.long)
|
138 |
input_ids = input_ids[:, -history_max_len:].to(device)
|
139 |
|
|
|
122 |
|
123 |
model, tokenizer = init_model(pretrained_model_name_or_path)
|
124 |
|
125 |
+
if model.config.model_type == "chatglm":
|
126 |
+
input_ids = []
|
127 |
+
else:
|
128 |
+
input_ids = [tokenizer.bos_token_id]
|
129 |
+
|
130 |
+
# history
|
131 |
+
for idx, (h_question, h_answer) in enumerate(history):
|
132 |
+
if model.config.model_type == "chatglm":
|
133 |
+
h_question = "[Round {}]\n\n问:{}\n\n答:".format(idx, h_question)
|
134 |
+
h_question = tokenizer.__call__(h_question, add_special_tokens=False)
|
135 |
+
h_answer = tokenizer.__call__(h_answer, add_special_tokens=False)
|
136 |
+
|
137 |
+
input_ids.append(h_question)
|
138 |
+
if model.config.model_type != "chatglm":
|
139 |
+
input_ids.append(tokenizer.eos_token_id)
|
140 |
+
input_ids.append(h_answer)
|
141 |
+
if model.config.model_type != "chatglm":
|
142 |
+
input_ids.append(tokenizer.eos_token_id)
|
143 |
+
|
144 |
+
# question
|
145 |
+
question = tokenizer.__call__(question, add_special_tokens=False)
|
146 |
+
input_ids.append(question)
|
147 |
+
if model.config.model_type != "chatglm":
|
148 |
input_ids.append(tokenizer.eos_token_id)
|
149 |
+
|
150 |
input_ids = torch.tensor([input_ids], dtype=torch.long)
|
151 |
input_ids = input_ids[:, -history_max_len:].to(device)
|
152 |
|