Skip to content

Commit

Permalink
Merge pull request confident-ai#422 from confident-ai/hotfix/popupdis…
Browse files Browse the repository at this point in the history
…play

fix error on api key
  • Loading branch information
penguine-ip authored Jan 20, 2024
2 parents 61b7390 + 4685528 commit 2c71ec8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
5 changes: 3 additions & 2 deletions deepeval/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Golden,
DatasetHttpResponse,
)
from deepeval.utils import is_confident


@dataclass
Expand Down Expand Up @@ -245,7 +246,7 @@ def push(self, alias: str):
raise ValueError(
"Unable to push empty dataset to Confident AI, there must be at least one test case in dataset"
)
if os.path.exists(".deepeval"):
if is_confident():
goldens = convert_test_cases_to_goldens(self.test_cases)
body = APIDataset(
alias=alias, overwrite=False, goldens=goldens
Expand All @@ -272,7 +273,7 @@ def push(self, alias: str):
)

def pull(self, alias: str, auto_convert_goldens_to_test_cases: bool = True):
if os.path.exists(".deepeval"):
if is_confident():
api = Api()
result = api.get_request(
endpoint=Endpoints.DATASET_ENDPOINT.value,
Expand Down
23 changes: 12 additions & 11 deletions deepeval/test_run/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
import json
from pydantic import BaseModel, Field
from typing import Any, Optional, List, Dict
import shutil
import webbrowser
import sys
import datetime
import portalocker
from rich.table import Table
from rich.console import Console
from rich import print

from deepeval.metrics import BaseMetric
from deepeval.test_case import LLMTestCase
from deepeval.tracing import get_trace_stack
Expand All @@ -13,15 +22,7 @@
MetricsMetadata,
TestRunHttpResponse,
)
import shutil
import webbrowser
from deepeval.utils import delete_file_if_exists
import sys
import datetime
import portalocker
from rich.table import Table
from rich.console import Console
from rich import print
from deepeval.utils import delete_file_if_exists, is_confident

TEMP_FILE_NAME = "temp_test_run_data.json"

Expand Down Expand Up @@ -262,7 +263,7 @@ def post_test_run(self, test_run: TestRun):
for test_case in test_run.test_cases:
test_case.id = None

if os.path.exists(".deepeval"):
if is_confident():
try:
body = test_run.model_dump(by_alias=True, exclude_none=True)
except AttributeError:
Expand All @@ -278,7 +279,7 @@ def post_test_run(self, test_run: TestRun):
projectId=result["projectId"],
link=result["link"],
)
if response and os.path.exists(".deepeval"):
if response:
link = response.link
console.print(
"✅ Tests finished! View results on "
Expand Down
7 changes: 7 additions & 0 deletions deepeval/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
from dataclasses import asdict, is_dataclass
import re

from deepeval.key_handler import KeyValues, KEY_FILE_HANDLER


def is_confident():
confident_api_key = KEY_FILE_HANDLER.fetch_data(KeyValues.API_KEY)
return confident_api_key is not None


def drop_and_copy(obj, drop_attrs):
# Function to drop attributes from a single object
Expand Down

0 comments on commit 2c71ec8

Please sign in to comment.