diff --git a/README.md b/README.md index 67e7742..273d3fc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## Description A chat-bot operator returns answer in text given input text. -This operator is implemented with GPT models from [OpenAI](https://platform.openai.com/docs/guides/embeddings). +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.
@@ -43,8 +43,8 @@ Create the operator via the following factory method: ***model_name***: *str* -The model name in string, defaults to 'text-davinci-003'. Supported model names: -- text-davinci-003 +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* @@ -55,7 +55,7 @@ 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 emabedding in numpy.ndarray. +It returns a text answer. ***\_\_call\_\_(txt)*** diff --git a/openai_qa.py b/openai_qa.py index 31fac6e..b6bd0ec 100644 --- a/openai_qa.py +++ b/openai_qa.py @@ -19,18 +19,18 @@ from towhee.operator.base import PyOperator class OpenaiQA(PyOperator): - def __init__(self, model_name='text-davinci-003', api_key=None): - self._engine = model_name + def __init__(self, model_name='text-davinci-003', api_key=None, max_token=50): + self._model = model_name self._api_key = api_key + self._max_token = max_token # @retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(6)) def _call(self, prompt): - prompt = prompt.replace("\n", " ") response = openai.Completion.create( api_key=self._api_key, - engine=self._engine, + model=self._model, prompt=prompt, - max_tokens=1024, + max_tokens=self._max_token, n=1, stop=None, temperature=0.3, diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dab6363 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +openai>=2.7 \ No newline at end of file