in genai-on-vertex-ai/gemini/needle_in_a_haystack/needlehaystack/llm_needle_haystack_tester.py [0:0]
def encode_and_trim(self, context, context_length):
tokens = self.model_to_test.encode_text_to_tokens(context)
if len(tokens) > context_length:
context = self.model_to_test.decode_tokens(tokens, context_length)
return context