# Ernie Bot 文心一言 *author: Jael*
## Description 描述 A LLM operator generates answer given prompt in messages using a large language model or 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 利用了来自百度的[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) 才能访问该服务。
## Code Example 代码示例 *Write a pipeline with explicit inputs/outputs name specifications:* ```python from towhee import pipe, ops p = ( pipe.input('messages') .map('messages', 'answer', ops.LLM.Ernie(eb_api_type=EB_API_TYPE, eb_access_token=EB_ACCESS_TOKEN)) .output('answer') ) messages=[ {'question': 'Zilliz Cloud 是什么?', 'answer': 'Zilliz Cloud 是一种全托管的向量检索服务。'}, {'question': '它和 Milvus 的关系是什么?'} ] 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(eb_api_type=EB_API_TYPE, eb_access_token=EB_ACCESS_TOKEN) ) .output('answer') ) answer = p(question, docs, history).get()[0] ```
## Factory Constructor 接口说明 Create the operator via the following factory method: ***LLM.Ernie(eb_api_type: str, eb_access_token: str)*** **Parameters:** ***eb_api_type***: *str=None* 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. ***eb_access_token***: *str=None* 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*** Other Ernie parameters such as temperature, etc.
## Interface 使用说明 The operator takes a piece of text in string as input. It returns answer in json. ***\_\_call\_\_(txt)*** **Parameters:** ***messages***: *list* ​ A list of messages to set up chat. Must be a list of dictionaries with key value from "question", "answer". For example, [{"question": "a past question?", "answer": "a past answer."}, {"question": "current question?"}]. It also accepts the orignal Ernie message format like [{"role": "user", "content": "a question?"}, {"role": "assistant", "content": "an answer."}] **Returns**: *answer: str* ​ The next answer generated by role "assistant".
# More Resources - [Training Text Embeddings with Jina AI - Zilliz blog](https://zilliz.com/blog/training-text-embeddings-with-jina-ai): In a recent talk by Bo Wang, he discussed the creation of Jina text embeddings for modern vector search and RAG systems. He also shared methodologies for training embedding models that effectively encode extensive information, along with guidance o - [OpenAI's ChatGPT - Zilliz blog](https://zilliz.com/learn/ChatGPT-Vector-Database-Prompt-as-code): A guide to the new AI Stack - ChatGPT, your Vector Database, and Prompt as code - [Building an Intelligent QA System with NLP and Milvus - Zilliz blog](https://zilliz.com/blog/building-intelligent-chatbot-with-nlp-and-milvus): The Next-Gen QA Bot is here - [Prompting in LangChain - Zilliz blog](https://zilliz.com/blog/prompting-langchain): Prompting is one of today's most popular and important tasks in AI app building. Learn how to use LangChain for more complex prompts. - [Boost your LLM with Private Data Using LlamaIndex | Zilliz Webinar](https://zilliz.com/event/boost-your-llm-with-private-data-using-llamaindex/success): Zilliz webinar covering how to boost your LLM with private data with LlamaIndex to generate accurate and meaningful responses that reflect unique data inputs. - [The guide to bge-base-zh-v1.5 | BAAI](https://zilliz.com/ai-models/bge-base-zh-v1.5): bge-base-zh-v1.5: A general embedding (BGE) model introduced by BAAI and tailored for Chinese text. - [Boost your LLM with Private Data Using LlamaIndex | Zilliz Webinar](https://zilliz.com/event/boost-your-llm-with-private-data-using-llamaindex): Zilliz webinar covering how to boost your LLM with private data with LlamaIndex to generate accurate and meaningful responses that reflect unique data inputs. - [How to Build an AI Chatbot with Milvus and Towhee - Zilliz blog](https://zilliz.com/blog/how-to-build-ai-chatbot-with-Milvus-and-Towhee): Learn how to build a simple chatbot with Python using Milvus and Towhee.