Readme
Files and versions
Updated 2 years ago
chatbot
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. Please note you need an OpenAI API key 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:
from towhee.dc2 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 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.
| 6 Commits | ||
---|---|---|---|
|
1.1 KiB
|
2 years ago | |
|
1.5 KiB
|
2 years ago | |
|
100 B
|
2 years ago | |
|
1.6 KiB
|
2 years ago | |
|
11 B
|
2 years ago |