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

Feaeture/improve get api key #66

Merged
merged 4 commits into from
Aug 29, 2023
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
25 changes: 25 additions & 0 deletions .github/workflows/pip_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pip install comment

on:
pull_request:

jobs:
create-pip-link-comment:
runs-on: ubuntu-latest
name: pip link
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Comment PR
uses: marocchino/sticky-pull-request-comment@v2
with:
hide_and_recreate: true
hide_classify: "OUTDATED"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: |
Thanks for the PR! Going to review and merge soon 😉
Just before that though can you please test the installation with the command below? 😎
```
pip install git+https://github.com/RelevanceAI/relevance-workflows-core.git@${{ github.head_ref }}
```
2 changes: 1 addition & 1 deletion deepeval/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "0.10.2"
__version__: str = "0.10.4"
4 changes: 3 additions & 1 deletion deepeval/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def login(
if api_key == "":
api_key = KEY_FILE_HANDLER.fetch_api_key()
api_key = typer.prompt(
text="Paste it here (Hit enter if default is right) ",
text="Paste it here (Hit enter if default is right)",
default=api_key,
)
KEY_FILE_HANDLER.write_api_key(api_key)
client = Api(api_key=api_key)
if project_name == "":
project_name = KEY_FILE_HANDLER.fetch_implementation_name()
if project_name is None or project_name == "":
project_name = "example"
print("What is the name of your project?")
project_name = typer.prompt(
text="Name (Hit enter if default is right):",
Expand Down
10 changes: 3 additions & 7 deletions deepeval/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import getpass
from .api import Api
from .get_api_key import _get_api_key
from typing import Optional, List, Dict


Expand All @@ -12,13 +13,8 @@ class Client(Api):
_implementation_id: Dict[str, str] = {}

def __init__(self, api_key: str = None, local_mode: bool = False, **kwargs):
if api_key is None:
if "CONFIDENT_AI_API_KEY" not in os.environ:
api_key = getpass.getpass(
"Grab your API key from https://app.confident-ai.com"
)
else:
api_key = os.environ["CONFIDENT_AI_API_KEY"]
if api_key is None or api_key == "":
api_key = _get_api_key()
self.api_key = api_key
self.local_mode = local_mode
if self.local_mode:
Expand Down
13 changes: 13 additions & 0 deletions deepeval/get_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Utility function for getting API key.
"""
import os
from .key_handler import KEY_FILE_HANDLER
from .constants import API_KEY_ENV


def _get_api_key():
"""Get an API key here."""
api_key = KEY_FILE_HANDLER.fetch_api_key()
if api_key is None or api_key == "":
api_key = os.getenv(API_KEY_ENV, "")
return api_key
15 changes: 9 additions & 6 deletions deepeval/metrics/metric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import warnings
from typing import Optional
from ..get_api_key import _get_api_key
from ..constants import (
API_KEY_ENV,
IMPLEMENTATION_ID_ENV,
Expand Down Expand Up @@ -37,12 +38,14 @@ def is_successful(self) -> bool:
raise NotImplementedError

def _is_api_key_set(self):
result = os.getenv(API_KEY_ENV) is not None
if result is False:
warnings.warn(
"""API key is not set. Please set it by visiting https://app.confident-ai.com"""
)
return result
result = _get_api_key()
# if result == "" or result is None:
# warnings.warn(
# """API key is not set - you won't be able to log to the DeepEval dashboard. Please set it by running `deepeval login`"""
# )
if result == "" or result is None:
return False
return True

def _is_send_okay(self):
# DOing this until the API endpoint is fixed
Expand Down