From 61ec8e96f2c443034e9bd5c3dfcc99d4b9f705c0 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Thu, 2 Mar 2023 19:49:36 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=A8=A1=E5=9E=8B-=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models_and_interfaces.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/compatibility_tests/models_and_interfaces.py diff --git a/tests/compatibility_tests/models_and_interfaces.py b/tests/compatibility_tests/models_and_interfaces.py new file mode 100644 index 00000000..1ace18d4 --- /dev/null +++ b/tests/compatibility_tests/models_and_interfaces.py @@ -0,0 +1,46 @@ +import openai +import time + +# 测试completion api +models = [ + 'gpt-3.5-turbo', + 'gpt-3.5-turbo-0301', + 'text-davinci-003', + 'text-davinci-002', + 'code-davinci-002', + 'code-cushman-001', + 'text-curie-001', + 'text-babbage-001', + 'text-ada-001', +] + +openai.api_key = "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" + +for model in models: + print('Testing model: ', model) + + # completion api + try: + response = openai.Completion.create( + model=model, + prompt="Say this is a test", + max_tokens=7, + temperature=0 + ) + print(' completion api: ', response['choices'][0]['text'].strip()) + except Exception as e: + print(' completion api err: ', e) + + # chat completion api + try: + completion = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "user", "content": "Hello!"} + ] + ) + print(" chat api: ",completion.choices[0].message['content'].strip()) + except Exception as e: + print(' chat api err: ', e) + + time.sleep(60)