public class TikTokensUtil extends Object
Constructor and Description |
---|
TikTokensUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
decode(@NotNull com.knuddels.jtokkit.api.Encoding enc,
@NotNull List<Integer> encoded)
通过Encoding和encoded数组反推text信息
|
static String |
decode(@NotNull com.knuddels.jtokkit.api.EncodingType encodingType,
@NotNull List<Integer> encoded)
通过EncodingType和encoded编码数组,反推字符串文本
|
static String |
decode(@NotNull String modelName,
@NotNull List<Integer> encoded)
通过模型名称和encoded编码数组,反推字符串文本
|
static List<Integer> |
encode(@NotNull com.knuddels.jtokkit.api.Encoding enc,
String text)
通过Encoding和text获取编码数组
|
static List<Integer> |
encode(@NotNull com.knuddels.jtokkit.api.EncodingType encodingType,
String text)
获取encode的编码数组
|
static List<Integer> |
encode(@NotNull String modelName,
String text)
获取encode的编码数组,通过模型名称
|
static com.knuddels.jtokkit.api.Encoding |
getEncoding(@NotNull com.knuddels.jtokkit.api.EncodingType encodingType)
获取一个Encoding对象,通过Encoding类型
|
static com.knuddels.jtokkit.api.Encoding |
getEncoding(@NotNull String modelName)
获取一个Encoding对象,通过模型名称
|
static int |
tokens(@NotNull com.knuddels.jtokkit.api.Encoding enc,
String text)
通过Encoding计算text信息的tokens
|
static int |
tokens(@NotNull com.knuddels.jtokkit.api.EncodingType encodingType,
String text)
计算指定字符串的tokens,通过EncodingType
|
static int |
tokens(@NotNull String modelName,
@NotNull List<Message> messages)
通过模型名称计算messages获取编码数组
参考官方的处理逻辑:
https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
|
static int |
tokens(@NotNull String modelName,
String text)
通过模型名称, 计算指定字符串的tokens
|
public static List<Integer> encode(@NotNull @NotNull com.knuddels.jtokkit.api.Encoding enc, String text)
enc
- text
- public static int tokens(@NotNull @NotNull com.knuddels.jtokkit.api.Encoding enc, String text)
enc
- text
- public static String decode(@NotNull @NotNull com.knuddels.jtokkit.api.Encoding enc, @NotNull @NotNull List<Integer> encoded)
enc
- encoded
- public static com.knuddels.jtokkit.api.Encoding getEncoding(@NotNull @NotNull com.knuddels.jtokkit.api.EncodingType encodingType)
encodingType
- public static List<Integer> encode(@NotNull @NotNull com.knuddels.jtokkit.api.EncodingType encodingType, String text)
text
- public static int tokens(@NotNull @NotNull com.knuddels.jtokkit.api.EncodingType encodingType, String text)
encodingType
- text
- public static String decode(@NotNull @NotNull com.knuddels.jtokkit.api.EncodingType encodingType, @NotNull @NotNull List<Integer> encoded)
encodingType
- encoded
- public static com.knuddels.jtokkit.api.Encoding getEncoding(@NotNull @NotNull String modelName)
modelName
- public static List<Integer> encode(@NotNull @NotNull String modelName, String text)
text
- public static int tokens(@NotNull @NotNull String modelName, String text)
modelName
- text
- public static int tokens(@NotNull @NotNull String modelName, @NotNull @NotNull List<Message> messages)
modelName
- 模型名称messages
- 消息体Copyright © 2023 grt1228. All rights reserved.