From 97899aba742fbf98c128ae620f067777536d7057 Mon Sep 17 00:00:00 2001 From: Jael Gu Date: Mon, 19 Jun 2023 16:07:55 +0800 Subject: [PATCH] Add pipeline example Signed-off-by: Jael Gu --- README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b2d0932..87b1774 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ from towhee import pipe, ops p = ( pipe.input('messages') - .map('messages', 'answer', ops.LLM.Ernie(api_key=ERNIE_API_KEY, secret_key=ERNIE_SECRET_KEY)) + .map('messages', 'answer', ops.LLM.Ernie(api_key=ERNIE_API_KEY, secret_key=ERNIE_SECRET_KEY, temperature=0.5)) .output('answer') ) @@ -34,6 +34,38 @@ 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 = '''根据以下材料回答最末尾的问题: + +{context} + +问题:{question} +''' + + +docs = ['你可以通过`pip install towhee` 安装 Towhee。'] +history = [ + ('什么是 Towhee?', 'Towhee 是一个开源项目,可以将非结构化数据转换为向量。') +] +question = '怎么安装它?' + +p = ( + pipe.input('question', 'docs', 'history') + .map(('question', 'docs', 'history'), 'prompt', ops.prompt.template(temp, ['question', 'context'])) + .map('prompt', 'answer', + ops.LLM.Ernie(api_key=ERNIE_API_KEY, secret_key=ERNIE_SECRET_KEY) + ) + .output('answer') +) + +answer = p(question, docs, history).get()[0] +``` +
## Factory Constructor 接口说明 @@ -55,7 +87,7 @@ The Ernie Secret key in string, defaults to None. If None, it will use the envir ***\*\*kwargs*** -Other OpenAI parameters such as temperature, etc. +Other Ernie parameters such as temperature, etc.