AI-Discord-Bot/tests/test_modelfile.py

40 lines
1 KiB
Python
Raw Permalink Normal View History

import os
from src.modelfile import parse_mod_file, load_modfile_if_exists
def test_parse_simple_mod(tmp_path):
content = '''
NAME Gojo
FROM gemma3:12b
PARAMETER temperature 0.7
SYSTEM """
You are Gojo, sarcastic and helpful.
"""
TEMPLATE """
{{ .System }}
{{ .Prompt }}
"""
'''
p = tmp_path / "gojo.mod"
p.write_text(content)
parsed = parse_mod_file(str(p))
assert parsed['name'] == 'Gojo'
assert parsed['base_model'] == 'gemma3:12b'
assert parsed['params']['temperature'] == 0.7
assert 'Gojo' in parsed['system'] or 'Gojo' in parsed['template']
def test_parse_json_mod(tmp_path):
data = {
"name": "json-persona",
"from": "gemma3:12b",
"system": "You are JSON persona",
"params": {"temperature": 0.5}
}
p = tmp_path / "j.mod.json"
p.write_text(str(data).replace("'", '"'))
parsed = parse_mod_file(str(p))
assert parsed['name'] == 'json-persona'
assert parsed['base_model'] == 'gemma3:12b'
assert parsed['params']['temperature'] == 0.5