logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

21 lines
670 B

from typing import List, Tuple, Dict, Optional
from towhee.operator import PyOperator
class TemplatePrompt(PyOperator):
def __init__(self, temp: str):
super().__init__()
self._template = temp
def __call__(self, **kwargs) -> List[Dict[str, str]]:
history = kwargs.get('history', [])
prompt_str = self._template.format(**kwargs)
ret = [{'question': prompt_str}]
if not isinstance(history, list):
return ret
else:
history_data = []
for item in history:
history_data.append({'question': item[0], 'answer': item[1]})
return history_data + ret