|
|
|
# question-answer
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Desription
|
|
|
|
|
|
|
|
Prompt Template.
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Code Example
|
|
|
|
|
|
|
|
### Example
|
|
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
|
|
|
from towhee import ops, pipe
|
|
|
|
import requests
|
|
|
|
|
|
|
|
towhee_docs = requests.get('https://raw.githubusercontent.com/towhee-io/towhee/main/README.md').content
|
|
|
|
|
|
|
|
temp = """{question}
|
|
|
|
|
|
|
|
input:
|
|
|
|
{context}
|
|
|
|
"""
|
|
|
|
|
|
|
|
p = (
|
|
|
|
pipe.input('question', 'doc', 'history')
|
|
|
|
.map('docs', 'docs', lambda x: x[:2000])
|
|
|
|
.map(('question', 'doc', 'history'), 'prompt', ops.prompt.template(temp, ['question', 'context']))
|
|
|
|
.map('prompt', 'answer', ops.LLM.OpenAI())
|
|
|
|
.output('answer')
|
|
|
|
)
|
|
|
|
|
|
|
|
an1 = p('Tell me something about Towhee', towhee_docs, []).get()[0]
|
|
|
|
print(an1)
|
|
|
|
|
|
|
|
an2 = p('How to use it', towhee_docs, [('Tell me something about Towhee', an1)]).get()[0]
|
|
|
|
print(an2)
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Factory Constructor
|
|
|
|
|
|
|
|
Create the operator via the following factory method:
|
|
|
|
|
|
|
|
***ops.prompt.template(temp, keys)***
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
**Returns:** *List[Dict]*
|