Browse Source
Parse output
Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
2 changed files with
4 additions and
5 deletions
-
README.md
-
hf_dolly.py
|
@ -30,7 +30,7 @@ p = ( |
|
|
|
|
|
|
|
|
history=[('Who won the world series in 2020?', 'The Los Angeles Dodgers won the World Series in 2020.')] |
|
|
history=[('Who won the world series in 2020?', 'The Los Angeles Dodgers won the World Series in 2020.')] |
|
|
question = 'Where was it played?' |
|
|
question = 'Where was it played?' |
|
|
answer = p(question, [], history) |
|
|
answer = p(question, [], history).get()[0] |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
<br /> |
|
|
<br /> |
|
|
|
@ -35,7 +35,7 @@ class HuggingfaceDolly(PyOperator): |
|
|
def __call__(self, messages: List[dict]): |
|
|
def __call__(self, messages: List[dict]): |
|
|
prompt = self.parse_inputs(messages) |
|
|
prompt = self.parse_inputs(messages) |
|
|
ans = self.pipeline(prompt) |
|
|
ans = self.pipeline(prompt) |
|
|
return ans |
|
|
return ans[0]['generated_text'] |
|
|
|
|
|
|
|
|
def parse_inputs(self, messages: List[dict]): |
|
|
def parse_inputs(self, messages: List[dict]): |
|
|
assert isinstance(messages, list), \ |
|
|
assert isinstance(messages, list), \ |
|
@ -43,9 +43,8 @@ class HuggingfaceDolly(PyOperator): |
|
|
prompt = messages[-1]['question'] |
|
|
prompt = messages[-1]['question'] |
|
|
history = '' |
|
|
history = '' |
|
|
for m in messages[:-1]: |
|
|
for m in messages[:-1]: |
|
|
for k, v in m.items(): |
|
|
for _, v in m.items(): |
|
|
line = k + ': ' + v + '\n' |
|
|
history += v + '\n' |
|
|
history += line |
|
|
|
|
|
return prompt + '\n' + history |
|
|
return prompt + '\n' + history |
|
|
|
|
|
|
|
|
|
|
|
|
|
|