diff --git a/examples/convert_legacy_llama.py b/examples/convert_legacy_llama.py index 9ab9ab06e..b82cf2808 100755 --- a/examples/convert_legacy_llama.py +++ b/examples/convert_legacy_llama.py @@ -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) diff --git a/gguf-py/gguf/constants.py b/gguf-py/gguf/constants.py index 59ffd92ea..f9d34dd30 100644 --- a/gguf-py/gguf/constants.py +++ b/gguf-py/gguf/constants.py @@ -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 diff --git a/gguf-py/gguf/gguf_writer.py b/gguf-py/gguf/gguf_writer.py index 76385a828..8e0e9e889 100644 --- a/gguf-py/gguf/gguf_writer.py +++ b/gguf-py/gguf/gguf_writer.py @@ -529,6 +529,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) diff --git a/gguf-py/gguf/metadata.py b/gguf-py/gguf/metadata.py index ea4d02705..cb1119f50 100644 --- a/gguf-py/gguf/metadata.py +++ b/gguf-py/gguf/metadata.py @@ -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 @@ -379,6 +380,7 @@ class Metadata: use_model_card_metadata("license", "license") use_model_card_metadata("license_name", "license_name") use_model_card_metadata("license_link", "license_link") + use_model_card_metadata("license_content", "license_content") use_array_model_card_metadata("tags", "tags") use_array_model_card_metadata("tags", "pipeline_tag") @@ -431,6 +433,14 @@ 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 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): @@ -463,6 +473,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)