1+ import Foundation
12import Hub
2- @_exported import TokenizersCore
33import Jinja
4- import Foundation
4+ @ _exported import TokenizersCore
55
66let specialTokenAttributes : [ String ] = [
77 " bos_token " ,
@@ -11,24 +11,24 @@ let specialTokenAttributes: [String] = [
1111 " pad_token " ,
1212 " cls_token " ,
1313 " mask_token " ,
14- " additional_special_tokens "
14+ " additional_special_tokens " ,
1515]
1616
17- open class PreTrainedTokenizerWithTemplates : PreTrainedTokenizer {
18- // I don't know why these need to be here. They are implemented in the protocol, **and** in the superclass.
19- public override func applyChatTemplate( messages: [ Message ] ) throws -> [ Int ] {
17+ open class PreTrainedTokenizerWithTemplates : PreTrainedTokenizer {
18+ /// I don't know why these need to be here. They are implemented in the protocol, **and** in the superclass.
19+ override public func applyChatTemplate( messages: [ Message ] ) throws -> [ Int ] {
2020 try applyChatTemplate ( messages: messages, addGenerationPrompt: true )
2121 }
2222
23- public override func applyChatTemplate( messages: [ Message ] , chatTemplate: ChatTemplateArgument ) throws -> [ Int ] {
23+ override public func applyChatTemplate( messages: [ Message ] , chatTemplate: ChatTemplateArgument ) throws -> [ Int ] {
2424 try applyChatTemplate ( messages: messages, chatTemplate: chatTemplate, addGenerationPrompt: true )
2525 }
2626
27- public override func applyChatTemplate( messages: [ Message ] , chatTemplate: String ) throws -> [ Int ] {
27+ override public func applyChatTemplate( messages: [ Message ] , chatTemplate: String ) throws -> [ Int ] {
2828 try applyChatTemplate ( messages: messages, chatTemplate: . literal( chatTemplate) , addGenerationPrompt: true )
2929 }
3030
31- public override func applyChatTemplate(
31+ override public func applyChatTemplate(
3232 messages: [ Message ] ,
3333 chatTemplate: ChatTemplateArgument ? = nil ,
3434 addGenerationPrompt: Bool = false ,
@@ -42,18 +42,18 @@ open class PreTrainedTokenizerWithTemplates : PreTrainedTokenizer {
4242 )
4343 }
4444
45- public override func applyChatTemplate(
45+ override public func applyChatTemplate(
4646 messages: [ Message ] ,
4747 chatTemplate: ChatTemplateArgument ? = nil ,
4848 addGenerationPrompt: Bool = false ,
4949 truncation: Bool = false ,
5050 maxLength: Int ? = nil ,
51- /// A list of tools (callable functions) that will be accessible to the model. If the template does not
52- /// support function calling, this argument will have no effect. Each tool should be passed as a JSON Schema,
53- /// giving the name, description and argument types for the tool. See the
54- /// [chat templating guide](https://huggingface.co/docs/transformers/main/en/chat_templating#automated-function-conversion-for-tool-use)
55- /// for more information.
56- /// Note: tool calling is not supported yet, it will be available in a future update.
51+ // A list of tools (callable functions) that will be accessible to the model. If the template does not
52+ // support function calling, this argument will have no effect. Each tool should be passed as a JSON Schema,
53+ // giving the name, description and argument types for the tool. See the
54+ // [chat templating guide](https://huggingface.co/docs/transformers/main/en/chat_templating#automated-function-conversion-for-tool-use)
55+ // for more information.
56+ // Note: tool calling is not supported yet, it will be available in a future update.
5757 tools: [ [ String : Any ] ] ? = nil ,
5858 additionalContext: [ String : Any ] ? = nil
5959 ) throws -> [ Int ] {
@@ -143,7 +143,7 @@ open class PreTrainedTokenizerWithTemplates : PreTrainedTokenizer {
143143 }
144144}
145145
146- // Template-enabled tokenizer classes
146+ /// Template-enabled tokenizer classes
147147/// See https://github.com/xenova/transformers.js/blob/1a9964fb09b8f54fcbeac46dc6aae8d76795809d/src/tokenizers.js#L3203 for these exceptions
148148class LlamaPreTrainedTokenizerWithTemplates : PreTrainedTokenizerWithTemplates {
149149 let isLegacy : Bool
@@ -174,8 +174,8 @@ struct PreTrainedTokenizerTemplateClasses {
174174 ]
175175}
176176
177- // Override AutoTokenizer to use template-enabled tokenizers
178- // See Sources/Tokenizers/Tokenizer.swift
177+ /// Override AutoTokenizer to use template-enabled tokenizers
178+ /// See Sources/Tokenizers/Tokenizer.swift
179179public extension AutoTokenizer {
180180 private static func tokenizerClassWithTemplates( for tokenizerConfig: Config ) -> PreTrainedTokenizerWithTemplates . Type {
181181 guard let tokenizerClassName = tokenizerConfig. tokenizerClass? . string ( ) else {
0 commit comments