Skip to content

Commit

Permalink
feat: Add ability to load chat format from huggingface autotokenizer …
Browse files Browse the repository at this point in the history
…or tokenizer_config.json files.
  • Loading branch information
abetlen committed Jan 19, 2024
1 parent 48c3b77 commit b8fc1c7
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 316 deletions.
25 changes: 24 additions & 1 deletion llama_cpp/_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import sys

import sys, traceback
import sys
from typing import Any, Dict

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

self.os.close(self.old_stdout_fileno)
self.os.close(self.old_stderr_fileno)


class MetaSingleton(type):
"""
Metaclass for implementing the Singleton pattern.
"""

_instances: Dict[type, Any] = {}

def __call__(cls, *args: Any, **kwargs: Any) -> Any:
if cls not in cls._instances:
cls._instances[cls] = super(MetaSingleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]


class Singleton(object, metaclass=MetaSingleton):
"""
Base class for implementing the Singleton pattern.
"""

def __init__(self):
super(Singleton, self).__init__()
Loading

0 comments on commit b8fc1c7

Please sign in to comment.