Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add_generation_prompt to apply_chat_template #32

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions anonipy/anonymize/generators/llm_label_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _generate_response(

# tokenize the message
input_ids = self.tokenizer.apply_chat_template(
message, tokenize=True, return_tensors="pt"
message, tokenize=True, return_tensors="pt", add_generation_prompt=True
).to(self.model.device)

# generate the response
Expand All @@ -166,18 +166,4 @@ def _generate_response(
response = self.tokenizer.decode(
output_ids[0][len(input_ids[0]) :], skip_special_tokens=True
)
return self._parse_response(response)

def _parse_response(self, response: str) -> str:
"""Parse the response from the LLM.

Args:
response: The response to parse.

Returns:
The parsed response.

"""

match = re.search(r"assistant\s*(.*)", response, re.IGNORECASE | re.DOTALL)
return match.group(1).strip() if match else response
return response
Loading