Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow empty apikey and model #79

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion chattool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '3.1.6'
__version__ = '3.1.7'

import os, sys, requests
from .chattype import Chat, Resp
Expand Down
4 changes: 2 additions & 2 deletions chattool/chattype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions tests/test_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading