Allow both .so and .dylib extensions for macos
This commit is contained in:
parent
c9e79c6681
commit
607d217caa
1 changed files with 19 additions and 14 deletions
|
@ -15,28 +15,32 @@ from ctypes import (
|
||||||
c_size_t,
|
c_size_t,
|
||||||
)
|
)
|
||||||
import pathlib
|
import pathlib
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
# Load the library
|
# Load the library
|
||||||
def _load_shared_library(lib_base_name: str):
|
def _load_shared_library(lib_base_name: str):
|
||||||
# Determine the file extension based on the platform
|
|
||||||
if sys.platform.startswith("linux"):
|
|
||||||
lib_ext = ".so"
|
|
||||||
elif sys.platform == "darwin":
|
|
||||||
lib_ext = ".so"
|
|
||||||
elif sys.platform == "win32":
|
|
||||||
lib_ext = ".dll"
|
|
||||||
else:
|
|
||||||
raise RuntimeError("Unsupported platform")
|
|
||||||
|
|
||||||
# Construct the paths to the possible shared library names
|
# Construct the paths to the possible shared library names
|
||||||
_base_path = pathlib.Path(__file__).parent.resolve()
|
_base_path = pathlib.Path(__file__).parent.resolve()
|
||||||
# Searching for the library in the current directory under the name "libllama" (default name
|
# Searching for the library in the current directory under the name "libllama" (default name
|
||||||
# for llamacpp) and "llama" (default name for this repo)
|
# for llamacpp) and "llama" (default name for this repo)
|
||||||
_lib_paths = [
|
_lib_paths: List[pathlib.Path] = []
|
||||||
_base_path / f"lib{lib_base_name}{lib_ext}",
|
# Determine the file extension based on the platform
|
||||||
_base_path / f"{lib_base_name}{lib_ext}",
|
if sys.platform.startswith("linux"):
|
||||||
|
_lib_paths += [
|
||||||
|
_base_path / f"lib{lib_base_name}.so",
|
||||||
]
|
]
|
||||||
|
elif sys.platform == "darwin":
|
||||||
|
_lib_paths += [
|
||||||
|
_base_path / f"lib{lib_base_name}.so",
|
||||||
|
_base_path / f"lib{lib_base_name}.dylib",
|
||||||
|
]
|
||||||
|
elif sys.platform == "win32":
|
||||||
|
_lib_paths += [
|
||||||
|
_base_path / f"{lib_base_name}.dll",
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Unsupported platform")
|
||||||
|
|
||||||
if "LLAMA_CPP_LIB" in os.environ:
|
if "LLAMA_CPP_LIB" in os.environ:
|
||||||
lib_base_name = os.environ["LLAMA_CPP_LIB"]
|
lib_base_name = os.environ["LLAMA_CPP_LIB"]
|
||||||
|
@ -160,6 +164,7 @@ llama_progress_callback = ctypes.CFUNCTYPE(None, c_float, c_void_p)
|
||||||
# bool use_mlock; // force system to keep model in RAM
|
# bool use_mlock; // force system to keep model in RAM
|
||||||
# bool embedding; // embedding mode only
|
# bool embedding; // embedding mode only
|
||||||
|
|
||||||
|
|
||||||
# // called with a progress value between 0 and 1, pass NULL to disable
|
# // called with a progress value between 0 and 1, pass NULL to disable
|
||||||
# llama_progress_callback progress_callback;
|
# llama_progress_callback progress_callback;
|
||||||
# // context pointer passed to the progress callback
|
# // context pointer passed to the progress callback
|
||||||
|
|
Loading…
Reference in a new issue