mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
Protect for empty description
This commit is contained in:
@ -298,12 +298,16 @@ def clip_tokens(text: str, max_tokens: int) -> str:
|
|||||||
str: The clipped string.
|
str: The clipped string.
|
||||||
"""
|
"""
|
||||||
# We'll estimate the number of tokens by hueristically assuming 2.5 tokens per word
|
# We'll estimate the number of tokens by hueristically assuming 2.5 tokens per word
|
||||||
encoder = get_token_encoder()
|
try:
|
||||||
num_input_tokens = len(encoder.encode(text))
|
encoder = get_token_encoder()
|
||||||
if num_input_tokens <= max_tokens:
|
num_input_tokens = len(encoder.encode(text))
|
||||||
|
if num_input_tokens <= max_tokens:
|
||||||
|
return text
|
||||||
|
num_chars = len(text)
|
||||||
|
chars_per_token = num_chars / num_input_tokens
|
||||||
|
num_output_chars = int(chars_per_token * max_tokens)
|
||||||
|
clipped_text = text[:num_output_chars]
|
||||||
|
return clipped_text
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"Failed to clip tokens: {e}")
|
||||||
return text
|
return text
|
||||||
num_chars = len(text)
|
|
||||||
chars_per_token = num_chars / num_input_tokens
|
|
||||||
num_output_chars = int(chars_per_token * max_tokens)
|
|
||||||
clipped_text = text[:num_output_chars]
|
|
||||||
return clipped_text
|
|
||||||
|
Reference in New Issue
Block a user