mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-26 19:34:35 +00:00
py: if LICENSE exist then include a copy of it
This commit is contained in:
parent
1ef14b3007
commit
323bf80091
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user