logo
Ernie
repo-copy-icon

copied

Browse Source

update readme

Signed-off-by: ChengZi <chen.zhang@zilliz.com>
main
ChengZi 1 year ago
parent
commit
4ae8e06378
  1. 20
      README.md
  2. 4
      ernie_chat.py
  3. 3
      requirements.txt

20
README.md

@ -7,10 +7,10 @@
## Description 描述
A LLM operator generates answer given prompt in messages using a large language model or service.
This operator is implemented with Ernie Bot from [Baidu](https://cloud.baidu.com/wenxin.html).
Please note you will need [Ernie API key & Secret key](https://ai.baidu.com/ai-doc/REFERENCE/Lkru0zoz4) to access the service.
This operator is implemented with [Ernie Bot SDK from Baidu](https://github.com/PaddlePaddle/ERNIE-Bot-SDK).
Please note you will need [EB_API_TYPE & EB_ACCESS_TOKEN](https://github.com/PaddlePaddle/ERNIE-Bot-SDK/blob/develop/docs/authentication.md) to access the service.
LLM 算子使用大语言模型或服务,为输入的问题或提示生成答案。LLM/Ernie 利用了来自百度的[文心一言](https://cloud.baidu.com/wenxin.html)。请注意,您需要[文心一言服务的 API Key 和 Secret Key](https://ai.baidu.com/ai-doc/REFERENCE/Lkru0zoz4)才能访问该服务。
LLM 算子使用大语言模型或服务,为输入的问题或提示生成答案。LLM/Ernie 利用了来自百度的[Ernie Bot SDK](https://github.com/PaddlePaddle/ERNIE-Bot-SDK) 。请注意,您需要文心一言服务的 [EB_API_TYPE & EB_ACCESS_TOKEN](https://github.com/PaddlePaddle/ERNIE-Bot-SDK/blob/develop/docs/authentication.md) 才能访问该服务。
<br />
@ -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, temperature=0.5))
.map('messages', 'answer', ops.LLM.Ernie(api_type=EB_API_TYPE, access_token=EB_ACCESS_TOKEN))
.output('answer')
)
@ -58,7 +58,7 @@ 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)
ops.LLM.Ernie(api_type=EB_API_TYPE, access_token=EB_ACCESS_TOKEN)
)
.output('answer')
)
@ -72,18 +72,18 @@ answer = p(question, docs, history).get()[0]
Create the operator via the following factory method:
***LLM.Ernie(api_key: str, secret_key: str)***
***LLM.Ernie(api_type: str, access_token: str)***
**Parameters:**
***api_key***: *str=None*
***api_type***: *str=None*
The Ernie API key in string, defaults to None. If None, it will use the environment variable `ERNIE_API_KEY`.
The API type in string, defaults to None. If None, it will use the environment variable `EB_API_TYPE`. Refer to [authentication](https://github.com/PaddlePaddle/ERNIE-Bot-SDK/blob/develop/docs/authentication.md) for more details.
***secret_key***: *str=None*
***access_token***: *str=None*
The Ernie Secret key in string, defaults to None. If None, it will use the environment variable `ERNIE_SECRET_KEY`.
The access token in string, defaults to None. If None, it will use the environment variable `EB_ACCESS_TOKEN`. Refer to [authentication](https://github.com/PaddlePaddle/ERNIE-Bot-SDK/blob/develop/docs/authentication.md) for more details.
***\*\*kwargs***

4
ernie_chat.py

@ -29,8 +29,8 @@ class ErnieChat(PyOperator):
access_token: str = None,
**kwargs
):
erniebot.api_type = api_type or os.getenv('ERNIEBOT_API_TYPE')
erniebot.access_token = access_token or os.getenv('ERNIEBOT_ACCESS_TOKEN')
erniebot.api_type = api_type or os.getenv('EB_API_TYPE')
erniebot.access_token = access_token or os.getenv('EB_ACCESS_TOKEN')
self._model = model_name
self.stream = kwargs.pop('stream') if 'stream' in kwargs else False
self.kwargs = kwargs

3
requirements.txt

@ -1 +1,2 @@
requests
requests
erniebot
Loading…
Cancel
Save