Spaces:
Runtime error
Runtime error
File size: 589 Bytes
8a8ca58 757dddf 8a8ca58 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from loguru import logger
import ollama
def models():
return sorted([x['model'] for x in ollama.list()['models']], key=lambda x: (not x.startswith("openhermes"), x))
def ask(model, system_prompt, pre_prompt, question):
messages = [
{'role': 'system', 'content': f"{system_prompt} {pre_prompt}", },
{'role': 'user', 'content': f"{question}", },
]
logger.debug(f"<< {model} << {question}")
response = ollama.chat(model=model, messages=messages)
answer = response['message']['content']
logger.debug(f">> {model} >> {answer}")
return answer
|