Skip to content

Commit

Permalink
Update token_handler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DedyKredo authored Feb 22, 2024
1 parent 42bcda1 commit a461c2a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pr_agent/algo/token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ def _get_system_user_tokens(self, pr, encoder, vars: dict, system, user):
Returns:
The sum of the number of tokens in the system and user strings.
"""
environment = Environment(undefined=StrictUndefined)
system_prompt = environment.from_string(system).render(vars)
user_prompt = environment.from_string(user).render(vars)
system_prompt_tokens = len(encoder.encode(system_prompt))
user_prompt_tokens = len(encoder.encode(user_prompt))
return system_prompt_tokens + user_prompt_tokens
try:
environment = Environment(undefined=StrictUndefined)
system_prompt = environment.from_string(system).render(vars)
user_prompt = environment.from_string(user).render(vars)
system_prompt_tokens = len(encoder.encode(system_prompt))
user_prompt_tokens = len(encoder.encode(user_prompt))
return system_prompt_tokens + user_prompt_tokens
except:
return -1

def count_tokens(self, patch: str) -> int:
"""
Expand All @@ -66,4 +69,4 @@ def count_tokens(self, patch: str) -> int:
Returns:
The number of tokens in the patch string.
"""
return len(self.encoder.encode(patch, disallowed_special=()))
return len(self.encoder.encode(patch, disallowed_special=()))

0 comments on commit a461c2a

Please sign in to comment.