ollama/lib/template.py

21 lines
639 B
Python
Raw Normal View History

2023-06-26 17:41:16 +00:00
from difflib import SequenceMatcher
2023-06-26 18:03:49 +00:00
import json
2023-06-26 17:41:16 +00:00
2023-06-26 18:03:49 +00:00
with open("model_prompts.json", "r") as f:
model_prompts = json.load(f)
2023-06-26 17:41:16 +00:00
def template(model, prompt):
max_ratio = 0
closest_key = ""
model_name = model.lower()
# Find the specialized prompt with the closest name match
for key in model_prompts.keys():
ratio = SequenceMatcher(None, model_name, key).ratio()
if ratio > max_ratio:
max_ratio = ratio
closest_key = key
# Return the value of the closest match
2023-06-26 17:56:54 +00:00
p = model_prompts.get(closest_key) # TODO: provide a better default template
2023-06-26 17:41:16 +00:00
return p.format(prompt=prompt)