MCPcopy
hub / github.com/llmware-ai/llmware / prepare_local_model

Method prepare_local_model

llmware/models.py:1119–1216  ·  view source on GitHub ↗

Resolves obtaining a valid local path to the required model components. 1. Identify if model is available in local path. -- if custom path provided, then validate from that path. -- if custom loader provided, then use custom loader to complete this step

(self, model_card, custom_loader=None, api_key=None, **kwargs)

Source from the content-addressed store, hash-verified

1117 return my_model
1118
1119 def prepare_local_model(self, model_card, custom_loader=None, api_key=None, **kwargs):
1120
1121 """ Resolves obtaining a valid local path to the required model components.
1122
1123 1. Identify if model is available in local path.
1124 -- if custom path provided, then validate from that path.
1125 -- if custom loader provided, then use custom loader to complete this step
1126 -- once local path resolved:
1127 -- Validate that local path contains the required elements
1128 -- Return the loading path to load_the_model_for_inference
1129
1130 2. If not available locally, then need to fetch.
1131 -- Use the fetch method provided in the Model Card
1132 -- if not provided, then use a default for model class
1133 -- need to provide error-handling if download fails
1134
1135 """
1136
1137 # Step 1 - resolve local path
1138
1139 if custom_loader:
1140 return custom_loader(model_card, api_key=api_key)
1141
1142 if "custom_model_repo" in model_card:
1143 custom_repo = model_card["custom_model_repo"]
1144 else:
1145 custom_repo = None
1146
1147 if custom_repo and os.path.exists(custom_repo):
1148
1149 # if path exists ... (if null result, then will continue down main resolve path)
1150
1151 custom_local_path = self.check_custom_local_repo(model_card, api_key=api_key)
1152 if custom_local_path:
1153 return custom_local_path
1154
1155 # Main resolve path
1156
1157 # check for llmware path & create if not already set up
1158 if not os.path.exists(LLMWareConfig.get_llmware_path()):
1159 # if not explicitly set up by user, then create folder directory structure
1160 LLMWareConfig.setup_llmware_workspace()
1161
1162 if not os.path.exists(LLMWareConfig.get_model_repo_path()):
1163 os.mkdir(LLMWareConfig.get_model_repo_path())
1164
1165 # strip '/' from model name
1166 model_folder_name = model_card["model_name"].split("/")[-1]
1167
1168 model_location = os.path.join(LLMWareConfig.get_model_repo_path(), model_folder_name)
1169
1170 go_ahead = False
1171
1172 if os.path.exists(model_location):
1173
1174 go_ahead = True
1175
1176 model_files = os.listdir(model_location)

Callers 1

load_modelMethod · 0.95

Calls 7

fetch_resolveMethod · 0.95
LLMWareExceptionClass · 0.90
get_llmware_pathMethod · 0.80
get_model_repo_pathMethod · 0.80
itemsMethod · 0.80

Tested by

no test coverage detected