logo
openai
repo-copy-icon

copied

Browse Source

Update with latest openai version

Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
Jael Gu 2 years ago
parent
commit
32c9ee9efd
  1. 8
      README.md
  2. 10
      openai_qa.py
  3. 1
      requirements.txt

8
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.
<br />
@ -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)***

10
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,

1
requirements.txt

@ -0,0 +1 @@
openai>=2.7
Loading…
Cancel
Save