From c645bfdd8782dbd0eae2f12cf670fbb06cc2db52 Mon Sep 17 00:00:00 2001 From: Jael Gu Date: Mon, 19 Jun 2023 18:41:27 +0800 Subject: [PATCH] Update README Signed-off-by: Jael Gu --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 882341b..e60ef04 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,41 @@ messages=[ answer = p(messages).get()[0] ``` +*Write a [retrieval-augmented generation pipeline](https://towhee.io/tasks/detail/pipeline/retrieval-augmented-generation) with explicit inputs/outputs name specifications:* + +```python +from towhee import pipe, ops + + +temp = '''Use the following pieces of context to answer the question at the end. +If you don't know the answer, just say that you don't know, don't try to make up an answer. + +{context} + +Question: {question} + +Helpful Answer: +''' + + +docs = ['You can install towhee via command `pip install towhee`.'] +history = [ + ('What is Towhee?', 'Towhee is an open-source machine learning pipeline that helps you encode your unstructured data into embeddings.') +] +question = 'How to install it?' + +p = ( + pipe.input('question', 'docs', 'history') + .map(('question', 'docs', 'history'), 'prompt', ops.prompt.template(temp, ['question', 'context'])) + .map('prompt', 'answer', + ops.LLM.OpenAI(api_key=OPENAI_API_KEY, temperature=0.5, max_tokens=100) + ) + .output('answer') +) + +answer = p(question, docs, history).get()[0] +``` +
## Factory Constructor