[New Model] Devstral support (#6547)
Signed-off-by: Xinyuan Tong <justinning0323@outlook.com>
This commit is contained in:
@@ -2169,3 +2169,51 @@ class Withable(Generic[T]):
|
||||
finally:
|
||||
assert self._value is new_value
|
||||
self._value = None
|
||||
|
||||
|
||||
def find_local_repo_dir(repo_id: str, revision: Optional[str] = None) -> Optional[str]:
|
||||
import huggingface_hub as hf
|
||||
|
||||
# Build cache path
|
||||
cache_path = os.path.join(
|
||||
hf.constants.HF_HUB_CACHE,
|
||||
hf.constants.REPO_ID_SEPARATOR.join(["models", *repo_id.split("/")]),
|
||||
)
|
||||
|
||||
# Get revision from main ref if not specified
|
||||
if not revision:
|
||||
ref_path = os.path.join(cache_path, "refs", "main")
|
||||
if os.path.isfile(ref_path):
|
||||
with open(ref_path) as f:
|
||||
revision = f.read().strip()
|
||||
|
||||
# List files from revision directory
|
||||
if revision:
|
||||
rev_dir = os.path.join(cache_path, "snapshots", revision)
|
||||
if os.path.isdir(rev_dir):
|
||||
return rev_dir
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def read_system_prompt_from_file(model_name: str) -> str:
|
||||
"""Read system prompt from a file in the HuggingFace cache directory.
|
||||
|
||||
Args:
|
||||
model_name: The model name to construct the file path
|
||||
|
||||
Returns:
|
||||
The system prompt content from the file, or empty string if file not found
|
||||
"""
|
||||
try:
|
||||
local_repo_dir = find_local_repo_dir(model_name)
|
||||
if local_repo_dir:
|
||||
system_prompt_file = os.path.join(local_repo_dir, "SYSTEM_PROMPT.txt")
|
||||
if os.path.exists(system_prompt_file):
|
||||
with open(system_prompt_file, "r", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
return ""
|
||||
except Exception:
|
||||
# If anything fails, return empty string
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user