MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / chat_token_encode

Function chat_token_encode

examples/llama3.py:397–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

395
396 @app.post("/v1/chat/token/encode")
397 def chat_token_encode():
398 rjson = json.loads(request.body.read())
399 if "messages" not in rjson: abort(400, "messages required")
400 toks = [tokenizer.bos_id]
401 for message in rjson["messages"]:
402 toks += encode_message(message["role"], message["content"])
403 if len(rjson["messages"]) > 0 and message["role"] == "user":
404 toks += encode_role("assistant")
405 return json.dumps(toks)
406
407 @app.post("/v1/chat/completions")
408 def chat_completions():

Callers

nothing calls this directly

Calls 3

encode_messageFunction · 0.85
encode_roleFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…