File size: 1,259 Bytes
cbc00ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # -*- coding: utf-8 -*-
# Copyright (c) Alibaba, Inc. and its affiliates.
import os
from typing import List
from dashscope.common.error import UnsupportedModel
from dashscope.tokenizers.qwen_tokenizer import QwenTokenizer
from .tokenizer_base import Tokenizer
QWEN_SERIALS = ["qwen-7b-chat", "qwen-turbo", "qwen-plus", "qwen-max"]
current_path = os.path.dirname(os.path.abspath(__file__))
root_path = os.path.dirname(current_path)
def get_tokenizer(model: str) -> Tokenizer:
"""Get a tokenizer based on model name.
Args:
model (str): The model name.
Raises:
UnsupportedModel: Not support model
Returns:
Tokenizer: The `Tokenizer` of the model.
"""
if model in QWEN_SERIALS:
return QwenTokenizer(
os.path.join(root_path, "resources", "qwen.tiktoken"),
)
elif model.startswith("qwen"):
return QwenTokenizer(
os.path.join(root_path, "resources", "qwen.tiktoken"),
)
else:
raise UnsupportedModel(
f"Not support model: {model}, currently only support qwen models.",
)
def list_tokenizers() -> List[str]:
"""List support models
Returns:
List[str]: The model list.
"""
return QWEN_SERIALS
|