template.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from difflib import SequenceMatcher
  2. model_prompts = {
  3. "alpaca": """Below is an instruction that describes a task. Write a response that appropriately completes the request.
  4. ### Instruction:
  5. {prompt}
  6. ### Response:
  7. """,
  8. "oasst": "<|prompter|>{prompt}<|endoftext|><|assistant|>",
  9. "vicuna": """A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.
  10. USER: {prompt}
  11. ASSISTANT:""",
  12. "hermes": """### Instruction:
  13. {prompt}
  14. ### Response:
  15. """,
  16. "gpt4": """### Instruction:
  17. {prompt}
  18. ### Response:
  19. """,
  20. "qlora": """### Human: {prompt}
  21. ### Assistant:""",
  22. "tulu": """<|user|>
  23. {prompt}
  24. <|assistant|>
  25. (include newline)""",
  26. "wizardlm-7b": """{prompt}
  27. ### Response:""",
  28. "wizardlm-13b": """{prompt}
  29. ### Response:""",
  30. "wizardlm-30b": """{prompt}
  31. ### Response:""",
  32. }
  33. def template(model, prompt):
  34. max_ratio = 0
  35. closest_key = ""
  36. model_name = model.lower()
  37. # Find the specialized prompt with the closest name match
  38. for key in model_prompts.keys():
  39. ratio = SequenceMatcher(None, model_name, key).ratio()
  40. if ratio > max_ratio:
  41. max_ratio = ratio
  42. closest_key = key
  43. # Return the value of the closest match
  44. p = model_prompts.get(closest_key) # TODO: provide a better default template
  45. return p.format(prompt=prompt)