Skip to content

Commit b8fc1c7

Browse files
committed
feat: Add ability to load chat format from huggingface autotokenizer or tokenizer_config.json files.
1 parent 48c3b77 commit b8fc1c7

File tree

6 files changed

+355
-316
lines changed

6 files changed

+355
-316
lines changed

llama_cpp/_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
22
import sys
33

4-
import sys, traceback
4+
import sys
5+
from typing import Any, Dict
56

67
# Avoid "LookupError: unknown encoding: ascii" when open() called in a destructor
78
outnull_file = open(os.devnull, "w")
@@ -55,3 +56,25 @@ def __exit__(self, *_):
5556

5657
self.os.close(self.old_stdout_fileno)
5758
self.os.close(self.old_stderr_fileno)
59+
60+
61+
class MetaSingleton(type):
62+
"""
63+
Metaclass for implementing the Singleton pattern.
64+
"""
65+
66+
_instances: Dict[type, Any] = {}
67+
68+
def __call__(cls, *args: Any, **kwargs: Any) -> Any:
69+
if cls not in cls._instances:
70+
cls._instances[cls] = super(MetaSingleton, cls).__call__(*args, **kwargs)
71+
return cls._instances[cls]
72+
73+
74+
class Singleton(object, metaclass=MetaSingleton):
75+
"""
76+
Base class for implementing the Singleton pattern.
77+
"""
78+
79+
def __init__(self):
80+
super(Singleton, self).__init__()

0 commit comments

Comments
 (0)