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 ba146d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
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']

Check warning on line 64 in openai_api_call/response.py

View check run for this annotation

Codecov / codecov/patch

openai_api_call/response.py#L64

Added line #L64 was not covered by tests

@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

Check warning on line 12 in tests/__init__.py

View check run for this annotation

Codecov / codecov/patch

tests/__init__.py#L7-L12

Added lines #L7 - L12 were not covered by tests

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
8 changes: 6 additions & 2 deletions 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 import debug_log, Resp
from openai_api_call.request import normalize_url, is_valid_url, valid_models

import openai_api_call
openai_api_call.api_key="free-123"
openai_api_call.request.base_url = "api.wzhecnu.cn"
api_key = openai_api_call.api_key

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

0 comments on commit ba146d2

Please sign in to comment.