# ChatBot with OpenAI *author: Jael, Yuchen*
## Description A chat-bot operator returns answer in text given input text. This operator is implemented with Completion method from [OpenAI](https://platform.openai.com/docs/models/overview). Please note you need an [OpenAI API key](https://platform.openai.com/account/api-keys) to access OpenAI.
## Code Example Use the default model to answer the question "Who are you?". *Write a pipeline with explicit inputs/outputs name specifications:* ```python from towhee import pipe, ops, DataCollection p = ( pipe.input('question') .map('question', 'answer', ops.chatbot.openai(api_key=OPENAI_API_KEY)) .output('question', 'answer') ) DataCollection(p('Who are you?')).show() ```
## Factory Constructor Create the operator via the following factory method: ***chatbot.openai(model_name: str, api_key: str)*** **Parameters:** ***model_name***: *str* The model name in string, defaults to 'text-davinci-003'. Refer to [OpenAI List Models](https://platform.openai.com/docs/api-reference/models/list) for all supported model names. ***api_key***: *str=None* The OpenAI API key in string, defaults to None.
## Interface The operator takes a piece of text in string as input. It returns a text answer. ***\_\_call\_\_(txt)*** **Parameters:** ***text***: *str* ​ The text in string. **Returns**: *answer: str* ​ The answer in string generated by model.
***supported_model_names()*** Get a list of supported model names. # More Resources - [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 Open Source Chatbots with LangChain and Milvus in 5m - Zilliz blog](https://zilliz.com/blog/building-open-source-chatbot-using-milvus-and-langchain-in-5-minutes): A start-to-finish tutorial for RAG retrieval and question-answering chatbot on custom documents using Milvus, LangChain, and an open-source LLM. - [Exploring OpenAI CLIP: The Future of Multi-Modal AI Learning - Zilliz blog](https://zilliz.com/learn/exploring-openai-clip-the-future-of-multimodal-ai-learning): Multimodal AI learning can get input and understand information from various modalities like text, images, and audio together, leading to a deeper understanding of the world. Learn more about OpenAI's CLIP (Contrastive Language-Image Pre-training), a popular multimodal model for text and image data. - [Building a Chatbot for Toward the Science with Zilliz Cloud (Part I) - Zilliz blog](https://zilliz.com/blog/chat-towards-data-science-building-chatbot-with-zilliz-cloud): Building a chatbot for the Towards Data Science publication using the Zilliz vector database - [OpenAI Whisper: Transforming Speech-to-Text with Advanced AI - Zilliz blog](https://zilliz.com/learn/open-ai-whisper-transforming-speech-to-text-with-advanced-ai): Understand Open AI Whisper and follow this step-by-step article to implement it in projects that can significantly enhance the efficiency of speech-to-text tasks. - [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.