(dedicated.token)
- tokenization - Tokenization
- detokenization - Detokenization
By giving a text input, generate a tokenized output of token IDs.
import os
from friendli import SyncFriendli
with SyncFriendli(
token=os.getenv("FRIENDLI_TOKEN", ""),
) as friendli:
res = friendli.dedicated.token.tokenization(
model="(endpoint-id)", prompt="What is generative AI?"
)
# Handle response
print(res)| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
model |
str | ✔️ | ID of target endpoint. If you want to send request to specific adapter, use the format "YOUR_ENDPOINT_ID:YOUR_ADAPTER_ROUTE". Otherwise, you can just use "YOUR_ENDPOINT_ID" alone. | (endpoint-id) |
prompt |
str | ✔️ | Input text prompt to tokenize. | What is generative AI? |
x_friendli_team |
OptionalNullable[str] | ➖ | ID of team to run requests as (optional parameter). | |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.DedicatedTokenizationSuccess
| Error Type | Status Code | Content Type |
|---|---|---|
| models.SDKError | 4XX, 5XX | */* |
By giving a list of tokens, generate a detokenized output text string.
import os
from friendli import SyncFriendli
with SyncFriendli(
token=os.getenv("FRIENDLI_TOKEN", ""),
) as friendli:
res = friendli.dedicated.token.detokenization(
model="(endpoint-id)",
tokens=[
128000,
3923,
374,
1803,
1413,
15592,
30,
],
)
# Handle response
print(res)| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
model |
str | ✔️ | ID of target endpoint. If you want to send request to specific adapter, use the format "YOUR_ENDPOINT_ID:YOUR_ADAPTER_ROUTE". Otherwise, you can just use "YOUR_ENDPOINT_ID" alone. | (endpoint-id) |
tokens |
List[int] | ✔️ | A token sequence to detokenize. | [ 128000, 3923, 374, 1803, 1413, 15592, 30 ] |
x_friendli_team |
OptionalNullable[str] | ➖ | ID of team to run requests as (optional parameter). | |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
models.DedicatedDetokenizationSuccess
| Error Type | Status Code | Content Type |
|---|---|---|
| models.SDKError | 4XX, 5XX | */* |