Skip to content

Commit

Permalink
repair the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maparent committed Oct 3, 2023
1 parent e7724a2 commit 114f821
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions easycompletion/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@

openai.api_base = EASYCOMPLETION_API_ENDPOINT

def validate_api_key(api_key=None):
"""
Validates the OpenAI API key.
Parameters:
api_key (str, optional): OpenAI API key. If not provided, it uses the one defined in constants.py.
Returns:
bool: True if the API key is valid, False otherwise.
"""
if api_key is None:
api_key = EASYCOMPLETION_API_KEY

return api_key is not None and api_key.strip() != ""

def parse_arguments(arguments, debug=DEBUG):
"""
Parses arguments that are expected to be either a JSON string, dictionary, or a list.
Expand Down Expand Up @@ -173,7 +158,7 @@ def chat_completion(
model_failure_retries=5,
model=None,
chunk_length=DEFAULT_CHUNK_LENGTH,
api_key=None,
api_key=EASYCOMPLETION_API_KEY,
debug=DEBUG,
temperature=0.0,
):
Expand All @@ -194,7 +179,7 @@ def chat_completion(
>>> text_completion("Hello, how are you?", model_failure_retries=3, model='gpt-3.5-turbo', chunk_length=1024, api_key='your_openai_api_key')
"""
# Validate the API key
if not validate_api_key(api_key):
if not api_key.strip():
return {"error": "Invalid OpenAI API key"}

openai.api_key = api_key
Expand Down Expand Up @@ -269,7 +254,7 @@ def text_completion(
model_failure_retries=5,
model=None,
chunk_length=DEFAULT_CHUNK_LENGTH,
api_key=None,
api_key=EASYCOMPLETION_API_KEY,
debug=DEBUG,
temperature=0.0,
):
Expand Down Expand Up @@ -374,7 +359,7 @@ def function_completion(
function_failure_retries=10,
chunk_length=DEFAULT_CHUNK_LENGTH,
model=None,
api_key=None,
api_key=EASYCOMPLETION_API_KEY,
debug=DEBUG,
temperature=0.0,
):
Expand Down

0 comments on commit 114f821

Please sign in to comment.