Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
6 changes: 5 additions & 1 deletion torchchat/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ def encode_dialog_prompt(self, dialog) -> List[int]:
tokens = self.tokenizer.encode(f"{B_INST} ")
first_message = True # Bool to handle placing the B_INST token. Behavior is weird - the system prompt should have the B_INST, but not the first user message. All following user messages *should* have it. Also, if there is no system prompt, then the user message should have it.
for message in dialog:
content = message["content"].strip()
if isinstance(message["content"], list):
content = message["content"][0]["text"]
else:
content = message["content"]
content = content.strip()
if message["role"] == "system":
encoded = self.tokenizer.encode(f"{B_SYS}\n{content}\n{E_SYS}")
first_message = False
Expand Down
2 changes: 1 addition & 1 deletion torchchat/usages/openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def chunked_completion(self, completion_request: CompletionRequest):
encoded_prompt=encoded,
temperature=float(completion_request.temperature),
chat_mode=False,
sequential_prefill=False,
sequential_prefill=True,
)

def callback(x, *, done_generating=False):
Expand Down
Loading