diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce8013f..323fe68 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,11 @@ on: jobs: build: + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENAI_API_BASE_URL: ${{ secrets.OPENAI_API_BASE_URL }} + OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }} + OPENAI_API_MODEL: ${{ secrets.OPENAI_API_MODEL }} runs-on: ${{ matrix.os }} strategy: matrix: @@ -28,9 +33,6 @@ jobs: python -m pip install .[test] python -m pip install -r requirements_dev.txt - name: Test with pytest and coverage - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - OPENAI_API_BASE_URL: ${{ secrets.OPENAI_API_BASE_URL }} run: | pip install coverage coverage run -m pytest tests/ diff --git a/chattool/__init__.py b/chattool/__init__.py index 6431442..a543156 100644 --- a/chattool/__init__.py +++ b/chattool/__init__.py @@ -2,7 +2,7 @@ __author__ = """Rex Wang""" __email__ = '1073853456@qq.com' -__version__ = '3.1.6' +__version__ = '3.1.7' import os, sys, requests from .chattype import Chat, Resp diff --git a/chattool/chattype.py b/chattool/chattype.py index f1e9332..aa5aa83 100644 --- a/chattool/chattype.py +++ b/chattool/chattype.py @@ -46,11 +46,11 @@ def __init__( self self._chat_log = msg.copy() # avoid changing the original list else: raise ValueError("msg should be a list of dict, a string or None") - self.api_key = api_key or chattool.api_key + self.api_key = api_key or chattool.api_key or '' + self.model = model or chattool.model or '' # chat_url > api_base > base_url > chattool.api_base > chattool.base_url self.api_base = api_base or chattool.api_base self.base_url = base_url or chattool.base_url - self.model = model or chattool.model or "gpt-3.5-turbo" if chat_url: self.chat_url = chat_url elif api_base: diff --git a/setup.py b/setup.py index 46297b0..3bdfc3c 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md') as readme_file: readme = readme_file.read() -VERSION = '3.1.6' +VERSION = '3.1.7' requirements = [ 'Click>=7.0', 'requests>=2.20', "responses>=0.23", 'aiohttp>=3.8', diff --git a/tests/test_async.py b/tests/test_async.py index c71f94b..210cd0a 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -23,7 +23,8 @@ def test_apikey(): assert chattool.api_key.startswith("sk-") def test_base_url(): - assert chattool.base_url.startswith("http") + assert not chattool.api_base or chattool.api_base.startswith("http") + assert not chattool.base_url or chattool.base_url.startswith('http') def test_stream(): chat = Chat("hello") diff --git a/tests/test_envs.py b/tests/test_envs.py index 94d52e5..8a5a290 100644 --- a/tests/test_envs.py +++ b/tests/test_envs.py @@ -4,6 +4,17 @@ from chattool import Chat, save_envs, load_envs testpath = 'tests/testfiles/' +def test_model_api_key(): + api_key, model = chattool.api_key, chattool.model + chattool.api_key, chattool.model = None, None + chat = Chat() + assert chat.api_key == '' + assert chat.model == '' + chattool.api_key, chattool.model = api_key, model + chat = Chat(api_key="sk-123", model="gpt-3.5-turbo") + assert chat.api_key == "sk-123" + assert chat.model == "gpt-3.5-turbo" + def test_apibase(): api_base, base_url = chattool.api_base, chattool.base_url chattool.api_base, chattool.base_url = None, None diff --git a/tests/test_function.py b/tests/test_function.py index fb69e37..cdf88da 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -127,7 +127,7 @@ def test_mock_resp(): def test_use_exec_function(): chat = Chat("find the result of sqrt(121314)") chat.setfuncs([exec_python_code]) - chat.autoresponse(max_tries=2) + chat.autoresponse(max_tries=2, display=True) def test_find_permutation_group(): pass