|
|
|
# question-answer
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Desription
|
|
|
|
|
|
|
|
Prompt to answer a question.
|
|
|
|
|
|
|
|
|
|
|
|
<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').context
|
|
|
|
|
|
|
|
|
|
|
|
p = (
|
|
|
|
pipe.input('question', 'docs', 'history')
|
|
|
|
.map(('question', 'docs', 'history'), 'prompt', ops.prompt.question_answer())
|
|
|
|
.map('prompt', 'answer', ops.LLM.OpenAI())
|
|
|
|
.output('answer')
|
|
|
|
)
|
|
|
|
|
|
|
|
an1 = p('Tell me something about Towhee', [towhee_docs], []).get()[0]
|
|
|
|
|
|
|
|
an2 = p('Give an example', [towhee_docs], [('Tell me something about Towhee', an1)]).get()[0]
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Factory Constructor
|
|
|
|
|
|
|
|
Create the operator via the following factory method:
|
|
|
|
|
|
|
|
***ops.prompt.question_answer()***
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
**temp: str**
|
|
|
|
|
|
|
|
User-defined prompt, must contain {context} and {question}"
|
|
|
|
|
|
|
|
**llm_name: str**
|
|
|
|
|
|
|
|
Pre-defined prompt, currently supports openai and dolly, openai prompt is used by default."
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
**Returns:** *List[Dict]*
|