mirror of
https://github.com/tcsenpai/ollama.git
synced 2025-06-08 04:05:20 +00:00
20 lines
618 B
Python
20 lines
618 B
Python
import os
|
|
from difflib import SequenceMatcher
|
|
from jinja2 import Environment, PackageLoader
|
|
|
|
|
|
def template(model, prompt):
|
|
best_ratio = 0
|
|
best_template = ''
|
|
|
|
environment = Environment(loader=PackageLoader(__name__, 'templates'))
|
|
for template in environment.list_templates():
|
|
base, _ = os.path.splitext(template)
|
|
ratio = SequenceMatcher(None, os.path.basename(model.lower()), base).ratio()
|
|
if ratio > best_ratio:
|
|
best_ratio = ratio
|
|
best_template = template
|
|
|
|
template = environment.get_template(best_template)
|
|
return template.render(prompt=prompt)
|