logo
Llama-2
repo-copy-icon

copied

Browse Source

Update

Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
Jael Gu 1 year ago
parent
commit
cc360263db
  1. 4
      README.md
  2. 8
      llama2.py

4
README.md

@ -25,7 +25,7 @@ Use the default model to continue the conversation from given messages.
```python ```python
from towhee import ops from towhee import ops
chat = ops.LLM.Llama_2('path/to/model_file.bin', max_tokens=2048, echo=True)
chat = ops.LLM.Llama_2('path/to/model_file.bin', max_tokens=2048)
message = [{"question": "Building a website can be done in 10 simple steps:"}] message = [{"question": "Building a website can be done in 10 simple steps:"}]
answer = chat(message) answer = chat(message)
@ -39,7 +39,7 @@ from towhee import pipe, ops
p = ( p = (
pipe.input('question', 'docs', 'history') pipe.input('question', 'docs', 'history')
.map(('question', 'docs', 'history'), 'prompt', ops.prompt.question_answer()) .map(('question', 'docs', 'history'), 'prompt', ops.prompt.question_answer())
.map('prompt', 'answer', ops.LLM.Llama_2('llama-2-7b-chat'))
.map('prompt', 'answer', ops.LLM.Llama_2('llama-2-7b-chat', stop='</s>'))
.output('answer') .output('answer')
) )

8
llama2.py

@ -57,15 +57,15 @@ class LlamaCpp(PyOperator):
for m in messages: for m in messages:
for k, v in m.items(): for k, v in m.items():
if k == 'system': if k == 'system':
prompt += f'''[INST] <<SYS>> {v} <</SYS>> [/INST]\n'''
prompt += f'''[INST] <<SYS>> {v} <</SYS>>\n'''
elif k == 'question': elif k == 'question':
prompt += f'''[INST] {v} [/INST]\n'''
prompt += f''' {v} [/INST]\n'''
elif k == 'answer': elif k == 'answer':
prompt += f'''{v}\n'''
prompt += f''' {v} '''
else: else:
raise KeyError(f'Invalid key of message: {k}') raise KeyError(f'Invalid key of message: {k}')
if len(prompt) > 0: if len(prompt) > 0:
prompt = '<s> ' + prompt + ' </s>' + f' {question}'
prompt = '<s> ' + prompt + ' </s>' + f'<s> [INST] {question} [/INST]'
else: else:
prompt = question prompt = question
return prompt return prompt

Loading…
Cancel
Save