Skip to content

Commit

Permalink
Fixed api env var loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tonic committed Feb 26, 2024
1 parent 85ba479 commit 2312734
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 111 deletions.
17 changes: 10 additions & 7 deletions tonic_ragas_logger/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os
from dotenv import load_dotenv

load_dotenv()

TONIC_VALIDATE_API_KEY = os.getenv(
"TONIC_VALIDATE_API_KEY",
)
TONIC_VALIDATE_BASE_URL = os.getenv(
"TONIC_VALIDATE_BASE_URL", "https://validate.tonic.ai/api/v1"
)
class Config:
def __init__(self) -> None:
load_dotenv()

self.TONIC_VALIDATE_API_KEY = os.getenv(
"TONIC_VALIDATE_API_KEY",
)
self.TONIC_VALIDATE_BASE_URL = os.getenv(
"TONIC_VALIDATE_BASE_URL", "https://validate.tonic.ai/api/v1"
)
7 changes: 4 additions & 3 deletions tonic_ragas_logger/ragas_validate_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Dict

from tonic_validate import Run, RunData
from tonic_ragas_logger.config import TONIC_VALIDATE_API_KEY, TONIC_VALIDATE_BASE_URL
from tonic_ragas_logger.config import Config

from tonic_ragas_logger.utils.http_client import HttpClient
from ragas.evaluation import Result
Expand All @@ -21,15 +21,16 @@ def __init__(
self,
api_key: Optional[str] = None,
):
self.config = Config()
if api_key is None:
api_key = TONIC_VALIDATE_API_KEY
api_key = self.config.TONIC_VALIDATE_API_KEY
if api_key is None:
exception_message = (
"No api key provided. Please provide an api key or set "
"TONIC_VALIDATE_API_KEY environment variable."
)
raise Exception(exception_message)
self.client = HttpClient(TONIC_VALIDATE_BASE_URL, api_key)
self.client = HttpClient(self.config.TONIC_VALIDATE_BASE_URL, api_key)

def upload_results(
self, project_id: str, results: Result, run_metadata: Dict[str, str] = {}
Expand Down
Empty file.
101 changes: 0 additions & 101 deletions tonic_ragas_logger/utils/http_client.py

This file was deleted.

0 comments on commit 2312734

Please sign in to comment.