MCPcopy Create free account
hub / github.com/modelscope/ms-agent / encode

Method encode

ms_agent/utils/tokenizer_util.py:19–30  ·  view source on GitHub ↗

Encode text into token IDs. Args: content: Input text string. Returns: List of token IDs.

(self, content: str)

Source from the content-addressed store, hash-verified

17 self.tokenizer = AutoTokenizer.from_pretrained(model_id)
18
19 def encode(self, content: str) -> List[int]:
20 """Encode text into token IDs.
21
22 Args:
23 content: Input text string.
24
25 Returns:
26 List of token IDs.
27 """
28 if not content.strip():
29 return []
30 return self.tokenizer.encode(content.strip())
31
32 def decode(self, token_ids: List[int]) -> str:
33 """Decode a list of token IDs back into a natural text string.

Callers 12

segmentMethod · 0.95
parse_imagesMethod · 0.80
send_requestMethod · 0.80
send_notificationMethod · 0.80
str_to_md5Function · 0.80
text_hashFunction · 0.80
file_lockFunction · 0.80
count_tokensMethod · 0.80
_hash_blockMethod · 0.80
_get_embeddingsMethod · 0.80
send_inputMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected