Merge 928aa66a92
into 19f65187cb
This commit is contained in:
commit
87b78eea62
4 changed files with 20 additions and 0 deletions
|
@ -458,6 +458,7 @@ LazyModel: TypeAlias = 'dict[str, LazyTensor]'
|
|||
|
||||
ModelFormat: TypeAlias = Literal['ggml', 'torch', 'safetensors', 'none']
|
||||
|
||||
|
||||
@dataclass
|
||||
class ModelPlus:
|
||||
model: LazyModel
|
||||
|
@ -810,6 +811,8 @@ class OutputFile:
|
|||
self.gguf.add_license_name(metadata.license_name)
|
||||
if metadata.license_link is not None:
|
||||
self.gguf.add_license_link(metadata.license_link)
|
||||
if metadata.license_content is not None:
|
||||
self.gguf.add_license_content(metadata.license_content)
|
||||
|
||||
if metadata.url is not None:
|
||||
self.gguf.add_url(metadata.url)
|
||||
|
|
|
@ -43,6 +43,7 @@ class Keys:
|
|||
LICENSE = "general.license"
|
||||
LICENSE_NAME = "general.license.name"
|
||||
LICENSE_LINK = "general.license.link"
|
||||
LICENSE_CONTENT = "general.license.content"
|
||||
|
||||
# Typically represents the converted GGUF repo (Unless native)
|
||||
URL = "general.url" # Model Website/Paper
|
||||
|
|
|
@ -530,6 +530,9 @@ class GGUFWriter:
|
|||
def add_license_link(self, license: str) -> None:
|
||||
self.add_string(Keys.General.LICENSE_LINK, license)
|
||||
|
||||
def add_license_content(self, license: str) -> None:
|
||||
self.add_string(Keys.General.LICENSE_CONTENT, license)
|
||||
|
||||
def add_url(self, url: str) -> None:
|
||||
self.add_string(Keys.General.URL, url)
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ class Metadata:
|
|||
license: Optional[str] = None
|
||||
license_name: Optional[str] = None
|
||||
license_link: Optional[str] = None
|
||||
license_content: Optional[str] = None
|
||||
base_models: Optional[list[dict]] = None
|
||||
tags: Optional[list[str]] = None
|
||||
languages: Optional[list[str]] = None
|
||||
|
@ -77,6 +78,7 @@ class Metadata:
|
|||
metadata.size_label = metadata_override.get(Keys.General.SIZE_LABEL, metadata.size_label)
|
||||
metadata.license_name = metadata_override.get(Keys.General.LICENSE_NAME, metadata.license_name)
|
||||
metadata.license_link = metadata_override.get(Keys.General.LICENSE_LINK, metadata.license_link)
|
||||
metadata.license_content = metadata_override.get(Keys.General.LICENSE_CONTENT, metadata.license_content)
|
||||
|
||||
metadata.url = metadata_override.get(Keys.General.URL, metadata.url)
|
||||
metadata.doi = metadata_override.get(Keys.General.DOI, metadata.doi)
|
||||
|
@ -518,6 +520,15 @@ class Metadata:
|
|||
if metadata.size_label is None and size_label is not None:
|
||||
metadata.size_label = size_label
|
||||
|
||||
# Detect LICENSE file and include a copy
|
||||
#########################################
|
||||
if isinstance(metadata.license_link, str) and not (metadata.license_link.startswith("http://") or metadata.license_link.startswith("https://")):
|
||||
if metadata.license_content is None:
|
||||
standard_license_file_path = Path("LICENSE")
|
||||
if standard_license_file_path.is_file():
|
||||
with open(standard_license_file_path, 'r') as file:
|
||||
metadata.license_content = file.read()
|
||||
|
||||
return metadata
|
||||
|
||||
def set_gguf_meta_model(self, gguf_writer: gguf.GGUFWriter):
|
||||
|
@ -553,6 +564,8 @@ class Metadata:
|
|||
gguf_writer.add_license_name(self.license_name)
|
||||
if self.license_link is not None:
|
||||
gguf_writer.add_license_link(self.license_link)
|
||||
if self.license_content is not None:
|
||||
gguf_writer.add_license_content(self.license_content)
|
||||
|
||||
if self.url is not None:
|
||||
gguf_writer.add_url(self.url)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue