(
self,
text: str,
*,
add_bos: bool = True,
special: bool = True,
)
| 11932 | ) |
| 11933 | |
| 11934 | def tokenize( |
| 11935 | self, |
| 11936 | text: str, |
| 11937 | *, |
| 11938 | add_bos: bool = True, |
| 11939 | special: bool = True, |
| 11940 | ) -> List[int]: |
| 11941 | encoded = text.encode("utf-8") |
| 11942 | capacity = max(32, len(encoded) + 32) |
| 11943 | while True: |
| 11944 | tokens = (llama_cpp.llama_token * capacity)() |
| 11945 | count = int( |
| 11946 | llama_cpp.llama_tokenize( |
| 11947 | self.vocab, |
| 11948 | encoded, |
| 11949 | len(encoded), |
| 11950 | tokens, |
| 11951 | capacity, |
| 11952 | add_bos, |
| 11953 | special, |
| 11954 | ) |
| 11955 | ) |
| 11956 | if count >= 0: |
| 11957 | return [int(tokens[index]) for index in range(count)] |
| 11958 | capacity = max(capacity * 2, -count) |
| 11959 | |
| 11960 | def build_prompt_tokens(self, prompt: str, suffix: Optional[str]) -> List[int]: |
| 11961 | if suffix is None: |
no test coverage detected