template.py 639 B

1234567891011121314151617181920
  1. from difflib import SequenceMatcher
  2. import json
  3. with open("model_prompts.json", "r") as f:
  4. model_prompts = json.load(f)
  5. def template(model, prompt):
  6. max_ratio = 0
  7. closest_key = ""
  8. model_name = model.lower()
  9. # Find the specialized prompt with the closest name match
  10. for key in model_prompts.keys():
  11. ratio = SequenceMatcher(None, model_name, key).ratio()
  12. if ratio > max_ratio:
  13. max_ratio = ratio
  14. closest_key = key
  15. # Return the value of the closest match
  16. p = model_prompts.get(closest_key) # TODO: provide a better default template
  17. return p.format(prompt=prompt)