Skip to content

Commit

Permalink
fix error of githubaction
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Aug 22, 2023
1 parent 6e7e673 commit 8ac4d64
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
OPENAI_API_BASE_URL: ${{ secrets.OPENAI_API_BASE_URL }}
run: |
pip install coverage
echo OPENAI_API_KEY=$OPENAI_API_KEY\nOPENAI_API_BASE_URL=$OPENAI_API_BASE_URL > .env
source .env
coverage run -m pytest tests/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
17 changes: 13 additions & 4 deletions openai_api_call/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,34 @@ def content(self):
"""Content of the response"""
return self.message['content']

@property
def object(self):
return self.response['object']

@property
def error(self):
"""Error"""
return self.response['error']

@property
def error_message(self):
"""Error message"""
return self.response['error']['message']
return self.error['message']

@property
def error_type(self):
"""Error type"""
return self.response['error']['type']
return self.error['type']

@property
def error_param(self):
"""Error parameter"""
return self.response['error']['param']
return self.error['param']

@property
def error_code(self):
"""Error code"""
return self.response['error']['code']
return self.error['code']

@property
def finish_reason(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ def test_simple():
chat.getresponse()
chat.print_log()
assert chat.chat_log[0] == {"role": "user", "content": "Hello!"}
assert len(chat.chat_log) == 2
assert len(chat.chat_log) == 2

2 changes: 0 additions & 2 deletions tests/test_openai_api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def test_with_template():
chat = Chat("hello!")
assert chat.chat_log == [{"role": "user", "content": "hello!"}]


def test_error_message():
resp = Resp(response=err_api_key_resp)
assert resp.error_message == "Incorrect API key provided: sk-132. You can find your API key at https://platform.openai.com/account/api-keys."
Expand All @@ -190,7 +189,6 @@ def test_error_message():
assert resp.is_valid() == False



def test_usage():
resp = Resp(response=response)
assert resp.total_tokens == 18
Expand Down
6 changes: 5 additions & 1 deletion tests/test_request.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from openai_api_call import debug_log, api_key, Resp
from openai_api_call.request import normalize_url, is_valid_url, valid_models


import os
print("Secret", len(os.environ['OPENAI_API_KEY']))
print("URL", len(os.environ['OPENAI_API_BASE_URL']))

def test_valid_models():
models = valid_models(api_key=api_key, gpt_only=False)
assert len(models) >= 1
Expand Down

0 comments on commit 8ac4d64

Please sign in to comment.