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

repair the tests. #19

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
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